SALOME - SMESH
|
00001 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 #ifndef MED_Utilities_HeaderFile 00023 #define MED_Utilities_HeaderFile 00024 00025 #include "SMESH_DriverUNV.hxx" 00026 00027 #include <iostream> 00028 #include <sstream> 00029 #include <fstream> 00030 #include <string> 00031 #include <stdexcept> 00032 #include <cassert> 00033 #include <cstdlib> 00034 00035 namespace UNV{ 00036 class MESHDRIVERUNV_EXPORT PrefixPrinter{ 00037 static int myCounter; 00038 public: 00039 PrefixPrinter(); 00040 ~PrefixPrinter(); 00041 00042 static std::string GetPrefix(); 00043 }; 00044 00050 inline bool beginning_of_dataset(std::istream& in_file, const std::string& ds_name) 00051 { 00052 assert (in_file.good()); 00053 assert (!ds_name.empty()); 00054 00055 std::string olds, news; 00056 00057 while(true){ 00058 in_file >> olds >> news; 00059 /* 00060 * a "-1" followed by a number means the beginning of a dataset 00061 * stop combing at the end of the file 00062 */ 00063 while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() ){ 00064 olds = news; 00065 in_file >> news; 00066 } 00067 if(in_file.eof()) 00068 return false; 00069 if (news == ds_name) 00070 return true; 00071 } 00072 // should never end up here 00073 return false; 00074 } 00075 00082 inline double D_to_e(std::string& number) 00083 { 00084 /* find "D" in string, start looking at 00085 * 6th element, to improve speed. 00086 * We dont expect a "D" earlier 00087 */ 00088 const int position = number.find("D",6); 00089 if(position != std::string::npos){ 00090 number.replace(position, 1, "e"); 00091 } 00092 return std::atof (number.c_str()); 00093 } 00094 00100 inline bool check_file(const std::string theFileName) 00101 { 00102 std::ifstream in_stream(theFileName.c_str()); 00103 if (!in_stream) 00104 return false; 00105 std::string olds, news; 00106 while (!in_stream.eof()){ 00107 olds = news; 00108 std::getline(in_stream, news, '\n'); 00109 } 00110 return (olds == " -1"); 00111 } 00112 00113 }; 00114 00115 00116 #ifndef MESSAGE 00117 00118 #define MESSAGE(msg) std::cout<<__FILE__<<"["<<__LINE__<<"]::"<<msg<<endl; 00119 00120 #define BEGMSG(msg) std::cout<<UNV::PrefixPrinter::GetPrefix()<<msg 00121 00122 #define ADDMSG(msg) std::cout<<msg 00123 00124 #endif 00125 00126 00127 #ifndef EXCEPTION 00128 00129 #define EXCEPTION(TYPE, MSG) {\ 00130 std::ostringstream aStream;\ 00131 aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\ 00132 throw TYPE(aStream.str());\ 00133 } 00134 00135 #endif 00136 00137 #endif