Salome HOME
c8a98279279162e11fd89808f76ae3fe0a9f3092
[modules/geom.git] / src / XAO / XAO_XaoUtils.hxx
1 // Copyright (C) 2013-2023  CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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.hxx"
29 #include "XAO_Exception.hxx"
30
31 #ifdef WIN32
32 #pragma warning(disable:4290) // Warning Exception ...
33 #endif
34
35 namespace XAO
36 {
37     /**
38      * @enum Format
39      */
40     enum Format
41     {
42         BREP,
43         STEP
44     };
45
46     /**
47      * @enum Dimension
48      */
49     enum Dimension
50     {
51         VERTEX = 0,//!< VERTEX
52         EDGE = 1,  //!< EDGE
53         FACE = 2,  //!< FACE
54         SOLID = 3, //!< SOLID
55         WHOLE = -1 //!< WHOLE
56     };
57
58     /**
59      * @enum Type
60      */
61     enum Type
62     {
63         BOOLEAN = 0,//!< BOOLEAN
64         INTEGER = 1,//!< INTEGER
65         DOUBLE = 2, //!< DOUBLE
66         STRING = 3  //!< STRING
67     };
68
69     /**
70      * \class XaoUtils
71      * Utilities class to convert types.
72      */
73     class XAO_EXPORT XaoUtils
74     {
75     public:
76         /**
77          * Converts an integer into a string.
78          * \param value the integer to convert.
79          * \return the string.
80          */
81         static std::string intToString(int value);
82
83         /**
84          * Converts a string into an integer.
85          * \param value the string to convert.
86          * \return the integer value.
87          * \throw XAO_Exception if value cannot be converted to string.
88          */
89         static int stringToInt(const std::string& value);
90
91         /**
92          * Converts a double into a string.
93          * \param value the double to convert.
94          * \return the string.
95          */
96         static std::string doubleToString(double value);
97         /**
98          * Converts a string into a double.
99          * \param value the string to convert.
100          * \return the double value.
101          * \throw XAO_Exception if value cannot be converted to string.
102          */
103         static double stringToDouble(const std::string& value);
104
105         /**
106          * Converts a boolean into a string.
107          * \param value the boolean to convert.
108          * \return the string.
109          */
110         static std::string booleanToString(bool value);
111         /**
112          * Converts a string into a boolean.
113          * \param value the string to convert.
114          * \return the boolean value.
115          * \throw XAO_Exception if value cannot be converted to boolean.
116          * \note accepted values are "true", "1", "false", "0".
117          */
118         static bool stringToBoolean(const std::string& value);
119
120         /**
121          * Converts a Dimension to string.
122          * \param dimension the Dimension to convert.
123          * \return the dimension as a string.
124          * \throw XAO_Exception
125          */
126         static std::string dimensionToString(XAO::Dimension dimension);
127
128         /**
129          * Converts a string into a Dimension.
130          * \param dimension the dimension as a string.
131          * \return the converted Dimension.
132          * \throw XAO_Exception if dimension cannot be converted.
133          */
134         static XAO::Dimension stringToDimension(const std::string& dimension);
135
136         /**
137          * Converts a Type to string.
138          * \param type the Type to convert.
139          * \return the Type as a string.
140          * \throw XAO_Exception
141          */
142         static std::string fieldTypeToString(XAO::Type type);
143
144         /**
145          * Converts a string into a Type.
146          * \param type the Type as a string.
147          * \return the converted Type.
148          * \throw XAO_Exception if type cannot be converted.
149          */
150         static XAO::Type stringToFieldType(const std::string& type);
151
152         /**
153          * Converts a Format to string.
154          * \param format the Format to convert.
155          * \return the Format as a string.
156          * \throw XAO_Exception
157          */
158         static std::string shapeFormatToString(XAO::Format format);
159
160         /**
161          * Converts a string into a Format.
162          * \param format the Format as a string.
163          * \return the converted Format.
164          * \throw XAO_Exception if format cannot be converted.
165          */
166         static XAO::Format stringToShapeFormat(const std::string& format);
167     };
168
169     /**
170      * @class MsgBuilder
171      * MsgBuilder can be use to easily create messages.
172      */
173     class MsgBuilder
174     {
175     public:
176         /** Constructor. */
177         MsgBuilder() {};
178         /** Destructor. */
179         ~MsgBuilder() {};
180
181 #ifndef SWIG
182         /** Stream operator. */
183         template <typename T>
184         MsgBuilder& operator <<(const T& t)
185         {
186             m_stream << t;
187             return *this;
188         }
189
190         /**
191          * Conversion operator to char*.
192          */
193         operator const char*() const   { return m_stream.str().c_str(); }
194 #endif
195
196     private :
197         std::stringstream m_stream;
198     };
199
200 }
201
202
203
204 #endif /* __XAO_UTILS_HXX__ */