Update of /cvsroot/pclasses/pclasses2/include/pclasses
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23571/include/pclasses
Modified Files:
Trace.h
Log Message:
- Added tracing support
Index: Trace.h
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Trace.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Trace.h 10 Jan 2005 02:48:38 -0000 1.1
+++ Trace.h 28 Apr 2005 10:11:36 -0000 1.2
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2004 by Christian Prochnow *
+ * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH *
* cp...@se... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -21,8 +21,94 @@
#ifndef P_Trace_h
#define P_Trace_h
+#include <pclasses/pclasses-config.h>
+#include <pclasses/Export.h>
+#include <pclasses/SourceInfo.h>
+#include <pclasses/IntTypes.h>
+
+#include <string>
+#include <iostream>
+
namespace P {
+class TraceLog;
+
+class PCORE_EXPORT TraceStream:
+ private std::ostream
+{
+ public:
+ TraceStream(TraceLog& log, const SourceInfo& si, const char* cl);
+ TraceStream(const TraceStream&);
+ ~TraceStream();
+
+ std::ostream& operator()();
+
+ private:
+ TraceLog& _log;
+ SourceInfo _src;
+ std::string _class;
+};
+
+class PCORE_EXPORT TraceLog {
+ public:
+ TraceStream stream(const SourceInfo& si, const char* cl);
+
+ void output(const SourceInfo& si, const std::string& cl,
+ const std::string& msg);
+
+ static TraceLog& instance();
+
+ private:
+ TraceLog();
+ ~TraceLog();
+
+ static TraceLog _trace;
+};
+
+class NullTraceStream {
+ public:
+ inline NullTraceStream& operator()(const SourceInfo& si)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(char ch)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(const char* str)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(int16_t val)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(uint16_t val)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(int32_t val)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(uint32_t val)
+ { return *this; }
+
+ #ifdef PCLASSES_HAVE_64BIT_INT
+ inline NullTraceStream& operator<<(int64_t val)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(uint64_t val)
+ { return *this; }
+ #endif
+
+ inline NullTraceStream& operator<<(const void* ptr)
+ { return *this; }
+
+ inline NullTraceStream& operator<<(const std::string& str)
+ { return *this; }
+
+};
+
+#if defined(_DEBUG) && !defined(NO_DEBUG)
+# define P_TRACE(c) NullTraceStream()
+#else
+# define P_TRACE(c) P::TraceLog::instance().stream(P_SOURCEINFO,#c)()
+#endif
} // !namespace P
|