Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
util/liblogger/logger_manipulators.h
00001 // copyright 2009 t. schneider tes@mit.edu
00002 // 
00003 // this file is part of goby-logger,
00004 // the goby logging library
00005 //
00006 // This program is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This software is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 #ifndef LoggerManipulators20091110H
00020 #define LoggerManipulators20091110H
00021 
00022 #include <iostream>
00023 #include <string>
00024 
00025 #include "term_color.h"
00026 
00027 namespace goby { namespace util { class FlexOstream; } }
00028            
00030 inline std::ostream& die(std::ostream & os)
00031 { return (os << goby::util::tcolor::red << "(Error): " << goby::util::tcolor::nocolor); }
00032 
00034 inline std::ostream& warn(std::ostream & os)
00035 { return (os << goby::util::tcolor::red << "(Warning): " << goby::util::tcolor::nocolor); }
00036 
00038 inline std::ostream& debug(std::ostream & os)
00039 { return (os << "(Debug): "); }
00040 
00042 class Group
00043 {
00044   public:
00045   Group(const std::string& name = "",
00046         const std::string& description = "",
00047         goby::util::Colors::Color color = goby::util::Colors::nocolor)
00048       : name_(name),
00049         description_(description),
00050         color_(color),
00051         enabled_(true)
00052         {}
00053 
00055 
00056 
00057     std::string name() const
00058     { return name_; }
00060     std::string description() const
00061     { return description_; }        
00063     goby::util::Colors::Color color() const
00064     { return color_; }
00066     bool enabled() const
00067     { return enabled_; }
00069 
00071 
00072     void name(const std::string & s)        { name_ = s; }    
00073     void description(const std::string & s) { description_ = s; }    
00074     void color(goby::util::Colors::Color c) { color_ = c; }        
00075     void enabled(bool b)                    { enabled_ = b; }
00077     
00078   private:
00079     std::string name_;
00080     std::string description_;
00081     goby::util::Colors::Color color_;
00082     bool enabled_;
00083 };
00084 
00085 
00086 std::ostream& operator<< (std::ostream& os, const Group & g);
00087 
00089 class GroupSetter
00090 {
00091     
00092   public:
00093     explicit GroupSetter (const std::string& s) : group_(s) { }
00094     void operator()(std::ostream& os) const;
00095     void operator()(goby::util::FlexOstream& os) const;
00096     
00097   private:
00098     std::string group_;
00099 };
00100 
00101 inline GroupSetter group(std::string n) 
00102 { return(GroupSetter(n)); }
00103 
00104 inline std::ostream& operator<<(std::ostream& os, const GroupSetter & gs)
00105 {
00106     gs(os);
00107     return(os);
00108 }
00109 
00110 inline goby::util::FlexOstream& operator<<(goby::util::FlexOstream& os, const GroupSetter & gs)
00111 {
00112     gs(os);
00113     return(os);
00114 }
00115 
00117 std::ostream& basic_log_header(std::ostream& os, const std::string& group_name);
00118 
00119 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends