Salome HOME
86c342f3517012cc6cf267b61f130e95f86abbf5
[modules/yacs.git] / src / bases / Cstr2d.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "Cstr2d.hxx"
20 #include "Exception.hxx"
21
22 #include <iostream>
23 #include <sstream>
24
25 //! replacement for atof witch does not work everywhere
26 /*!
27  * When using xml parser (parser.cxx) from YACSGui_XMLDriver (in GUI context),
28  * instruction like double d = atof(content); where content = "0.8"
29  * gives d = 0 .
30  * the same binary code called from outside GUI context works fine...
31  */ 
32  
33 double Cstr2d(const char* s)
34 {
35   std::istringstream ss(s);
36   double d;
37   if (!(ss >> d))
38     {
39       std::stringstream msg;
40       msg << "problem in conversion from string to double: " << s ;
41       throw YACS::Exception::Exception(msg.str());
42     }
43   return d;
44 }