c89ffdc3e36fa99868abe97f7391003001c06e3b
[ctsim.git] / include / sstream_subst
1 #ifndef __CM_SSTREAM__
2 #define __CM_SSTREAM__
3 \r
4 #ifndef MSVC\r
5
6 #include <string>
7 #include <cstdio>
8 #include <strstream>
9 #include <algorithm>
10
11 namespace std {
12
13 class ostringstream
14 {
15 public:
16     ostringstream (const string & str = "")
17         : buffer(str) {}
18
19     const string & str() const
20     {
21         return buffer;
22     }
23
24     void str (const string & new_string)
25     {
26         buffer = new_string;
27     }
28
29     ostringstream & operator<< (const string & item)
30     {
31         buffer += item;
32
33         return *this;
34     }
35
36     ostringstream & operator<< (int item)
37     {
38         char temp[100];
39
40         sprintf (temp, "%d", item);
41         buffer += temp;
42
43         return *this;
44     }
45
46     ostringstream & operator<< (unsigned int item)
47     {
48         char temp[100];
49
50         sprintf (temp, "%u", item);
51         buffer += temp;
52
53         return *this;
54     }
55
56     ostringstream & operator<< (char item)
57     {
58         buffer += item;
59         return *this;
60     }
61
62     ostringstream & operator<< (double item)
63     {
64         char temp[1000];
65
66         sprintf (temp, "%g", item);
67         buffer += temp;
68
69         return *this;
70     }
71
72 private:
73     string buffer;
74 };
75
76
77
78 class istringstream
79 {
80     friend istringstream & getline (istringstream &, string &, char = '\n');
81
82 public:
83     istringstream (const string & str = "")
84         : buffer (str.c_str(), str.length()) {}
85
86     template <class T>
87     istringstream & operator>> (T & item)
88     {
89         buffer >> item;
90         return *this;
91     }
92
93     operator void * () const
94     {
95         return (void *) buffer;
96     }
97
98 private:
99     istrstream buffer;
100 };
101
102
103 inline istringstream & getline (istringstream & src_stream, string & str, char separator)
104 {
105     getline (src_stream.buffer, str, separator);
106     return src_stream;
107 }
108
109 }   // End of namespace std
110 \r
111 #endif\r
112
113 #endif
114