Version: 6.3.1

src/DriverUNV/UNV_Utilities.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 
00023 #ifndef MED_Utilities_HeaderFile
00024 #define MED_Utilities_HeaderFile
00025 
00026 #include "SMESH_DriverUNV.hxx"
00027 
00028 #include <iostream>     
00029 #include <sstream>      
00030 #include <fstream>
00031 #include <string>
00032 #include <stdexcept>
00033 #include <cassert>
00034 #include <cstdlib>
00035 
00036 namespace UNV{
00037   using namespace std;
00038 
00039   class MESHDRIVERUNV_EXPORT PrefixPrinter{
00040     static int myCounter;
00041   public:
00042     PrefixPrinter();
00043     ~PrefixPrinter();
00044 
00045     static string GetPrefix();
00046   };
00047 
00053   inline bool beginning_of_dataset(std::istream& in_file, const std::string& ds_name)
00054   {
00055     assert (in_file.good());
00056     assert (!ds_name.empty());
00057     
00058     std::string olds, news;
00059     
00060     while(true){
00061       in_file >> olds >> news;
00062       /*
00063        * a "-1" followed by a number means the beginning of a dataset
00064        * stop combing at the end of the file
00065        */
00066       while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() ){     
00067         olds = news;
00068         in_file >> news;
00069       }
00070       if(in_file.eof())
00071         return false;
00072       if (news == ds_name)
00073         return true;
00074     }
00075     // should never end up here
00076     return false;
00077   }
00078 
00085   inline double D_to_e(std::string& number)
00086   {
00087     /* find "D" in string, start looking at 
00088      * 6th element, to improve speed.
00089      * We dont expect a "D" earlier
00090      */
00091     const int position = number.find("D",6);
00092     if(position != std::string::npos){
00093       number.replace(position, 1, "e"); 
00094     }
00095     return atof (number.c_str());
00096   }
00097   
00103   inline bool check_file(const std::string theFileName)
00104   {
00105     std::ifstream in_stream(theFileName.c_str());
00106     if (!in_stream)
00107       return false;
00108     std::string olds, news;
00109     while (!in_stream.eof()){
00110       olds = news;
00111       std::getline(in_stream, news, '\n');
00112     }
00113     return (olds == "    -1");
00114   }
00115 
00116 };
00117 
00118 
00119 #ifndef MESSAGE
00120 
00121 #define MESSAGE(msg) std::cout<<__FILE__<<"["<<__LINE__<<"]::"<<msg<<endl;
00122 
00123 #define BEGMSG(msg) std::cout<<UNV::PrefixPrinter::GetPrefix()<<msg
00124 
00125 #define ADDMSG(msg) std::cout<<msg
00126 
00127 #endif
00128 
00129 
00130 #ifndef EXCEPTION
00131 
00132 #define EXCEPTION(TYPE, MSG) {\
00133   std::ostringstream aStream;\
00134   aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
00135   throw TYPE(aStream.str());\
00136 }
00137 
00138 #endif
00139 
00140 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS