/* * * versuch project * several things for replace in pwlibs * $Id: Utils.h,v 1.3 2006/05/19 15:21:25 warlock_kg Exp $ * warlock copyright since 2005 Nov * */ #ifndef _utils_h_ #define _utils_h_ #include #include #include #include using namespace std; typedef multimap TSection; void Tokenize(const string& str, vector& tokens, const string& delimiters = " ", bool onePerSeparator = false); void wtrim(string& str); // PConfig calss of pwlib uses PThread class TConfig { protected: string fname; map m_config; string CurrentSection; ifstream *f; public: TConfig(const string& filename, const string& section = "system"); ~TConfig(); bool TryOpen(const string prefix = ""); void Load(); string GetString (const string &key, const string &dflt = "") const; void SetDefaultSection (const string §ion); long GetInteger (const string &key, long dflt=0) const; unsigned GetVector(const string &key, vector& params) const; bool GetBool(const string &key, const bool dflt = false); string Prefix; }; // PAssertFunc with message "Cannot use PTRACE before PProcess constructed." class WTrace { public: enum EDebugOptions { Blocks = 1, DateAndTime = 2, Timestamp = 4, Thread = 8, TraceLevel = 16, FileAndLine = 32, ThreadAddress = 64, AppendToFile = 128, GMTTime = 256, SystemLogStream = 32768 }; static void Initialise( const char * filename = NULL, unsigned options = Timestamp | Thread | Blocks | FileAndLine ); static void SetOptions(unsigned EDebugOptions); static void ClearOptions(unsigned EDebugOptions); static bool CanTrace(unsigned level); static void SetLevel(unsigned level); static unsigned GetLevel(); static void SetStream(ostream * out); static ostream & Begin( unsigned level, const char * fileName, // Source file being traced int lineNum ); static ostream & End(ostream & strm); }; #define WTRACE_LINE() \ if (!WTrace::CanTrace(1)) ; else \ WTrace::Begin(1, __FILE__, __LINE__) << __FILE__ << '(' << __LINE__ << ')' << WTrace::End #define WTRACE(level, args) \ if (!WTrace::CanTrace(level)) ; else \ WTrace::Begin(level, __FILE__, __LINE__) << args << WTrace::End #define WTRACE_IF(level, cond, args) \ if (!( WTrace::CanTrace(level) || cond)) ; else \ WTrace::Begin(level, __FILE__, __LINE__) << args << WTrace::End #endif // _utils_h_