geom/src/XAO/XaoUtils.cxx

121 lines
3.0 KiB
C++
Raw Normal View History

// Copyright (C) 2013 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// Author : Frederic Pons (OpenCascade)
#include <cstring>
#include <sstream>
#include <iosfwd>
#include <Utils_SALOME_Exception.hxx>
#include "Xao.hxx"
2013-08-27 11:27:42 +00:00
#include "Field.hxx"
#include "XaoUtils.hxx"
using namespace XAO;
2013-08-28 15:22:43 +00:00
const std::string XaoUtils::intToString(const int& value)
2013-08-27 11:27:42 +00:00
{
std::ostringstream str;
str << value;
return str.str();
}
2013-08-28 15:22:43 +00:00
const int XaoUtils::stringToInt(const std::string& value)
2013-08-27 11:27:42 +00:00
{
int res;
std::istringstream convert(value);
if ( !(convert >> res) )
res = 0;
return res;
}
2013-08-28 15:22:43 +00:00
const std::string XaoUtils::doubleToString(const double& value)
2013-08-27 11:27:42 +00:00
{
std::ostringstream str;
str << value;
return str.str();
}
2013-08-28 15:22:43 +00:00
const double XaoUtils::stringToDouble(const std::string& value)
{
double res;
std::istringstream convert(value);
if ( !(convert >> res) )
res = 0;
return res;
}
const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
{
if (dimension == VERTEX)
return "vertex";
if (dimension == EDGE)
return "edge";
if (dimension == FACE)
return "face";
if (dimension == SOLID)
return "solid";
2013-08-27 11:27:42 +00:00
if (dimension == WHOLE)
return "whole";
throw SALOME_Exception("Bad dimension");
}
2013-08-28 15:22:43 +00:00
const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
{
2013-08-28 15:22:43 +00:00
if (dimension == "vertex")
return VERTEX;
2013-08-28 15:22:43 +00:00
if (dimension == "edge")
return EDGE;
2013-08-28 15:22:43 +00:00
if (dimension == "face")
return FACE;
2013-08-28 15:22:43 +00:00
if (dimension == "solid")
return SOLID;
2013-08-28 15:22:43 +00:00
if (dimension == "whole")
2013-08-27 11:27:42 +00:00
return WHOLE;
throw SALOME_Exception("Bad dimension");
}
2013-08-27 11:27:42 +00:00
2013-08-28 15:22:43 +00:00
const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
2013-08-27 11:27:42 +00:00
{
if (type == BOOLEAN)
return "boolean";
if (type == INTEGER)
return "integer";
if (type == DOUBLE)
return "double";
if (type == STRING)
return "string";
throw SALOME_Exception("Bad type");
}
2013-08-28 15:22:43 +00:00
const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
2013-08-27 11:27:42 +00:00
{
2013-08-28 15:22:43 +00:00
if (type == "boolean")
2013-08-27 11:27:42 +00:00
return BOOLEAN;
2013-08-28 15:22:43 +00:00
if (type == "integer")
2013-08-27 11:27:42 +00:00
return INTEGER;
2013-08-28 15:22:43 +00:00
if (type == "double")
2013-08-27 11:27:42 +00:00
return DOUBLE;
2013-08-28 15:22:43 +00:00
if (type == "string")
2013-08-27 11:27:42 +00:00
return STRING;
throw SALOME_Exception("Bad type");
}