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)
23 #include "XAO_Exception.hxx"
24 #include "XAO_Xao.hxx"
25 #include "XAO_XaoUtils.hxx"
30 const std::string XaoUtils::intToString(const int& value)
32 std::ostringstream str;
37 const int XaoUtils::stringToInt(const std::string& value)
41 std::istringstream convert(value);
42 if ( !(convert >> res) )
43 throw XAO_Exception(MsgBuilder() << "Cannot convert '" << value << "' to integer.");
47 const std::string XaoUtils::doubleToString(const double& value)
49 std::ostringstream str;
54 const double XaoUtils::stringToDouble(const std::string& value)
58 std::istringstream convert(value);
59 if ( !(convert >> res) )
60 throw XAO_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
64 const std::string XaoUtils::booleanToString(const bool& value)
71 const bool XaoUtils::stringToBoolean(const std::string& value)
74 if (value == "true" || value == "1")
76 if (value == "false" || value == "0")
79 throw XAO_Exception(MsgBuilder() << "Invalid boolean value: " << value);
82 const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
85 if (dimension == XAO::VERTEX)
87 if (dimension == XAO::EDGE)
89 if (dimension == XAO::FACE)
91 if (dimension == XAO::SOLID)
93 if (dimension == XAO::WHOLE)
96 throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
99 const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
102 if (dimension == "vertex")
104 if (dimension == "edge")
106 if (dimension == "face")
108 if (dimension == "solid")
110 if (dimension == "whole")
113 throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
116 const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
119 if (type ==XAO:: BOOLEAN)
121 if (type == XAO::INTEGER)
123 if (type == XAO::DOUBLE)
125 if (type == XAO::STRING)
128 throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
131 const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
134 if (type == "boolean")
136 if (type == "integer")
138 if (type == "double")
140 if (type == "string")
143 throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
146 const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
149 if (format == XAO::BREP)
151 if (format == XAO::STEP)
154 throw XAO_Exception(MsgBuilder() << "Bad format: " << format);
157 const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
160 if (format == "BREP")
162 if (format == "STEP")
165 throw XAO_Exception(MsgBuilder() << "Bad format: " << format);