X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=include%2Fsstream_subst;fp=include%2Fsstream_subst;h=c89ffdc3e36fa99868abe97f7391003001c06e3b;hb=7c3c1727423ad6c0f56ac45ac33f250b4029dc88;hp=0000000000000000000000000000000000000000;hpb=e0fe7f917f52ea92621348e501400a3d1e9da96d;p=ctsim.git diff --git a/include/sstream_subst b/include/sstream_subst new file mode 100644 index 0000000..c89ffdc --- /dev/null +++ b/include/sstream_subst @@ -0,0 +1,114 @@ +#ifndef __CM_SSTREAM__ +#define __CM_SSTREAM__ + +#ifndef MSVC + +#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 + +#endif +