All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Console.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /*
18  * Desc: Gazebo Message
19  * Author: Nathan Koenig
20  * Date: 09 June 2007
21  */
22 
23 #ifndef _GAZEBO_CONSOLE_HH_
24 #define _GAZEBO_CONSOLE_HH_
25 
26 #include <iostream>
27 #include <fstream>
28 #include <string>
29 
30 #include "common/CommonTypes.hh"
31 
32 namespace gazebo
33 {
34  namespace common
35  {
38 
40  #define gzmsg (gazebo::common::Console::Instance()->ColorMsg("Msg", 32))
41 
43  #define gzdbg (gazebo::common::Console::Instance()->ColorMsg("Dbg", 36))
44 
46  #define gzwarn (gazebo::common::Console::Instance()->ColorErr("Warning", \
47  __FILE__, __LINE__, 33))
48 
50  #define gzerr (gazebo::common::Console::Instance()->ColorErr("Error", \
51  __FILE__, __LINE__, 31))
52 
54  #define gzclr_start(clr) "\033[1;33m"
55 
56  #define gzclr_end "\033[0m"
57 
58 
59 
62 
65 
66  class Console
67  {
69  private: Console();
70 
72  private: virtual ~Console();
73 
75  public: static Console *Instance();
76 
78  public: void Load();
79 
82  public: void SetQuiet(bool _q);
83 
88  public: std::ostream &ColorMsg(const std::string &_lbl, int _color);
89 
96  public: std::ostream &ColorErr(const std::string &_lbl,
97  const std::string &_file, unsigned int _line, int _color);
98 
101  private: class NullStream : public std::ostream
102  {
104  public: NullStream() : std::ios(0), std::ostream(0) {}
105  };
106 
108  private: NullStream nullStream;
109 
111  private: std::ostream *msgStream;
112 
114  private: std::ostream *errStream;
115 
117  private: static Console *myself;
118  };
120  }
121 }
122 #endif