]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_STRING.hxx
Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / MEDMEM_STRING.hxx
1 # ifndef MEDMEM_STRING_HXX
2 # define MEDMEM_STRING_HXX
3
4 using namespace std;
5
6 # include <string>
7 # include <strstream>
8
9 /*!
10  A class to generate string from any type:
11
12  here is a simple use case
13       STRING msgErr;
14       msgErr << "This Object cannot be instanciated by now ! Try "<< 11 << "times just to see what happens ";
15       throw SALOME_EXCEPTION (LOCALIZED(msgErr)) ;
16                                                                 */
17 class STRING : public string
18 {
19
20 private :
21   ostrstream _s ;
22
23 public :
24   
25   STRING::STRING() :string(), _s() 
26    {
27    }
28
29   STRING::~STRING()
30    {
31         _s.freeze(false);
32    }
33
34   STRING::operator const char * () const 
35    {     
36         return const_cast <const char *> (this->c_str()) ;
37    }
38
39    template <class T> STRING::STRING( const T &valeur ) : string(), _s() 
40    {
41         _s.freeze(false);
42
43         _s << valeur ;
44         _s << ends;
45
46         this->string::operator =( _s.str());  // freeze is true by now
47    }
48
49    template <class T> STRING & STRING::operator<<( const T &valeur )
50    {
51   
52         if ( _s.pcount() )
53         {
54                 _s.seekp(-1, ios::cur); // Back up before NULL
55                 _s.rdbuf()->freeze(0); // Unfreeze it
56         }
57
58         _s << valeur ;
59         _s << ends;
60
61         this->string::operator = ( _s.str() ) ;  // freeze is true by now
62         _s.freeze( false ) ;
63         return *this ;
64
65
66    }
67 } ;
68
69 # endif