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 #include <miniXml/ustring.h>
00028 #include "def.h"
00029 
00030 namespace Spm
00031 {
00032   namespace Util
00033   {
00034     class Output
00035     {
00036       friend class Debug;
00037     protected :
00038       Output ()
00039       {
00040       }
00041 
00042       virtual ~Output ()
00043       {
00044       }
00045 
00046     public :
00047       virtual void out (const miniXml::ustring & str,
00048                         const miniXml::ustring & className,
00049                         const miniXml::ustring & functionName,
00050                         const miniXml::ustring & file,
00051                         int line)
00052       {
00053       }
00054       
00055       virtual void error (const miniXml::ustring & str,
00056                           const miniXml::ustring & className,
00057                           const miniXml::ustring & functionName,
00058                           const miniXml::ustring & file,
00059                           int line)
00060       {
00061       }
00062 
00063       virtual void warning (const miniXml::ustring & str,
00064                             const miniXml::ustring & className,
00065                             const miniXml::ustring & functionName,
00066                             const miniXml::ustring & file,
00067                             int line)
00068       {
00069       }
00070     };
00071 
00072     class Debug
00073     {
00074     private:
00075       Debug (const miniXml::ustring & projectName);
00076       Output * output_;
00077       static std::map<miniXml::ustring,
00078                       boost::shared_ptr<Debug> > debugInstances_;
00079     public:
00080       ~Debug ();
00081       typedef enum 
00082         {
00083           MESSAGE,
00084           WARNING,
00085           ERROR
00086         } messageType_e;
00087       
00093       static boost::shared_ptr<Debug> create (const miniXml::ustring & project);
00094 
00104       void message (const miniXml::ustring & message,
00105                     messageType_e type = MESSAGE,
00106                     const miniXml::ustring & className = "",
00107                     const miniXml::ustring & functionName = "",
00108                     const miniXml::ustring & file = "",
00109                     int line = 0);
00110 
00120       template <class T>  void value (const miniXml::ustring & varName,
00121                                       T & value,
00122                                       const miniXml::ustring & className = "",
00123                                       const miniXml::ustring & functionName = "",
00124                                       const miniXml::ustring & file = "",
00125                                       int line = 0)
00126       {
00127         std::stringstream strStream;
00128         strStream << varName << "=" << value;
00129         output_->out(strStream.str (),
00130                      className,
00131                      functionName,
00132                      file,
00133                      line);
00134       }
00135       
00145       template <class T>  void valueNotRef (const miniXml::ustring & varName,
00146                                             T value,
00147                                             const miniXml::ustring & className = "",
00148                                             const miniXml::ustring & functionName = "",
00149                                             const miniXml::ustring & file = "",
00150                                             int line = 0)
00151       {
00152         std::stringstream strStream;
00153         strStream << varName << EQUAL << value;
00154         output_->out(strStream.str (),
00155                      className,
00156                      functionName,
00157                      file,
00158                      line);
00159       }
00160 
00171       template <class Iterator> void value (const miniXml::ustring & varName,
00172                                             Iterator beginIterator,
00173                                             Iterator endIterator,
00174                                             const miniXml::ustring & className = "",
00175                                             const miniXml::ustring & functionName = "",
00176                                             const miniXml::ustring & file = "",
00177                                             int line = 0)
00178       {
00179         output_->out(varName,
00180                      className,
00181                      functionName,
00182                      file,
00183                      line);
00184         for(;
00185             beginIterator != endIterator;
00186             beginIterator++)
00187           output_->out("\t" + *beginIterator + "\n",
00188                        "",
00189                        "",
00190                        "",
00191                        0);
00192           
00193       }
00194 
00205       template <class Iterator> void mapValue (const miniXml::ustring & varName,
00206                                                Iterator beginIterator,
00207                                                Iterator endIterator,
00208                                                const miniXml::ustring & className = "",
00209                                                const miniXml::ustring & functionName = "",
00210                                                const miniXml::ustring & file = "",
00211                                                int line = 0)
00212       {
00213         output_->out(varName,
00214                      className,
00215                      functionName,
00216                      file,
00217                      line);
00218         for(;
00219             beginIterator != endIterator;
00220             beginIterator++)
00221           output_->out("\t" + beginIterator->first + "=" + beginIterator->second + "\n",
00222                        "",
00223                        "",
00224                        "",
00225                        0);        
00226       }
00227     };
00228   }
00229   miniXml::ustring strUpper (const char * str);
00230 }
00231 
00232 #endif

Generated on Sat Mar 21 17:00:14 2009 for libSpm by  doxygen 1.5.2