14 #include "LibCyberRadio/Common/Debuggable.h" 15 #include "LibCyberRadio/Common/Pythonesque.h" 30 const std::string& debug_name,
32 const std::string& debug_timefmt
35 _debugName(debug_name),
37 _debugTimeFmt(debug_timefmt),
38 _debugTimestamp(NULL),
39 _debugTimestampSize(80)
41 _debugTimestamp =
new char[_debugTimestampSize];
46 delete _debugTimestamp;
51 _debugName(other._debugName),
52 _debugFp(other._debugFp),
53 _debugTimeFmt(other._debugTimeFmt),
54 _debugTimestamp(other._debugTimestamp),
55 _debugTimestampSize(other._debugTimestampSize)
64 _debug = other._debug;
65 _debugName = other._debugName;
66 _debugFp = other._debugFp;
67 _debugTimeFmt = other._debugTimeFmt;
68 _debugTimestamp = other._debugTimestamp;
69 _debugTimestampSize = other._debugTimestampSize;
75 const std::string& debug_name
78 _debugName = debug_name;
89 const std::string& debug_timefmt
92 _debugTimeFmt = debug_timefmt;
101 if ( _debug && (_debugFp != NULL) )
103 if (_debugTimeFmt.length() > 0)
105 time_t now = time(NULL);
106 memset(_debugTimestamp, 0, _debugTimestampSize);
107 strftime(_debugTimestamp,
109 _debugTimeFmt.c_str(),
111 ret += fprintf(_debugFp,
"[%s]", _debugTimestamp);
113 if (_debugName.length() > 0)
114 ret += fprintf(_debugFp,
"[%s] ", _debugName.c_str());
118 va_start(ap, format);
119 ret += vfprintf(_debugFp, format, ap);
130 return ( x ?
"true" :
"false" );
146 std::ostringstream oss;
147 for (std::string::const_iterator it = data.begin(); it!= data.end(); it++)
149 if ( !isalnum(*it) && !ispunct(*it) && !isspace(*it) )
151 oss <<
"\\x" << std::hex << std::setw(2)
152 << std::setfill(
'0') << (int)((
unsigned char)(*it));
Debuggable & operator=(const Debuggable &other)
Assignment operator for Debuggable objects.
virtual ~Debuggable()
Destroys a Debuggable object.
static std::string Replace(const std::string &str, const std::string &oldstr, const std::string &newstr, int count=INT_MAX)
Replaces occurrences of one substring with another within the given string.
virtual void setDebugFile(FILE *debug_fp)
Sets the debug file pointer for this object.
Class that supports debug output.
virtual void setDebugTimeFormat(const std::string &debug_timefmt)
Sets the debug time format for this object.
virtual int debug(const char *format,...)
Outputs debug information.
Defines functionality for LibCyberRadio applications.
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.
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
virtual std::string rawString(const std::string &data)
Gets a "raw" string representation of a given data string.
virtual bool isDebug() const
Gets whether this object produces debug output.
virtual std::string getDebugName() const
Gets the debug name for this object.
virtual void setDebugName(const std::string &debug_name)
Sets the debug name for this object.