1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef MED_Utilities_HeaderFile
24 #define MED_Utilities_HeaderFile
26 #include "SMESH_DriverUNV.hxx"
39 const size_t theMaxLineLen = 80;
41 class MESHDRIVERUNV_EXPORT PrefixPrinter{
47 static string GetPrefix();
51 * @returns \p false when error occured, \p true otherwise.
52 * Adjusts the \p in_stream to the beginning of the
55 inline bool beginning_of_dataset(std::istream& in_file, const std::string& ds_name)
57 assert (in_file.good());
58 assert (!ds_name.empty());
60 std::string olds, news;
64 in_file >> olds >> news;
66 * a "-1" followed by a number means the beginning of a dataset
67 * stop combing at the end of the file
69 while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() ){
81 // should never end up here
86 * Method for converting exponential notation
87 * from "D" to "e", for example
88 * \p 3.141592654D+00 \p --> \p 3.141592654e+00
89 * in order to make it readable for C++.
91 inline double D_to_e(std::string& number)
93 /* find "D" in string, start looking at
94 * 6th element, to improve speed.
95 * We dont expect a "D" earlier
97 const int position = number.find("D",6);
98 if(position != std::string::npos){
99 number.replace(position, 1, "e");
101 return atof (number.c_str());
105 * @returns \p false when file is incorrect, \p true otherwise.
106 * Check file with name \p theFileName for correct terminate
107 * string, i.e. the next to the last line is equal to " -1",
109 inline bool check_file(const std::string theFileName)
111 std::ifstream in_stream(theFileName.c_str());
114 std::string olds, news;
115 while (!in_stream.eof()){
117 std::getline(in_stream, news, '\n');
119 return (olds == " -1");
123 * \brief reads a whole line
124 * \param in_stream - source stream
125 * \param next - if true, first reads the current line up to the end
126 * which is necessary after reading using >> operator
127 * \retval std::string - the result line
129 inline std::string read_line(std::ifstream& in_stream, const bool next=true)
131 char line[theMaxLineLen];
132 in_stream.getline( line, theMaxLineLen );
134 in_stream.getline( line, theMaxLineLen );
136 std::string resLine = line;
137 if ( resLine.size() > 0 && resLine[ resLine.size()-1 ] == '\r' )
138 resLine.resize( resLine.size()-1 );
146 #define MESSAGE(msg) std::cout<<__FILE__<<"["<<__LINE__<<"]::"<<msg<<endl;
148 #define BEGMSG(msg) std::cout<<UNV::PrefixPrinter::GetPrefix()<<msg
150 #define ADDMSG(msg) std::cout<<msg
157 #define EXCEPTION(TYPE, MSG) {\
158 std::ostringstream aStream;\
159 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
160 throw TYPE(aStream.str());\