1 // Copyright (C) 2013-2024 CEA, EDF, 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 std::string XaoUtils::intToString(int value)
32 std::ostringstream str;
37 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 std::string XaoUtils::doubleToString(double value)
48 std::ostringstream str;
53 double XaoUtils::stringToDouble(const std::string& value)
56 std::istringstream convert(value);
57 if ( !(convert >> res) )
58 throw XAO_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
62 std::string XaoUtils::booleanToString(bool value)
64 return value ? "true" : "false";
67 bool XaoUtils::stringToBoolean(const std::string& value)
69 if (value == "true" || value == "1")
71 if (value == "false" || value == "0")
74 throw XAO_Exception(MsgBuilder() << "Invalid boolean value: " << value);
77 std::string XaoUtils::dimensionToString(XAO::Dimension dimension)
79 if (dimension == XAO::VERTEX)
81 if (dimension == XAO::EDGE)
83 if (dimension == XAO::FACE)
85 if (dimension == XAO::SOLID)
87 if (dimension == XAO::WHOLE)
90 throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
93 XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
95 if (dimension == "vertex")
97 if (dimension == "edge")
99 if (dimension == "face")
101 if (dimension == "solid")
103 if (dimension == "whole")
106 throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
109 std::string XaoUtils::fieldTypeToString(XAO::Type type)
111 if (type ==XAO:: BOOLEAN)
113 if (type == XAO::INTEGER)
115 if (type == XAO::DOUBLE)
117 if (type == XAO::STRING)
120 throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
123 XAO::Type XaoUtils::stringToFieldType(const std::string& type)
125 if (type == "boolean")
127 if (type == "integer")
129 if (type == "double")
131 if (type == "string")
134 throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
137 std::string XaoUtils::shapeFormatToString(XAO::Format format)
139 if (format == XAO::BREP)
141 if (format == XAO::STEP)
144 throw XAO_Exception(MsgBuilder() << "Bad format: " << format);
147 XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
149 if (format == "BREP")
151 if (format == "STEP")
154 throw XAO_Exception(MsgBuilder() << "Bad format: " << format);