]> SALOME platform Git repositories - modules/geom.git/blob - src/XAO/XAO_XaoUtils.hxx
Salome HOME
0022307: implement workaround for OCC bug 0024263
[modules/geom.git] / src / XAO / XAO_XaoUtils.hxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Frederic Pons (OpenCascade)
20
21 #ifndef __XAO_UTILS_HXX__
22 #define __XAO_UTILS_HXX__
23
24 #include <sstream>
25 #include <string>
26 #include <exception>
27
28 #include "XAO_Exception.hxx"
29
30
31 namespace XAO
32 {
33     /**
34      * @enum Format
35      */
36     enum Format
37     {
38         BREP,
39         STEP
40     };
41
42     /**
43      * @enum Dimension
44      */
45     enum Dimension
46     {
47         VERTEX = 0,//!< VERTEX
48         EDGE = 1,  //!< EDGE
49         FACE = 2,  //!< FACE
50         SOLID = 3, //!< SOLID
51         WHOLE = -1 //!< WHOLE
52     };
53
54     /**
55      * @enum Type
56      */
57     enum Type
58     {
59         BOOLEAN = 0,//!< BOOLEAN
60         INTEGER = 1,//!< INTEGER
61         DOUBLE = 2, //!< DOUBLE
62         STRING = 3  //!< STRING
63     };
64
65     /**
66      * \class XaoUtils
67      * Utilities class to convert types.
68      */
69     class XaoUtils
70     {
71     public:
72         /**
73          * Converts an integer into a string.
74          * \param value the integer to convert.
75          * \return the string.
76          */
77         static const std::string intToString(const int& value);
78
79         /**
80          * Converts a string into an integer.
81          * \param value the string to convert.
82          * \return the integer value.
83          * \throw XAO_Exception if value cannot be converted to string.
84          */
85         static const int stringToInt(const std::string& value) throw(XAO_Exception);
86
87         /**
88          * Converts a double into a string.
89          * \param value the double to convert.
90          * \return the string.
91          */
92         static const std::string doubleToString(const double& value);
93         /**
94          * Converts a string into a double.
95          * \param value the string to convert.
96          * \return the double value.
97          * \throw XAO_Exception if value cannot be converted to string.
98          */
99         static const double stringToDouble(const std::string& value) throw(XAO_Exception);
100
101         /**
102          * Converts a boolean into a string.
103          * \param value the boolean to convert.
104          * \return the string.
105          */
106         static const std::string booleanToString(const bool& value);
107         /**
108          * Converts a string into a boolean.
109          * \param value the string to convert.
110          * \return the boolean value.
111          * \throw XAO_Exception if value cannot be converted to boolean.
112          * \note accepted values are "true", "1", "false", "0".
113          */
114         static const bool stringToBoolean(const std::string& value) throw(XAO_Exception);
115
116         /**
117          * Converts a Dimension to string.
118          * \param dimension the Dimension to convert.
119          * \return the dimension as a string.
120          * \throw XAO_Exception
121          */
122         static const std::string dimensionToString(const XAO::Dimension& dimension) throw(XAO_Exception);
123
124         /**
125          * Converts a string into a Dimension.
126          * \param dimension the dimension as a string.
127          * \return the converted Dimension.
128          * \throw XAO_Exception if dimension cannot be converted.
129          */
130         static const XAO::Dimension stringToDimension(const std::string& dimension) throw(XAO_Exception);
131
132         /**
133          * Converts a Type to string.
134          * \param type the Type to convert.
135          * \return the Type as a string.
136          * \throw XAO_Exception
137          */
138         static const std::string fieldTypeToString(const XAO::Type& type) throw(XAO_Exception);
139
140         /**
141          * Converts a string into a Type.
142          * \param type the Type as a string.
143          * \return the converted Type.
144          * \throw XAO_Exception if type cannot be converted.
145          */
146         static const XAO::Type stringToFieldType(const std::string& type) throw(XAO_Exception);
147
148         /**
149          * Converts a Format to string.
150          * \param format the Format to convert.
151          * \return the Format as a string.
152          * \throw XAO_Exception
153          */
154         static const std::string shapeFormatToString(const XAO::Format& format) throw(XAO_Exception);
155
156         /**
157          * Converts a string into a Format.
158          * \param format the Format as a string.
159          * \return the converted Format.
160          * \throw XAO_Exception if format cannot be converted.
161          */
162         static const XAO::Format stringToShapeFormat(const std::string& format) throw(XAO_Exception);
163     };
164
165     /**
166      * @class MsgBuilder
167      * MsgBuilder can be use to easily create messages.
168      */
169     class MsgBuilder
170     {
171     public:
172         /** Constructor. */
173         MsgBuilder() {};
174         /** Destructor. */
175         ~MsgBuilder() {};
176
177 #ifndef SWIG
178         /** Stream operator. */
179         template <typename T>
180         MsgBuilder& operator <<(const T& t)
181         {
182             m_stream << t;
183             return *this;
184         }
185
186         /**
187          * Conversion operator to char*.
188          */
189         operator const char*() const   { return m_stream.str().c_str(); }
190 #endif
191
192     private :
193         std::stringstream m_stream;
194     };
195
196 }
197
198
199
200 #endif /* __XAO_UTILS_HXX__ */