1 // Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Frederic Pons (OpenCascade)
21 #ifndef __XAO_UTILS_HXX__
22 #define __XAO_UTILS_HXX__
29 #include "XAO_Exception.hxx"
32 #pragma warning(disable:4290) // Warning Exception ...
51 VERTEX = 0,//!< VERTEX
63 BOOLEAN = 0,//!< BOOLEAN
64 INTEGER = 1,//!< INTEGER
65 DOUBLE = 2, //!< DOUBLE
66 STRING = 3 //!< STRING
71 * Utilities class to convert types.
73 class XAO_EXPORT XaoUtils
77 * Converts an integer into a string.
78 * \param value the integer to convert.
81 static const std::string intToString(const int& value);
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.
89 static const int stringToInt(const std::string& value) throw(XAO_Exception);
92 * Converts a double into a string.
93 * \param value the double to convert.
96 static const std::string doubleToString(const double& value);
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.
103 static const double stringToDouble(const std::string& value) throw(XAO_Exception);
106 * Converts a boolean into a string.
107 * \param value the boolean to convert.
108 * \return the string.
110 static const std::string booleanToString(const bool& value);
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".
118 static const bool stringToBoolean(const std::string& value) throw(XAO_Exception);
121 * Converts a Dimension to string.
122 * \param dimension the Dimension to convert.
123 * \return the dimension as a string.
124 * \throw XAO_Exception
126 static const std::string dimensionToString(const XAO::Dimension& dimension) throw(XAO_Exception);
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.
134 static const XAO::Dimension stringToDimension(const std::string& dimension) throw(XAO_Exception);
137 * Converts a Type to string.
138 * \param type the Type to convert.
139 * \return the Type as a string.
140 * \throw XAO_Exception
142 static const std::string fieldTypeToString(const XAO::Type& type) throw(XAO_Exception);
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.
150 static const XAO::Type stringToFieldType(const std::string& type) throw(XAO_Exception);
153 * Converts a Format to string.
154 * \param format the Format to convert.
155 * \return the Format as a string.
156 * \throw XAO_Exception
158 static const std::string shapeFormatToString(const XAO::Format& format) throw(XAO_Exception);
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.
166 static const XAO::Format stringToShapeFormat(const std::string& format) throw(XAO_Exception);
171 * MsgBuilder can be use to easily create messages.
182 /** Stream operator. */
183 template <typename T>
184 MsgBuilder& operator <<(const T& t)
191 * Conversion operator to char*.
193 operator const char*() const { return m_stream.str().c_str(); }
197 std::stringstream m_stream;
204 #endif /* __XAO_UTILS_HXX__ */