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)
23 #include "XAO_Xao.hxx"
24 #include "XAO_XaoUtils.hxx"
29 const std::string XaoUtils::intToString(const int& value)
31 std::ostringstream str;
36 const int XaoUtils::stringToInt(const std::string& value)
40 std::istringstream convert(value);
41 if ( !(convert >> res) )
42 throw XAO_Exception(MsgBuilder() << "Cannot convert '" << value << "' to integer.");
46 const std::string XaoUtils::doubleToString(const double& value)
48 std::ostringstream str;
53 const double XaoUtils::stringToDouble(const std::string& value)
57 std::istringstream convert(value);
58 if ( !(convert >> res) )
59 throw XAO_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
63 const std::string XaoUtils::booleanToString(const bool& value)
70 const bool XaoUtils::stringToBoolean(const std::string& value)
73 if (value == "true" || value == "1")
75 if (value == "false" || value == "0")
78 throw XAO_Exception(MsgBuilder() << "Invalid boolean value: " << value);
81 const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
84 if (dimension == XAO::VERTEX)
86 if (dimension == XAO::EDGE)
88 if (dimension == XAO::FACE)
90 if (dimension == XAO::SOLID)
92 if (dimension == XAO::WHOLE)
95 throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
98 const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
101 if (dimension == "vertex")
103 if (dimension == "edge")
105 if (dimension == "face")
107 if (dimension == "solid")
109 if (dimension == "whole")
112 throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
115 const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
118 if (type ==XAO:: BOOLEAN)
120 if (type == XAO::INTEGER)
122 if (type == XAO::DOUBLE)
124 if (type == XAO::STRING)
127 throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
130 const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
133 if (type == "boolean")
135 if (type == "integer")
137 if (type == "double")
139 if (type == "string")
142 throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
145 const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
148 if (format == XAO::BREP)
150 if (format == XAO::STEP)
153 throw XAO_Exception(MsgBuilder() << "Bad format: " << format);
156 const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
159 if (format == "BREP")
161 if (format == "STEP")
164 throw XAO_Exception(MsgBuilder() << "Bad format: " << format);