00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "TraceObject.h"
00039 #include <iostream>
00040 #include <syslog.h>
00041
00042 using namespace std;
00043
00044 namespace ClearSilver
00045 {
00046
00047 static void create (const string&, const string&, const void*);
00048 static void copy (const string&, const void*, const void*);
00049 static void destroy (const string&, const void*);
00050 static void assign (const string&, const void*, const void*);
00051 static void swap (const string&, const void*, const void*);
00052
00053 bool&
00054 TraceObject::log_messages()
00055 {
00056 static bool flag_ = true;
00057 return flag_;
00058 }
00059
00060 bool&
00061 TraceObject::stream_messages()
00062 {
00063 static bool flag_ = false;
00064 return flag_;
00065 }
00066
00067 #if HAVE_OBJECT_TRACING
00068
00069
00070 TraceObject::TraceObject (bool debug, const string& name)
00071 : debug_(debug), name_(name)
00072 {
00073 if (debug_)
00074 create(name_, string(), this);
00075 }
00076
00077 TraceObject::TraceObject (bool debug, const string& name, const string& args)
00078 : debug_(debug), name_(name)
00079 {
00080 if (debug_)
00081 create(name_, args, this);
00082 }
00083
00084 TraceObject::TraceObject (const TraceObject& m)
00085 : debug_(m.debug_), name_(m.name_)
00086 {
00087 if (debug_)
00088 copy(name_, this, &m);
00089 }
00090
00091 TraceObject::~TraceObject () throw()
00092 {
00093 if (debug_)
00094 destroy (name_, this);
00095 }
00096
00097 TraceObject::TraceObject&
00098 TraceObject::operator = (const TraceObject& m)
00099 {
00100 if (debug_)
00101 assign (name_, this, &m);
00102 string name (name_);
00103 debug_ = m.debug_;
00104 name_.swap (name);
00105 return *this;
00106 }
00107
00108 void
00109 TraceObject::swap (TraceObject& m) throw()
00110 {
00111 if (debug_)
00112 ClearSilver::swap (name_, this, &m);
00113 std::swap (debug_, m.debug_);
00114 std::swap (name_, m.name_);
00115 }
00116
00117
00118 void
00119 create (const string& name, const string& args, const void* p)
00120 {
00121 if (ClearSilver::TraceObject::log_messages())
00122 syslog (LOG_DEBUG, "%s::%s(%s): this=0x%x",
00123 name.c_str(), name.c_str(), args.c_str(), p);
00124 if (ClearSilver::TraceObject::stream_messages())
00125 cerr
00126 << name << "::" << name << "(" << args << "): "
00127 << "this=" << hex << p << dec << endl;
00128 }
00129
00130 void
00131 copy (const string& name, const void* dest, const void* src)
00132 {
00133 if (ClearSilver::TraceObject::log_messages())
00134 syslog (LOG_DEBUG, "%s::%s(const %s&): this=0x%x, %s=0x%x",
00135 name.c_str(), name.c_str(), name.c_str(),
00136 dest, name.c_str(), src);
00137 if (ClearSilver::TraceObject::stream_messages())
00138 cerr
00139 << name << "::" << name << "(const " << name << "&): "
00140 << "this=" << hex << dest << ", " << name << "=" << src << dec << endl;
00141 }
00142
00143 void
00144 destroy (const string& name, const void* p)
00145 {
00146 if (ClearSilver::TraceObject::log_messages())
00147 syslog (LOG_DEBUG, "%s::~%s(): this=0x%x",
00148 name.c_str(), name.c_str(), p);
00149 if (ClearSilver::TraceObject::stream_messages())
00150 cerr
00151 << name << "::~" << name << "(): "
00152 << "this=" << hex << p << dec << endl;
00153 }
00154
00155 void
00156 assign (const string& name, const void* dest, const void* src)
00157 {
00158 if (ClearSilver::TraceObject::log_messages())
00159 syslog (LOG_DEBUG, "%s::%s& %s::operator = (const %s&): "
00160 "this=0x%x, %s=0x%x",
00161 name.c_str(), name.c_str(), name.c_str(), name.c_str(),
00162 dest, name.c_str(), src);
00163 if (ClearSilver::TraceObject::stream_messages())
00164 cerr
00165 << name << "::" << name << "& "
00166 << name << "::operator = (const " << name << "&): "
00167 << "this=" << hex << dest << ", " << name << "=" << src << dec << endl;
00168 }
00169
00170 void
00171 swap (const string& name, const void* dest, const void* src)
00172 {
00173 if (ClearSilver::TraceObject::log_messages())
00174 syslog (LOG_DEBUG, "%s::swap(%s&): this=0x%x, %s=0x%x",
00175 name.c_str(), name.c_str(), dest, name.c_str(), src);
00176 if (ClearSilver::TraceObject::stream_messages())
00177 cerr
00178 << name << "::swap(" << name << "&): "
00179 << "this=" << hex << dest << ", " << name << "=" << src << dec << endl;
00180 }
00181
00182 #endif // HAVE_OBJECT_TRACING
00183
00184 }