diff options
author | Brad King <brad.king@kitware.com> | 2002-10-10 14:43:59 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2002-10-10 14:43:59 (GMT) |
commit | 281f7519e1707bd30ce8f9368b7515396f713af9 (patch) | |
tree | 560dd62bf62c26753d47b870c405677bb30eceb0 /Source/cmStandardIncludes.h | |
parent | 65cc289047fc2a4b444838c690d9bd45eca04f7e (diff) | |
download | CMake-281f7519e1707bd30ce8f9368b7515396f713af9.zip CMake-281f7519e1707bd30ce8f9368b7515396f713af9.tar.gz CMake-281f7519e1707bd30ce8f9368b7515396f713af9.tar.bz2 |
ENH: Renamed cmStringStream to cmOStringStream and added cmIStringStream. Removed cmInputStringStream.
Diffstat (limited to 'Source/cmStandardIncludes.h')
-rw-r--r-- | Source/cmStandardIncludes.h | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index 20c4b0e..d72bb9c 100644 --- a/Source/cmStandardIncludes.h +++ b/Source/cmStandardIncludes.h @@ -162,65 +162,76 @@ struct cmStdString : public std::string StdString(s, pos, n) {} }; -// Define cmStringStream wrapper to hide differences between -// std::stringstream and the old strstream. +// Define cmOStringStream and cmIStringStream wrappers to hide +// differences between std::stringstream and the old strstream. #if !defined(CMAKE_NO_ANSI_STRING_STREAM) -class cmStringStream: public std::ostringstream +class cmOStringStream: public std::ostringstream { public: - cmStringStream() {} + cmOStringStream() {} private: - cmStringStream(const cmStringStream&); - void operator=(const cmStringStream&); + cmOStringStream(const cmOStringStream&); + void operator=(const cmOStringStream&); }; -class cmInputStringStream: public std::istringstream +class cmIStringStream: public std::istringstream { public: typedef std::istringstream Superclass; - cmInputStringStream() {} - cmInputStringStream(const char* c) : Superclass(c) {} + cmIStringStream() {} + cmIStringStream(const std::string& s): Superclass(s) {} private: - cmInputStringStream(const cmInputStringStream&); - void operator=(const cmInputStringStream&); + cmIStringStream(const cmIStringStream&); + void operator=(const cmIStringStream&); }; #else -class cmStrStreamCleanup +class cmOStrStreamCleanup { public: - cmStrStreamCleanup(std::ostrstream& ostr): m_StrStream(ostr) {} - ~cmStrStreamCleanup() { m_StrStream.rdbuf()->freeze(0); } - static void IgnoreUnusedVariable(const cmStrStreamCleanup&) {} + cmOStrStreamCleanup(std::ostrstream& ostr): m_OStrStream(ostr) {} + ~cmOStrStreamCleanup() { m_OStrStream.rdbuf()->freeze(0); } + static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {} protected: - std::ostrstream& m_StrStream; + std::ostrstream& m_OStrStream; }; -class cmStringStream: public std::ostrstream +class cmOStringStream: public std::ostrstream { public: typedef std::ostrstream Superclass; - cmStringStream() {} + cmOStringStream() {} std::string str() { - cmStrStreamCleanup cleanup(*this); - cmStrStreamCleanup::IgnoreUnusedVariable(cleanup); - int pcount = this->pcount(); - const char* ptr = this->Superclass::str(); - return std::string(ptr?ptr:"", pcount); + cmOStrStreamCleanup cleanup(*this); + cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup); + int pcount = this->pcount(); + const char* ptr = this->Superclass::str(); + return std::string(ptr?ptr:"", pcount); } private: - cmStringStream(const cmStringStream&); - void operator=(const cmStringStream&); + cmOStringStream(const cmOStringStream&); + void operator=(const cmOStringStream&); }; -class cmInputStringStream: public std::istrstream + +class cmIStringStream: private std::string, public std::istrstream { public: - typedef std::istrstream Superclass; - cmInputStringStream(const char* c) : Superclass(c) {} + typedef std::string StdString; + typedef std::istrstream IStrStream; + cmIStringStream(): StdString(), IStrStream(this->StdString::c_str()) {} + cmIStringStream(const std::string& s): + StdString(s), IStrStream(this->StdString::c_str()) {} + std::string str() const { return *this; } + void str(const std::string& s) + { + // Very dangerous. If this throws, the object is hosed. When the + // destructor is later called, the program is hosed too. + this->~cmIStringStream(); + new (this) cmIStringStream(s); + } private: - cmInputStringStream(const cmInputStringStream&); - void operator=(const cmInputStringStream&); + cmIStringStream(const cmIStringStream&); + void operator=(const cmIStringStream&); }; #endif - #endif |