Point Cloud Library (PCL)  1.14.1-dev
print.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder(s) nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #pragma once
39 
40 #include <cstdio>
41 
42 #include <pcl/pcl_exports.h>
43 #include <pcl/pcl_config.h>
44 
45 // Use e.g. like this:
46 // PCL_INFO_STREAM("Info: this is a point: " << pcl::PointXYZ(1.0, 2.0, 3.0) << std::endl);
47 // PCL_ERROR_STREAM("Error: an Eigen vector: " << std::endl << Eigen::Vector3f(1.0, 2.0, 3.0) << std::endl);
48 // NOLINTBEGIN(bugprone-macro-parentheses)
49 #define PCL_LOG_STREAM(LEVEL, STREAM, CSTR, ATTR, FG, ARGS) if(pcl::console::isVerbosityLevelEnabled(pcl::console::LEVEL)) { fflush(stdout); pcl::console::change_text_color(CSTR, pcl::console::ATTR, pcl::console::FG); STREAM << ARGS; pcl::console::reset_text_color(CSTR); }
50 // NOLINTEND(bugprone-macro-parentheses)
51 #define PCL_ALWAYS_STREAM(ARGS) PCL_LOG_STREAM(L_ALWAYS, std::cout, stdout, TT_RESET, TT_WHITE, ARGS)
52 #define PCL_ERROR_STREAM(ARGS) PCL_LOG_STREAM(L_ERROR, std::cerr, stderr, TT_BRIGHT, TT_RED, ARGS)
53 #define PCL_WARN_STREAM(ARGS) PCL_LOG_STREAM(L_WARN, std::cerr, stderr, TT_BRIGHT, TT_YELLOW, ARGS)
54 #define PCL_INFO_STREAM(ARGS) PCL_LOG_STREAM(L_INFO, std::cout, stdout, TT_RESET, TT_WHITE, ARGS)
55 #define PCL_DEBUG_STREAM(ARGS) PCL_LOG_STREAM(L_DEBUG, std::cout, stdout, TT_RESET, TT_GREEN, ARGS)
56 #define PCL_VERBOSE_STREAM(ARGS) PCL_LOG_STREAM(L_VERBOSE, std::cout, stdout, TT_RESET, TT_WHITE, ARGS)
57 
58 
59 #define PCL_ALWAYS(...) pcl::console::print (pcl::console::L_ALWAYS, __VA_ARGS__)
60 #define PCL_ERROR(...) pcl::console::print (pcl::console::L_ERROR, __VA_ARGS__)
61 #define PCL_WARN(...) pcl::console::print (pcl::console::L_WARN, __VA_ARGS__)
62 #define PCL_INFO(...) pcl::console::print (pcl::console::L_INFO, __VA_ARGS__)
63 #define PCL_DEBUG(...) pcl::console::print (pcl::console::L_DEBUG, __VA_ARGS__)
64 #define PCL_VERBOSE(...) pcl::console::print (pcl::console::L_VERBOSE, __VA_ARGS__)
65 #define PCL_HIGH(...) pcl::console::print_highlight (__VA_ARGS__)
66 
67 #define PCL_ASSERT_ERROR_PRINT_CHECK(pred, msg) \
68  do \
69  { \
70  if (!(pred)) \
71  { \
72  PCL_ERROR(msg); \
73  PCL_ERROR("In File %s, in line %d\n" __FILE__, __LINE__); \
74  } \
75  } while (0)
76 
77 #define PCL_ASSERT_ERROR_PRINT_RETURN(pred, msg, err) \
78  do \
79  { \
80  PCL_ASSERT_ERROR_PRINT_CHECK(pred, msg); \
81  if (!(pred)) return err; \
82  } while (0)
83 
84 namespace pcl
85 {
86  namespace console
87  {
89  {
90  TT_RESET = 0,
91  TT_BRIGHT = 1,
92  TT_DIM = 2,
94  TT_BLINK = 4,
96  TT_HIDDEN = 8
97  };
98 
99  enum TT_COLORS
100  {
108  TT_WHITE
109  };
110 
112  {
118  L_VERBOSE
119  };
120 
121  /** set the verbosity level */
122  PCL_EXPORTS void
124 
125  /** get the verbosity level. */
128 
129  /** initialize verbosity level. */
130  PCL_EXPORTS bool
132 
133  /** is verbosity level enabled? */
134  PCL_EXPORTS bool
136 
137  /** \brief Enable or disable colored text output, overriding the default behavior.
138  *
139  * By default, colored output is enabled for interactive terminals or when the environment
140  * variable PCL_CLICOLOR_FORCE is set.
141  *
142  * \param stream the output stream (stdout, stderr, etc)
143  * \param enable whether to emit color codes when calling any of the color related methods
144  */
145  PCL_EXPORTS void
146  enableColoredOutput (FILE *stream, bool enable);
147 
148  /** \brief Change the text color (on either stdout or stderr) with an attr:fg:bg
149  * \param stream the output stream (stdout, stderr, etc)
150  * \param attribute the text attribute
151  * \param fg the foreground color
152  * \param bg the background color
153  */
154  PCL_EXPORTS void
155  change_text_color (FILE *stream, int attribute, int fg, int bg);
156 
157  /** \brief Change the text color (on either stdout or stderr) with an attr:fg
158  * \param stream the output stream (stdout, stderr, etc)
159  * \param attribute the text attribute
160  * \param fg the foreground color
161  */
162  PCL_EXPORTS void
163  change_text_color (FILE *stream, int attribute, int fg);
164 
165  /** \brief Reset the text color (on either stdout or stderr) to its original state
166  * \param stream the output stream (stdout, stderr, etc)
167  */
168  PCL_EXPORTS void
169  reset_text_color (FILE *stream);
170 
171  /** \brief Print a message on stream with colors
172  * \param stream the output stream (stdout, stderr, etc)
173  * \param attr the text attribute
174  * \param fg the foreground color
175  * \param format the message
176  */
177  PCL_EXPORTS void
178  print_color (FILE *stream, int attr, int fg, const char *format, ...);
179 
180  /** \brief Print an info message on stream with colors
181  * \param format the message
182  */
183  PCL_EXPORTS void
184  print_info (const char *format, ...);
185 
186  /** \brief Print an info message on stream with colors
187  * \param stream the output stream (stdout, stderr, etc)
188  * \param format the message
189  */
190  PCL_EXPORTS void
191  print_info (FILE *stream, const char *format, ...);
192 
193  /** \brief Print a highlighted info message on stream with colors
194  * \param format the message
195  */
196  PCL_EXPORTS void
197  print_highlight (const char *format, ...);
198 
199  /** \brief Print a highlighted info message on stream with colors
200  * \param stream the output stream (stdout, stderr, etc)
201  * \param format the message
202  */
203  PCL_EXPORTS void
204  print_highlight (FILE *stream, const char *format, ...);
205 
206  /** \brief Print an error message on stream with colors
207  * \param format the message
208  */
209  PCL_EXPORTS void
210  print_error (const char *format, ...);
211 
212  /** \brief Print an error message on stream with colors
213  * \param stream the output stream (stdout, stderr, etc)
214  * \param format the message
215  */
216  PCL_EXPORTS void
217  print_error (FILE *stream, const char *format, ...);
218 
219  /** \brief Print a warning message on stream with colors
220  * \param format the message
221  */
222  PCL_EXPORTS void
223  print_warn (const char *format, ...);
224 
225  /** \brief Print a warning message on stream with colors
226  * \param stream the output stream (stdout, stderr, etc)
227  * \param format the message
228  */
229  PCL_EXPORTS void
230  print_warn (FILE *stream, const char *format, ...);
231 
232  /** \brief Print a debug message on stream with colors
233  * \param format the message
234  */
235  PCL_EXPORTS void
236  print_debug (const char *format, ...);
237 
238  /** \brief Print a debug message on stream with colors
239  * \param stream the output stream (stdout, stderr, etc)
240  * \param format the message
241  */
242  PCL_EXPORTS void
243  print_debug (FILE *stream, const char *format, ...);
244 
245 
246  /** \brief Print a value message on stream with colors
247  * \param format the message
248  */
249  PCL_EXPORTS void
250  print_value (const char *format, ...);
251 
252  /** \brief Print a value message on stream with colors
253  * \param stream the output stream (stdout, stderr, etc)
254  * \param format the message
255  */
256  PCL_EXPORTS void
257  print_value (FILE *stream, const char *format, ...);
258 
259  /** \brief Print a message on stream
260  * \param level the verbosity level
261  * \param stream the output stream (stdout, stderr, etc)
262  * \param format the message
263  */
264  PCL_EXPORTS void
265  print (VERBOSITY_LEVEL level, FILE *stream, const char *format, ...);
266 
267  /** \brief Print a message
268  * \param level the verbosity level
269  * \param format the message
270  */
271  PCL_EXPORTS void
272  print (VERBOSITY_LEVEL level, const char *format, ...);
273  }
274 }
PCL_EXPORTS void enableColoredOutput(FILE *stream, bool enable)
Enable or disable colored text output, overriding the default behavior.
PCL_EXPORTS void print_color(FILE *stream, int attr, int fg, const char *format,...)
Print a message on stream with colors.
PCL_EXPORTS void setVerbosityLevel(VERBOSITY_LEVEL level)
set the verbosity level
PCL_EXPORTS void print_debug(const char *format,...)
Print a debug message on stream with colors.
PCL_EXPORTS void print(VERBOSITY_LEVEL level, FILE *stream, const char *format,...)
Print a message on stream.
PCL_EXPORTS void print_highlight(const char *format,...)
Print a highlighted info message on stream with colors.
PCL_EXPORTS bool isVerbosityLevelEnabled(VERBOSITY_LEVEL severity)
is verbosity level enabled?
PCL_EXPORTS void reset_text_color(FILE *stream)
Reset the text color (on either stdout or stderr) to its original state.
PCL_EXPORTS void print_warn(const char *format,...)
Print a warning message on stream with colors.
PCL_EXPORTS void print_error(const char *format,...)
Print an error message on stream with colors.
TT_ATTIBUTES
Definition: print.h:89
@ TT_HIDDEN
Definition: print.h:96
@ TT_DIM
Definition: print.h:92
@ TT_BLINK
Definition: print.h:94
@ TT_BRIGHT
Definition: print.h:91
@ TT_RESET
Definition: print.h:90
@ TT_UNDERLINE
Definition: print.h:93
@ TT_REVERSE
Definition: print.h:95
VERBOSITY_LEVEL
Definition: print.h:112
@ L_ALWAYS
Definition: print.h:113
@ L_VERBOSE
Definition: print.h:118
PCL_EXPORTS void change_text_color(FILE *stream, int attribute, int fg, int bg)
Change the text color (on either stdout or stderr) with an attr:fg:bg.
@ TT_GREEN
Definition: print.h:103
@ TT_WHITE
Definition: print.h:108
@ TT_BLACK
Definition: print.h:101
@ TT_MAGENTA
Definition: print.h:106
@ TT_YELLOW
Definition: print.h:104
PCL_EXPORTS void print_info(const char *format,...)
Print an info message on stream with colors.
PCL_EXPORTS VERBOSITY_LEVEL getVerbosityLevel()
get the verbosity level.
PCL_EXPORTS void print_value(const char *format,...)
Print a value message on stream with colors.
PCL_EXPORTS bool initVerbosityLevel()
initialize verbosity level.
#define PCL_EXPORTS
Definition: pcl_macros.h:323