debug.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  *  this is part of Spm
00004  *
00005  *  Copyright (c) 2006 Guillaume Chevallereau
00006  *
00007  *  This program is free software. You can redistribute it and/or modify it 
00008  *  under the terms of the GNU General Public License as published by the 
00009  *  Free Software Foundation. Either version 2 of the license or (at your 
00010  *  option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be usefull but WITHOUT
00013  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00014  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
00015  *  more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License along 
00018  *  with this program; if not, write to the Free Software Foundation, Inc., 
00019  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
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

Generated on Wed Jul 4 15:27:21 2007 for libSpm by  doxygen 1.4.6