00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef H_LIBTHROWABLE_TRACER
00021 #define H_LIBTHROWABLE_TRACER
00022 #include "libthrowable/util/util.h"
00023 #include <ostream>
00024 #include <stack>
00025 namespace libthrowable {
00038 class LIBTHROWABLE_API TracePoint
00039 {
00040 public:
00044 TracePoint(const char *filename, int linenumber, const char *function) throw();
00045
00049 TracePoint(const char *filename, int linenumber, const char *function, const std::string& message) throw();
00050
00066 template<class OStreamableT> TracePoint(const char *filename, int linenumber, const char *function,
00067 const OStreamableT& t, const std::string& name) throw()
00068 : _function(filename, function)
00069 {
00070 std::string output;
00071 genVarOutput(output, linenumber, util::stringify(t), name);
00072 getOstream() << optimizeForLineWidth(output) << std::endl;
00073 }
00074
00075 ~TracePoint() throw();
00076
00092 static void setLineWidth(int width) throw();
00093
00099 static void setOstream(std::ostream& os) throw();
00100
00116 static void setThreadName(const std::string& name) throw();
00117
00118 private:
00119
00120 TracePoint(const TracePoint& other);
00121 TracePoint& operator=(const TracePoint& other);
00122
00123 struct Function
00124 {
00125 Function(const char *tFile, const char *tName) throw()
00126 : file(tFile), name(tName) {}
00127
00128 bool operator==(const Function& other) const throw()
00129 { return (name == other.name && file == other.file); }
00130
00131 bool operator!=(const Function& other) const throw()
00132 { return !(*this == other); }
00133
00134 const std::string file;
00135 const std::string name;
00136 };
00137
00138
00139 static std::ostream& getOstream(std::ostream *p_os = NULL) throw();
00140 static std::stack<Function>& getFunctionStack() throw();
00141
00142 static unsigned& getLevel() throw();
00143 static std::string optimizeForLineWidth(const std::string& str) throw();
00145
00146 void genBasicOutput(std::string& toWriteIn, int linenumber) const throw();
00147 void genVarOutput(std::string& toWriteIn, int linenumber, const std::string& varStr, const std::string& varName) const throw();
00148
00149
00150
00151
00152 bool fStackPush() const throw();
00153
00154
00155
00156 void fStackPop() const throw();
00157
00158 const Function _function;
00159
00160 };
00161 }
00162 #endif