Message.h

Go to the documentation of this file.
00001 /************************************************************************
00002  *
00003  * Copyright (C) 2009-2010 Cassio Neri Moreira
00004  *
00005  * This file is part of the KeyValue library.
00006  *
00007  * The KeyValue library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or (at
00010  * your option) any later version.
00011  *
00012  * The KeyValue library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00015  * Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with KeyValue. If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  **************************************************************************/
00021 
00028 #ifndef KEYVALUE_SYS_MESSAGE_H_
00029 #define KEYVALUE_SYS_MESSAGE_H_
00030 
00031 #include <iosfwd>
00032 #include <sstream>
00033 
00034 #include "keyvalue/extern/String.h"
00035 #include "keyvalue/sys/logger/ConsoleColors.h"
00036 
00037 namespace keyvalue {
00038 
00049 class Message {
00050 
00051 public:
00052 
00053   virtual ~Message();
00054 
00060   unsigned int
00061   getLevel() const;
00062 
00068   string
00069   getString() const;
00070 
00076   virtual const string&
00077   getPrefix() const = 0;
00078 
00084   virtual logger::Color
00085   getColor() const = 0;
00086 
00121   template <typename DataType>
00122   Message&
00123   operator&(const DataType& data);
00124 
00125 protected:
00126 
00132   explicit
00133   Message(unsigned int level);
00134 
00135   Message(const Message& orig);
00136 
00137   struct Traits_ {
00138     string        prefix_;
00139     logger::Color color_;
00140   };
00141 
00142   static const Traits_ traits_[];
00143 
00144 private:
00145 
00146   unsigned int                level_;
00147   mutable std::ostringstream  buf_;
00148 
00149   // Non assignable.
00150   Message&
00151   operator=(const Message& orig);
00152 
00153 }; // class Message
00154 
00160 std::ostream&
00161 operator<<(std::ostream& os, const Message& message);
00162 
00163 /*--------------------------------------------------------------------------
00164  * operator&()
00165  *------------------------------------------------------------------------*/
00166 
00167 template <typename DataType>
00168 Message&
00169 Message::operator&(const DataType& data) {
00170   buf_ << data;
00171   return *this;
00172 }
00173 
00174 } // namespace keyvalue
00175 
00176 #endif // KEYVALUE_SYS_MESSAGE_H_

Generated on Sat Mar 20 15:08:29 2010 for KeyValue by  doxygen 1.6.1