Point Cloud Library (PCL)  1.14.0-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 
66 #define PCL_ASSERT_ERROR_PRINT_CHECK(pred, msg) \
67  do \
68  { \
69  if (!(pred)) \
70  { \
71  PCL_ERROR(msg); \
72  PCL_ERROR("In File %s, in line %d\n" __FILE__, __LINE__); \
73  } \
74  } while (0)
75 
76 #define PCL_ASSERT_ERROR_PRINT_RETURN(pred, msg, err) \
77  do \
78  { \
79  PCL_ASSERT_ERROR_PRINT_CHECK(pred, msg); \
80  if (!(pred)) return err; \
81  } while (0)
82 
83 namespace pcl
84 {
85  namespace console
86  {
88  {
89  TT_RESET = 0,
90  TT_BRIGHT = 1,
91  TT_DIM = 2,
93  TT_BLINK = 4,
95  TT_HIDDEN = 8
96  };
97 
98  enum TT_COLORS
99  {
107  TT_WHITE
108  };
109 
111  {
117  L_VERBOSE
118  };
119 
120  /** set the verbosity level */
121  PCL_EXPORTS void
123 
124  /** get the verbosity level. */
127 
128  /** initialize verbosity level. */
129  PCL_EXPORTS bool
131 
132  /** is verbosity level enabled? */
133  PCL_EXPORTS bool
135 
136  /** \brief Enable or disable colored text output, overriding the default behavior.
137  *
138  * By default, colored output is enabled for interactive terminals or when the environment
139  * variable PCL_CLICOLOR_FORCE is set.
140  *
141  * \param stream the output stream (stdout, stderr, etc)
142  * \param enable whether to emit color codes when calling any of the color related methods
143  */
144  PCL_EXPORTS void
145  enableColoredOutput (FILE *stream, bool enable);
146 
147  /** \brief Change the text color (on either stdout or stderr) with an attr:fg:bg
148  * \param stream the output stream (stdout, stderr, etc)
149  * \param attribute the text attribute
150  * \param fg the foreground color
151  * \param bg the background color
152  */
153  PCL_EXPORTS void
154  change_text_color (FILE *stream, int attribute, int fg, int bg);
155 
156  /** \brief Change the text color (on either stdout or stderr) with an attr:fg
157  * \param stream the output stream (stdout, stderr, etc)
158  * \param attribute the text attribute
159  * \param fg the foreground color
160  */
161  PCL_EXPORTS void
162  change_text_color (FILE *stream, int attribute, int fg);
163 
164  /** \brief Reset the text color (on either stdout or stderr) to its original state
165  * \param stream the output stream (stdout, stderr, etc)
166  */
167  PCL_EXPORTS void
168  reset_text_color (FILE *stream);
169 
170  /** \brief Print a message on stream with colors
171  * \param stream the output stream (stdout, stderr, etc)
172  * \param attr the text attribute
173  * \param fg the foreground color
174  * \param format the message
175  */
176  PCL_EXPORTS void
177  print_color (FILE *stream, int attr, int fg, const char *format, ...);
178 
179  /** \brief Print an info message on stream with colors
180  * \param format the message
181  */
182  PCL_EXPORTS void
183  print_info (const char *format, ...);
184 
185  /** \brief Print an info message on stream with colors
186  * \param stream the output stream (stdout, stderr, etc)
187  * \param format the message
188  */
189  PCL_EXPORTS void
190  print_info (FILE *stream, const char *format, ...);
191 
192  /** \brief Print a highlighted info message on stream with colors
193  * \param format the message
194  */
195  PCL_EXPORTS void
196  print_highlight (const char *format, ...);
197 
198  /** \brief Print a highlighted info message on stream with colors
199  * \param stream the output stream (stdout, stderr, etc)
200  * \param format the message
201  */
202  PCL_EXPORTS void
203  print_highlight (FILE *stream, const char *format, ...);
204 
205  /** \brief Print an error message on stream with colors
206  * \param format the message
207  */
208  PCL_EXPORTS void
209  print_error (const char *format, ...);
210 
211  /** \brief Print an error message on stream with colors
212  * \param stream the output stream (stdout, stderr, etc)
213  * \param format the message
214  */
215  PCL_EXPORTS void
216  print_error (FILE *stream, const char *format, ...);
217 
218  /** \brief Print a warning message on stream with colors
219  * \param format the message
220  */
221  PCL_EXPORTS void
222  print_warn (const char *format, ...);
223 
224  /** \brief Print a warning message on stream with colors
225  * \param stream the output stream (stdout, stderr, etc)
226  * \param format the message
227  */
228  PCL_EXPORTS void
229  print_warn (FILE *stream, const char *format, ...);
230 
231  /** \brief Print a debug message on stream with colors
232  * \param format the message
233  */
234  PCL_EXPORTS void
235  print_debug (const char *format, ...);
236 
237  /** \brief Print a debug message on stream with colors
238  * \param stream the output stream (stdout, stderr, etc)
239  * \param format the message
240  */
241  PCL_EXPORTS void
242  print_debug (FILE *stream, const char *format, ...);
243 
244 
245  /** \brief Print a value message on stream with colors
246  * \param format the message
247  */
248  PCL_EXPORTS void
249  print_value (const char *format, ...);
250 
251  /** \brief Print a value message on stream with colors
252  * \param stream the output stream (stdout, stderr, etc)
253  * \param format the message
254  */
255  PCL_EXPORTS void
256  print_value (FILE *stream, const char *format, ...);
257 
258  /** \brief Print a message on stream
259  * \param level the verbosity level
260  * \param stream the output stream (stdout, stderr, etc)
261  * \param format the message
262  */
263  PCL_EXPORTS void
264  print (VERBOSITY_LEVEL level, FILE *stream, const char *format, ...);
265 
266  /** \brief Print a message
267  * \param level the verbosity level
268  * \param format the message
269  */
270  PCL_EXPORTS void
271  print (VERBOSITY_LEVEL level, const char *format, ...);
272  }
273 }
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:88
@ TT_HIDDEN
Definition: print.h:95
@ TT_DIM
Definition: print.h:91
@ TT_BLINK
Definition: print.h:93
@ TT_BRIGHT
Definition: print.h:90
@ TT_RESET
Definition: print.h:89
@ TT_UNDERLINE
Definition: print.h:92
@ TT_REVERSE
Definition: print.h:94
VERBOSITY_LEVEL
Definition: print.h:111
@ L_ALWAYS
Definition: print.h:112
@ L_VERBOSE
Definition: print.h:117
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:102
@ TT_WHITE
Definition: print.h:107
@ TT_BLACK
Definition: print.h:100
@ TT_MAGENTA
Definition: print.h:105
@ TT_YELLOW
Definition: print.h:103
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