X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=include%2Fsstream;fp=include%2Fsstream;h=69d4ee2804672e0fda8b344d5038c1f2213dde94;hb=b5857e74e5735455b5ef11cbea5044ae7b2e8a0d;hp=0000000000000000000000000000000000000000;hpb=4ff5096195e60f80c985d5762d74329406ffa21a;p=ctsim.git diff --git a/include/sstream b/include/sstream new file mode 100644 index 0000000..69d4ee2 --- /dev/null +++ b/include/sstream @@ -0,0 +1,110 @@ +#ifndef __CM_SSTREAM__ +#define __CM_SSTREAM__ + +#include +#include +#include +#include + +namespace std { + +class ostringstream +{ +public: + ostringstream (const string & str = "") + : buffer(str) {} + + const string & str() const + { + return buffer; + } + + void str (const string & new_string) + { + buffer = new_string; + } + + ostringstream & operator<< (const string & item) + { + buffer += item; + + return *this; + } + + ostringstream & operator<< (int item) + { + char temp[100]; + + sprintf (temp, "%d", item); + buffer += temp; + + return *this; + } + + ostringstream & operator<< (unsigned int item) + { + char temp[100]; + + sprintf (temp, "%u", item); + buffer += temp; + + return *this; + } + + ostringstream & operator<< (char item) + { + buffer += item; + return *this; + } + + ostringstream & operator<< (double item) + { + char temp[1000]; + + sprintf (temp, "%g", item); + buffer += temp; + + return *this; + } + +private: + string buffer; +}; + + + +class istringstream +{ + friend istringstream & getline (istringstream &, string &, char = '\n'); + +public: + istringstream (const string & str = "") + : buffer (str.c_str(), str.length()) {} + + template + istringstream & operator>> (T & item) + { + buffer >> item; + return *this; + } + + operator void * () const + { + return (void *) buffer; + } + +private: + istrstream buffer; +}; + + +inline istringstream & getline (istringstream & src_stream, string & str, char separator) +{ + getline (src_stream.buffer, str, separator); + return src_stream; +} + +} // End of namespace std + +#endif +