0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Interface / Interface_FloatWriter.hxx
CommitLineData
42cf5bc1 1// Created on: 1994-04-15
2// Created by: Christian CAILLET
3// Copyright (c) 1994-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Interface_FloatWriter_HeaderFile
18#define _Interface_FloatWriter_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <Standard_Character.hxx>
25#include <Standard_Real.hxx>
26#include <Standard_Boolean.hxx>
27#include <Standard_Integer.hxx>
28#include <Standard_CString.hxx>
29
30
31//! This class converts a floting number (Real) to a string
32//! It can be used if the standard C-C++ output functions
04232180 33//! (sprintf or std::cout<<) are not convenient. That is to say :
42cf5bc1 34//! - to suppress trailing '0' and 'E+00' (if desired)
35//! - to control exponant output and floating point output
36//!
37//! Formats are given in the form used by printf-sprintf
38class Interface_FloatWriter
39{
40public:
41
42 DEFINE_STANDARD_ALLOC
43
44
45 //! Creates a FloatWriter ready to work, with default options -
46 //! - zero suppress option is set
47 //! - main format is set to "%E"
48 //! - secondary format is set to "%f" for values between 0.1 and
49 //! 1000. in absolute values
50 //! If <chars> is given (and positive), it will produce options
51 //! to produce this count of characters : "%<chars>f","%<chars>%E"
52 Standard_EXPORT Interface_FloatWriter(const Standard_Integer chars = 0);
53
54 //! Sets a specific Format for Sending Reals (main format)
55 //! (Default from Creation is "%E")
56 //! If <reset> is given True (default), this call clears effects
57 //! of former calls to SetFormatForRange and SetZeroSuppress
58 Standard_EXPORT void SetFormat (const Standard_CString form, const Standard_Boolean reset = Standard_True);
59
60 //! Sets a secondary Format for Real, to be applied between R1 and
61 //! R2 (in absolute values). A Call to SetRealForm cancels this
62 //! secondary form if <reset> is True.
63 //! (Default from Creation is "%f" between 0.1 and 1000.)
64 //! Warning : if the condition (0. <= R1 < R2) is not fulfilled, this
65 //! secondary form is canceled.
66 Standard_EXPORT void SetFormatForRange (const Standard_CString form, const Standard_Real R1, const Standard_Real R2);
67
68 //! Sets Sending Real Parameters to suppress trailing Zeros and
69 //! Null Exponant ("E+00"), if <mode> is given True, Resets this
70 //! mode if <mode> is False (in addition to Real Forms)
71 //! A call to SetRealFrom resets this mode to False ig <reset> is
72 //! given True (Default from Creation is True)
73 Standard_EXPORT void SetZeroSuppress (const Standard_Boolean mode);
74
75 //! Sets again options to the defaults given by Create
76 Standard_EXPORT void SetDefaults (const Standard_Integer chars = 0);
77
78 //! Returns active options : <zerosup> is the option ZeroSuppress,
79 //! <range> is True if a range is set, False else
80 //! R1,R2 give the range (if it is set)
81 Standard_EXPORT void Options (Standard_Boolean& zerosup, Standard_Boolean& range, Standard_Real& R1, Standard_Real& R2) const;
82
83 //! Returns the main format
84 //! was C++ : return const
85 Standard_EXPORT Standard_CString MainFormat() const;
86
87 //! Returns the format for range, if set
88 //! Meaningful only if <range> from Options is True
89 //! was C++ : return const
90 Standard_EXPORT Standard_CString FormatForRange() const;
91
92 //! Writes a Real value <val> to a string <text> by using the
93 //! options. Returns the useful Length of produced string.
94 //! It calls the class method Convert.
95 //! Warning : <text> is assumed to be wide enough (20-30 is correct)
96 //! And, even if declared in, its content will be modified
97 Standard_EXPORT Standard_Integer Write (const Standard_Real val, const Standard_CString text) const;
98
99 //! This class method converts a Real Value to a string, given
100 //! options given as arguments. It can be called independantly.
101 //! Warning : even if declared in, content of <text> will be modified
102 Standard_EXPORT static Standard_Integer Convert (const Standard_Real val, const Standard_CString text, const Standard_Boolean zerosup, const Standard_Real Range1, const Standard_Real Range2, const Standard_CString mainform, const Standard_CString rangeform);
103
104
105
106
107protected:
108
109
110
111
112
113private:
114
115
116
117 Standard_Character themainform[12];
118 Standard_Real therange1;
119 Standard_Real therange2;
120 Standard_Character therangeform[12];
121 Standard_Boolean thezerosup;
122
123
124};
125
126
127
128
129
130
131
132#endif // _Interface_FloatWriter_HeaderFile