0024186: Eliminate remaining compiler warnings in MSVC++ 2010 64 bit with warning...
[occt.git] / src / Interface / Interface_FloatWriter.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18//#52 rln 23.12.98
19#include <Interface_FloatWriter.ixx>
20#include <stdio.h>
21
22
b311480e 23Interface_FloatWriter::Interface_FloatWriter (const Standard_Integer chars)
7fd59977 24{
25 SetDefaults(chars);
26}
27
28// .... Controle d Envoi des Flottants ....
29
30 void Interface_FloatWriter::SetFormat
31 (const Standard_CString form, const Standard_Boolean reset)
32{
33 strcpy(themainform,form);
34 if (!reset) return;
35 therange1 = therange2 = 0.; // second form : inhibee
36 thezerosup = Standard_False;
37}
38
39 void Interface_FloatWriter::SetFormatForRange
40 (const Standard_CString form,
41 const Standard_Real R1, const Standard_Real R2)
42{
43 strcpy(therangeform,form);
44 therange1 = R1;
45 therange2 = R2;
46}
47
48 void Interface_FloatWriter::SetZeroSuppress (const Standard_Boolean mode)
49 { thezerosup = mode; }
50
51 void Interface_FloatWriter::SetDefaults (const Standard_Integer chars)
52{
53 if (chars <= 0) {
54 strcpy(themainform ,"%E");
55 strcpy(therangeform ,"%f");
56 } else {
57 char pourcent = '%'; char point = '.';
91322f44 58 Sprintf(themainform, "%c%d%c%dE",pourcent,chars+2,point,chars);
59 Sprintf(therangeform, "%c%d%c%df",pourcent,chars+2,point,chars);
7fd59977 60 }
61 therange1 = 0.1; therange2 = 1000.;
62 thezerosup = Standard_True;
63}
64
65 void Interface_FloatWriter::Options
66 (Standard_Boolean& zerosup, Standard_Boolean& range,
67 Standard_Real& R1, Standard_Real& R2) const
68{
69 zerosup = thezerosup;
70 range = (therange2 >= therange1 && therange1 >= 0.);
71 R1 = therange1;
72 R2 = therange2;
73}
74
75 Standard_CString Interface_FloatWriter::MainFormat () const
76 { const Standard_CString mainform = Standard_CString(&themainform[0]); return mainform; }
77
78 Standard_CString Interface_FloatWriter::FormatForRange () const
79 { const Standard_CString rangeform = Standard_CString(&therangeform[0]); return rangeform; }
80
81// ########################################################################
82
83 Standard_Integer Interface_FloatWriter::Write
84 (const Standard_Real val, const Standard_CString text) const
85{
86 const Standard_CString mainform = Standard_CString(themainform);
87 const Standard_CString rangeform = Standard_CString(therangeform);
88 return Convert
89 (val,text,thezerosup,therange1,therange2,mainform,rangeform);
90}
91
92//=======================================================================
93//function : Convert
94//purpose :
95//=======================================================================
96Standard_Integer Interface_FloatWriter::Convert (const Standard_Real val,
97 const Standard_CString text,
98 const Standard_Boolean zsup,
99 const Standard_Real R1,
100 const Standard_Real R2,
101 const Standard_CString mainform,
102 const Standard_CString rangeform)
103{
104// Valeur flottante, expurgee de "0000" qui trainent et de "E+00"
a8195d65 105 const Standard_Integer anMasSize = 5; // change 6 to 5: index 5 is not used below
106 char lxp[anMasSize], *pText;
1d47d8d0 107 int i0 = 0, j0 = 0;
a8195d65 108
109 for (Standard_Integer i = 0; i < anMasSize; ++i)
110 lxp[i] = '\0';
7fd59977 111
7fd59977 112 pText=(char *)text;
113 //
a8195d65 114 if ( (val >= R1 && val < R2) || (val <= -R1 && val > -R2) )
91322f44 115 Sprintf(pText,rangeform,val);
a8195d65 116 else
91322f44 117 Sprintf(pText,mainform,val);
7fd59977 118
a8195d65 119 if (zsup)
120 {
121 for (int i = 0; i < 16; i ++)
122 {
7fd59977 123 i0 = i;
a8195d65 124 if (text[i] == 'e' || text[i] == 'E')
125 {
126 lxp[0] = 'E';
127 lxp[1] = text[i+1];
128 lxp[2] = text[i+2];
129 lxp[3] = text[i+3];
130 lxp[4] = text[i+4];
131
132 if (lxp[1] == '+' && lxp[2] == '0' && lxp[3] == '0' && lxp[4] == '\0')
133 lxp[0] = '\0';
134
135 pText[i] = '\0';
7fd59977 136 }
a8195d65 137 if (text[i] == '\0') break;
7fd59977 138 }
139 //#52 rln 23.12.98 converting 1e-07 throws exception
a8195d65 140 for (int j = i0-1; j >= 0; j --)
141 {
7fd59977 142 j0 = j;
a8195d65 143
144 if (text[j] != '0')
145 break;
146
7fd59977 147 pText[j] = '\0';
148 }
a8195d65 149
7fd59977 150 pText[j0+1] = lxp[0];
151 pText[j0+2] = lxp[1];
152 pText[j0+3] = lxp[2];
153 pText[j0+4] = lxp[3];
154 pText[j0+5] = lxp[4];
155 pText[j0+6] = '\0';
156 }
7dc9e047 157 return (Standard_Integer)strlen(text);
7fd59977 158}