stringizer.hpp

Go to the documentation of this file.
00001 #ifndef IOF_STRINGIZER_HPP_
00002 #define IOF_STRINGIZER_HPP_
00003 
00004 
00018 #include "iof/fmtr.hpp"
00019 
00020 namespace iof
00021 {
00022     
00023 
00031 class stringizer
00032 {
00033 public:
00034     stringizer(const std::string& fmt): my_fmtr(my_out, fmt, false) {}
00035     
00036     // note that std::ios_base::ate does not work with VC++, must use <<
00037     stringizer(const stringizer& rhs)
00038         : my_fmtr(my_out, rhs.my_fmtr) {my_out << rhs.my_out.str();}
00039     
00040     //~stringizer() {std::cout << "dest " << (void*)this << std::endl;}
00041     
00042     bool operator==(const stringizer& rhs) const 
00043     {
00044         return my_out.str() == rhs.my_out.str() && my_fmtr == rhs.my_fmtr;
00045     }
00046     bool operator!=(const stringizer& rhs) const {return !(*this == rhs);}
00047     
00048     template <typename TT>
00049     stringizer& operator<<(const TT& obj) {my_fmtr << obj; return *this;}
00050     
00051     template <typename TT>
00052     stringizer& operator&(const TT& obj)  {my_fmtr &  obj; return *this;}
00053     
00054     operator std::string() 
00055     {
00056         // check that all markers have been used up!
00057         my_fmtr.throwIfRemaining();
00058         return my_out.str();
00059     }
00060 
00061     std::string fmt() const {return my_fmtr.fmt();}
00062     
00063 private:
00064     std::ostringstream my_out;
00065     iof_private::fmtr_out my_fmtr;
00066 };
00067 
00068 
00069 } // namespace iof
00070 
00071 
00072 #endif // IOF_STRINGIZER_HPP_

Generated on Fri Nov 24 16:16:01 2006 for IOF Library by doxygen 1.5.1-p1
Thanks to SourceForge.net Logo for hosting