• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

log.hpp

00001 /* This file is part of Raul.
00002  * Copyright (C) 2009 David Robillard <http://drobilla.net>
00003  *
00004  * Raul is free software; you can redistribute it and/or modify it under the
00005  * terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * Raul is distributed in the hope that it will be useful, but WITHOUT ANY
00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
00012  *
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00016  */
00017 
00018 #ifndef RAUL_LOG_HPP
00019 #define RAUL_LOG_HPP
00020 
00021 #include <iostream>
00022 #include <sstream>
00023 #include <string>
00024 
00025 namespace Raul {
00026 
00030 class LogBuffer : public std::streambuf
00031 {
00032 public:
00033     enum Colour {
00034         DEFAULT = 0,
00035         RED = 31,
00036         GREEN,
00037         YELLOW,
00038         BLUE,
00039         MAGENTA,
00040         CYAN,
00041         WHITE
00042     };
00043 
00044     LogBuffer(const char* prefix="", Colour colour=DEFAULT)
00045         : _prefix(prefix)
00046         , _colour(colour)
00047         , _out(std::cout)
00048     {}
00049 
00051     std::string colour(Colour c);
00052 
00054     std::string plain();
00055 
00056 protected:
00057     int_type overflow(int_type c) {
00058         if (c == '\n')
00059             emit();
00060         else if (c != traits_type::eof())
00061             _line += c;
00062 
00063         return c;
00064     }
00065 
00066     int sync() {
00067         if (!_line.empty())
00068             emit();
00069         return 0;
00070     }
00071 
00072 private:
00073     void emit();
00074 
00075     const char*   _prefix;
00076     Colour        _colour;
00077     std::string   _line;
00078     std::ostream& _out;
00079 };
00080 
00081 
00082 class NullBuffer : public std::streambuf
00083 {
00084 protected:
00085     int_type overflow(int_type c) { return c; }
00086     int      sync()               { return 0; }
00087 };
00088 
00089 
00090 extern std::ostream info;
00091 extern std::ostream warn;
00092 extern std::ostream error;
00093 extern std::ostream debug;
00094 
00095 
00096 } // namespace Raul
00097 
00098 #endif // RAUL_LOG_HPP

Generated on Tue Jan 11 2011 18:26:17 for RAUL by  doxygen 1.7.1