1 /*  This file is part of MED.
2  *
3  *  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4  *  MED is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU Lesser General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  MED is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include "MEDerreur.hxx"
18 
19 #include <iostream>
20 #include <sstream>
21 //#include <memory>
22 
23 #include <cstdlib>
24 #include <cstring>
25 
26 /**
27  * Class OSS is useful when streaming data through a function
28  * that expect a string as parameter
29  */
30 class OSS
31 {
32 private:
33   std::ostringstream oss_;
34 
35 public:
OSS()36   explicit OSS() : oss_() {}
37 
38   template <class T>
operator <<(T obj)39   OSS & operator<<(T obj)
40   {
41     oss_ << obj;
42     return *this;
43   }
44 
operator std::string()45   operator std::string()
46   {
47     return oss_.str();
48   }
49 
50   // Surtout ne pas écrire le code suivant:
51   // car oss_.str() renvoie une string temporaire
52   //   operator const char*()
53   //   {
54   //     return oss_.str().c_str();
55   //   }
56 
57 
58 }; /* end class OSS */
59 
60 
~MEDerreur()61 MEDerreur::~MEDerreur() throw() {};
62 
MEDerreur(const char * fichier,const unsigned int ligneNo,const char * message,const char * arg)63 MEDerreur::MEDerreur( const char *fichier,
64 		      const unsigned int ligneNo,
65 		      const char * message,
66 		      const char * arg )
67 {
68   OSS oss ;
69   oss << "MEDerreur" ;
70 
71   if ( strcmp(fichier,"") ) {
72     oss << " dans le fichier " << fichier;
73 
74     if ( ligneNo) oss << "[" << ligneNo << "]";
75   }
76 
77   oss << " : " <<  message;
78 
79   _what = oss;
80 }
81 
what(void) const82 const char* MEDerreur::what( void ) const throw ()
83 {
84   return _what.c_str();
85 }
86 
87 
88