00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __DEBUG_H__
00022 #define __DEBUG_H__
00023
00024 #include <boost/shared_ptr.hpp>
00025 #include <sstream>
00026 #include <map>
00027
00028 namespace Spm
00029 {
00030 namespace Util
00031 {
00032 class Output
00033 {
00034 friend class Debug;
00035 protected :
00036 Output ()
00037 {
00038 }
00039
00040 virtual ~Output ()
00041 {
00042 }
00043
00044 public :
00045 virtual void out (const std::string & str,
00046 const std::string & className,
00047 const std::string & functionName,
00048 const std::string & file,
00049 int line)
00050 {
00051 }
00052
00053 virtual void error (const std::string & str,
00054 const std::string & className,
00055 const std::string & functionName,
00056 const std::string & file,
00057 int line)
00058 {
00059 }
00060
00061 virtual void warning (const std::string & str,
00062 const std::string & className,
00063 const std::string & functionName,
00064 const std::string & file,
00065 int line)
00066 {
00067 }
00068 };
00069
00070 typedef enum
00071 {
00072 MESSAGE,
00073 WARNING,
00074 ERROR
00075 } messageType_e;
00076
00077 class Debug
00078 {
00079 private:
00080 Debug (const std::string & projectName);
00081 Output * __output;
00082 static std::map<std::string,
00083 boost::shared_ptr<Debug> > __debugInstances;
00084 public:
00085 static boost::shared_ptr<Debug> create (const std::string & project);
00086
00087 void message (const std::string & message,
00088 messageType_e type = MESSAGE,
00089 const std::string & className = "",
00090 const std::string & functionName = "",
00091 const std::string & file = "",
00092 int line = 0);
00093
00094 template <class T> void value (const std::string & varName,
00095 T & value,
00096 const std::string & className = "",
00097 const std::string & functionName = "",
00098 const std::string & file = "",
00099 int line = 0)
00100 {
00101 std::stringstream strStream;
00102 strStream << varName << "=" << value;
00103 __output->out(strStream.str (),
00104 className,
00105 functionName,
00106 file,
00107 line);
00108 }
00109
00110 template <class T> void valueNotRef (const std::string & varName,
00111 T value,
00112 const std::string & className = "",
00113 const std::string & functionName = "",
00114 const std::string & file = "",
00115 int line = 0)
00116 {
00117 std::stringstream strStream;
00118 strStream << varName << "=" << value;
00119 __output->out(strStream.str (),
00120 className,
00121 functionName,
00122 file,
00123 line);
00124 }
00125
00126 template <class Iterator> void value (const std::string & varName,
00127 Iterator beginIterator,
00128 Iterator endIterator,
00129 const std::string & className = "",
00130 const std::string & functionName = "",
00131 const std::string & file = "",
00132 int line = 0)
00133 {
00134 __output->out(varName,
00135 className,
00136 functionName,
00137 file,
00138 line);
00139 for(;
00140 beginIterator != endIterator;
00141 beginIterator++)
00142 __output->out("\t" + *beginIterator + "\n",
00143 "",
00144 "",
00145 "",
00146 0);
00147
00148 }
00149
00150 template <class Iterator> void mapValue (const std::string & varName,
00151 Iterator beginIterator,
00152 Iterator endIterator,
00153 const std::string & className = "",
00154 const std::string & functionName = "",
00155 const std::string & file = "",
00156 int line = 0)
00157 {
00158 __output->out(varName,
00159 className,
00160 functionName,
00161 file,
00162 line);
00163 for(;
00164 beginIterator != endIterator;
00165 beginIterator++)
00166 __output->out("\t" + beginIterator->first + "=" + beginIterator->second + "\n",
00167 "",
00168 "",
00169 "",
00170 0);
00171 }
00172 };
00173 }
00174 std::string strUpper (const char * str);
00175 }
00176
00177 #endif