1 // Copyright (C) 2013 CEA/DEN, EDF R&D
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.
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__
28 #include "XAO_Exception.hxx"
47 VERTEX = 0,//!< VERTEX
59 BOOLEAN = 0,//!< BOOLEAN
60 INTEGER = 1,//!< INTEGER
61 DOUBLE = 2, //!< DOUBLE
62 STRING = 3 //!< STRING
67 * Utilities class to convert types.
73 * Converts an integer into a string.
74 * \param value the integer to convert.
77 static const std::string intToString(const int& value);
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.
85 static const int stringToInt(const std::string& value) throw(XAO_Exception);
88 * Converts a double into a string.
89 * \param value the double to convert.
92 static const std::string doubleToString(const double& value);
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.
99 static const double stringToDouble(const std::string& value) throw(XAO_Exception);
102 * Converts a boolean into a string.
103 * \param value the boolean to convert.
104 * \return the string.
106 static const std::string booleanToString(const bool& value);
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".
114 static const bool stringToBoolean(const std::string& value) throw(XAO_Exception);
117 * Converts a Dimension to string.
118 * \param dimension the Dimension to convert.
119 * \return the dimension as a string.
120 * \throw XAO_Exception
122 static const std::string dimensionToString(const XAO::Dimension& dimension) throw(XAO_Exception);
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.
130 static const XAO::Dimension stringToDimension(const std::string& dimension) throw(XAO_Exception);
133 * Converts a Type to string.
134 * \param type the Type to convert.
135 * \return the Type as a string.
136 * \throw XAO_Exception
138 static const std::string fieldTypeToString(const XAO::Type& type) throw(XAO_Exception);
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.
146 static const XAO::Type stringToFieldType(const std::string& type) throw(XAO_Exception);
149 * Converts a Format to string.
150 * \param format the Format to convert.
151 * \return the Format as a string.
152 * \throw XAO_Exception
154 static const std::string shapeFormatToString(const XAO::Format& format) throw(XAO_Exception);
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.
162 static const XAO::Format stringToShapeFormat(const std::string& format) throw(XAO_Exception);
167 * MsgBuilder can be use to easily create messages.
178 /** Stream operator. */
179 template <typename T>
180 MsgBuilder& operator <<(const T& t)
187 * Conversion operator to char*.
189 operator const char*() const { return m_stream.str().c_str(); }
193 std::stringstream m_stream;
200 #endif /* __XAO_UTILS_HXX__ */