libcyberradio  22.01.24
Debuggable.h
1 /* -*- c++ -*- */
2 /***************************************************************************
3  * \file Debuggable.h
4  *
5  * \brief Class that supports debug output.
6  *
7  * \author DA
8  * \copyright 2017 CyberRadio Solutions, Inc.
9  */
10 
11 #ifndef INCLUDED_LIBCYBERRADIO_DEBUGGABLE_H_
12 #define INCLUDED_LIBCYBERRADIO_DEBUGGABLE_H_
13 
14 #include <string>
15 #include <stdio.h>
16 
20 #define DEBUG_FP stderr
21 
24 #define DEBUG_TIME_FMT "%H:%M:%S"
25 
26 
30 namespace LibCyberRadio
31 {
38  class Debuggable
39  {
40  public:
50  Debuggable(
51  bool debug = false,
52  const std::string& debug_name = "",
53  FILE* debug_fp = DEBUG_FP,
54  const std::string& debug_timefmt = DEBUG_TIME_FMT
55  );
59  virtual ~Debuggable();
64  Debuggable(const Debuggable& other);
70  Debuggable& operator=(const Debuggable& other);
79  virtual void setDebugName(
80  const std::string& debug_name
81  );
87  virtual void setDebugFile(
88  FILE* debug_fp
89  );
96  virtual void setDebugTimeFormat(
97  const std::string& debug_timefmt
98  );
111  virtual int debug(
112  const char *format,
113  ...
114  );
120  virtual const char* debugBool(
121  bool x
122  );
127  virtual bool isDebug() const;
132  virtual std::string getDebugName() const;
146  virtual std::string rawString(const std::string& data);
147 
148  protected:
149  bool _debug;
150  std::string _debugName;
151  FILE* _debugFp;
152  std::string _debugTimeFmt;
153  char* _debugTimestamp;
154  size_t _debugTimestampSize;
155  };
156 
157 } /* namespace LibCyberRadio */
158 
159 #endif /* INCLUDED_LIBCYBERRADIO_DEBUGGABLE_H_ */
Debuggable & operator=(const Debuggable &other)
Assignment operator for Debuggable objects.
Definition: Debuggable.cpp:59
virtual ~Debuggable()
Destroys a Debuggable object.
Definition: Debuggable.cpp:44
virtual void setDebugFile(FILE *debug_fp)
Sets the debug file pointer for this object.
Definition: Debuggable.cpp:81
Class that supports debug output.
Definition: Debuggable.h:38
virtual void setDebugTimeFormat(const std::string &debug_timefmt)
Sets the debug time format for this object.
Definition: Debuggable.cpp:88
virtual int debug(const char *format,...)
Outputs debug information.
Definition: Debuggable.cpp:95
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
Debuggable(bool debug=false, const std::string &debug_name="", FILE *debug_fp=DEBUG_FP, const std::string &debug_timefmt=DEBUG_TIME_FMT)
Constructs a Debuggable object.
Definition: Debuggable.cpp:28
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
Definition: Debuggable.cpp:126
virtual std::string rawString(const std::string &data)
Gets a "raw" string representation of a given data string.
Definition: Debuggable.cpp:143
virtual bool isDebug() const
Gets whether this object produces debug output.
Definition: Debuggable.cpp:133
virtual std::string getDebugName() const
Gets the debug name for this object.
Definition: Debuggable.cpp:138
virtual void setDebugName(const std::string &debug_name)
Sets the debug name for this object.
Definition: Debuggable.cpp:74