00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012  
00013 
00014 #ifndef CNTM_FORMATUTILS_H
00015 #define CNTM_FORMATUTILS_H
00016 #include <string>
00017 #include <sstream>
00018 
00019 namespace Cntm
00020 {
00021 
00022 
00023 
00024 
00025         struct FormatMsgPrmConvertor
00026         {
00027 
00028 
00029 
00030                 std::string Str;
00031 
00032 
00033 
00034 
00035                 FormatMsgPrmConvertor() {}
00036 
00037 
00038 
00039 
00040                 template <typename T> FormatMsgPrmConvertor(const T& Prm);
00041         };
00042 
00043         template <class T>
00044         FormatMsgPrmConvertor::FormatMsgPrmConvertor(const T& Prm)
00045         {
00046                 std::ostringstream PrmConv;     
00047                 PrmConv << Prm;                         
00048                 Str = PrmConv.str();            
00049         }
00050 
00051 
00052 
00053 
00054 
00055 
00056         std::string FormatMsg(const std::string& Fmt,
00057                 const FormatMsgPrmConvertor& Prm1 = FormatMsgPrmConvertor(),
00058                 const FormatMsgPrmConvertor& Prm2 = FormatMsgPrmConvertor());
00059 
00060 
00061 
00062 
00063 
00064 
00065         std::string FormatMsg(const std::string& Fmt,
00066                 const FormatMsgPrmConvertor& Prm1,
00067                 const FormatMsgPrmConvertor& Prm2,
00068                 const FormatMsgPrmConvertor& Prm3,
00069                 const FormatMsgPrmConvertor& Prm4 = FormatMsgPrmConvertor());
00070 
00071 
00072 
00073 
00074 
00075 
00076         std::string FormatMsg(const std::string& Fmt,
00077                 const FormatMsgPrmConvertor& Prm1,
00078                 const FormatMsgPrmConvertor& Prm2,
00079                 const FormatMsgPrmConvertor& Prm3,
00080                 const FormatMsgPrmConvertor& Prm4,
00081                 const FormatMsgPrmConvertor& Prm5,
00082                 const FormatMsgPrmConvertor& Prm6 = FormatMsgPrmConvertor(),
00083                 const FormatMsgPrmConvertor& Prm7 = FormatMsgPrmConvertor(),
00084                 const FormatMsgPrmConvertor& Prm8 = FormatMsgPrmConvertor());
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095         class FormatString: public std::string
00096         {
00097         public:
00098 
00099 
00100 
00101 
00102                 FormatString(): std::string() {}
00103 
00104 
00105 
00106 
00107                 FormatString(const char* Str): std::string(Str) {}
00108 
00109 
00110 
00111 
00112                 FormatString(const std::string& Str): std::string(Str) {}
00113 
00114 
00115 
00116 
00117 
00118 
00119                 std::string operator()(
00120                         const FormatMsgPrmConvertor& Prm1 = FormatMsgPrmConvertor(),
00121                         const FormatMsgPrmConvertor& Prm2 = FormatMsgPrmConvertor()) const
00122                         { return FormatMsg(*this, Prm1, Prm2); }
00123 
00124 
00125 
00126 
00127 
00128 
00129                 std::string operator()(
00130                         const FormatMsgPrmConvertor& Prm1,
00131                         const FormatMsgPrmConvertor& Prm2,
00132                         const FormatMsgPrmConvertor& Prm3,
00133                         const FormatMsgPrmConvertor& Prm4 = FormatMsgPrmConvertor()) const
00134                         { return FormatMsg(*this, Prm1, Prm2, Prm3, Prm4); }
00135 
00136 
00137 
00138 
00139 
00140 
00141                 std::string operator()(
00142                         const FormatMsgPrmConvertor& Prm1,
00143                         const FormatMsgPrmConvertor& Prm2,
00144                         const FormatMsgPrmConvertor& Prm3,
00145                         const FormatMsgPrmConvertor& Prm4,
00146                         const FormatMsgPrmConvertor& Prm5,
00147                         const FormatMsgPrmConvertor& Prm6 = FormatMsgPrmConvertor(),
00148                         const FormatMsgPrmConvertor& Prm7 = FormatMsgPrmConvertor(),
00149                         const FormatMsgPrmConvertor& Prm8 = FormatMsgPrmConvertor()) const
00150                         { return FormatMsg(*this, Prm1, Prm2, Prm3, Prm4, Prm5, Prm6, Prm7, Prm8); }
00151         };
00152 
00153 }
00154 
00155 #endif //CNTM_FORMATUTILS_H