You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Christian P. <cp...@us...> - 2005-07-02 11:43:46
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/Console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18557/plugins/LogTarget/Console Removed Files: Makefile.am ConsoleLogTarget.cpp Log Message: - Renamed LogTarget plugins --- Makefile.am DELETED --- --- ConsoleLogTarget.cpp DELETED --- |
From: Christian P. <cp...@us...> - 2005-07-02 11:43:45
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/File In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18557/plugins/LogTarget/File Removed Files: Makefile.am FileLogTarget.cpp Log Message: - Renamed LogTarget plugins --- FileLogTarget.cpp DELETED --- --- Makefile.am DELETED --- |
From: Christian P. <cp...@us...> - 2005-07-02 11:43:45
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18557/plugins/LogTarget/console Added Files: Makefile.am LogTarget_console.cpp Log Message: - Renamed LogTarget plugins --- NEW FILE: Makefile.am --- INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include $(all_includes) METASOURCES = AUTO pkglib_LTLIBRARIES = LogTarget_console.la LogTarget_console_la_SOURCES = LogTarget_console.cpp LogTarget_console_la_LDFLAGS = -module -avoid-version LogTarget_console_la_LIBADD = $(top_builddir)/src/libpclasses.la \ $(top_builddir)/src/Unicode/libpclasses_unicode.la \ $(top_builddir)/src/IO/libpclasses_io.la \ $(top_builddir)/src/System/libpclasses_system.la \ $(top_builddir)/src/App/libpclasses_app.la --- NEW FILE: LogTarget_console.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/System/Plugin.h" #include "pclasses/App/LogTarget.h" #include <iostream> using namespace P; using namespace P::IO; using namespace P::App; using namespace std; class LogTarget_console: public LogTarget { public: LogTarget_console() { } ~LogTarget_console() throw() { } void open(const URL& url) throw(IOError) { _out = &cout; } void close() throw(IOError) { _out = 0; } void reload() throw(IOError) { } void output(const LogMessage& msg) throw(IOError) { (*_out) << msg.when() << ' ' << msg.level2Str(msg.level()) << ' ' << msg.msg().utf8() << endl; } bool valid() const throw() { return _out ? true : false; } private: ostream* _out; }; P_PLUGIN_REGISTER_TYPE(LogTarget, LogTarget_console); P_PLUGIN_REGISTER_ALIAS(LogTarget, console, LogTarget_console); |
From: Christian P. <cp...@us...> - 2005-07-02 11:43:45
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18557/plugins/LogTarget Modified Files: Makefile.am Log Message: - Renamed LogTarget plugins Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/plugins/LogTarget/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.am 28 Apr 2005 11:26:05 -0000 1.2 +++ Makefile.am 2 Jul 2005 11:43:35 -0000 1.3 @@ -1,2 +1,2 @@ -SUBDIRS = Console File +SUBDIRS = console file |
From: Christian P. <cp...@us...> - 2005-07-02 11:43:45
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/file In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18557/plugins/LogTarget/file Added Files: Makefile.am LogTarget_file.cpp Log Message: - Renamed LogTarget plugins --- NEW FILE: Makefile.am --- INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include $(all_includes) METASOURCES = AUTO pkglib_LTLIBRARIES = LogTarget_file.la LogTarget_file_la_SOURCES = LogTarget_file.cpp LogTarget_file_la_LDFLAGS = -module -avoid-version LogTarget_file_la_LIBADD = $(top_builddir)/src/libpclasses.la \ $(top_builddir)/src/Unicode/libpclasses_unicode.la \ $(top_builddir)/src/IO/libpclasses_io.la \ $(top_builddir)/src/System/libpclasses_system.la \ $(top_builddir)/src/App/libpclasses_app.la --- NEW FILE: LogTarget_file.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/IO/IOStream.h" #include "pclasses/System/File.h" #include "pclasses/System/Plugin.h" #include "pclasses/App/LogTarget.h" #include <iostream> using namespace P; using namespace P::IO; using namespace P::System; using namespace P::App; using namespace std; class LogTarget_file: public LogTarget { public: LogTarget_file() : _file(), _out(0) { } ~LogTarget_file() throw() { if(_out) delete _out; } void open(const URL& url) throw(IOError) { _file.open(url.path(), IODevice::Write, IODevice::OpenCreate, IODevice::AllowRead); _out = new IOStream(_file); } void close() throw(IOError) { _file.close(); delete _out; } void reload() throw(IOError) { } void output(const LogMessage& msg) throw(IOError) { (*_out) << msg.when() << ' ' << msg.level2Str(msg.level()) << ' ' << msg.msg().utf8() << endl; } bool valid() const throw() { return _file.valid(); } private: File _file; IOStream* _out; }; P_PLUGIN_REGISTER_TYPE(LogTarget, LogTarget_file); P_PLUGIN_REGISTER_ALIAS(LogTarget, file, LogTarget_file); |
From: Christian P. <cp...@us...> - 2005-07-02 11:43:43
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18557 Modified Files: configure.in Log Message: - Renamed LogTarget plugins Index: configure.in =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.in,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- configure.in 22 Jun 2005 11:37:57 -0000 1.14 +++ configure.in 2 Jul 2005 11:43:35 -0000 1.15 @@ -277,8 +277,8 @@ src/App/Makefile \ plugins/Makefile \ plugins/LogTarget/Makefile \ - plugins/LogTarget/Console/Makefile \ - plugins/LogTarget/File/Makefile \ + plugins/LogTarget/console/Makefile \ + plugins/LogTarget/file/Makefile \ plugins/IOHandler/Makefile \ plugins/IOHandler/file/Makefile \ plugins/ConfigStore/Makefile \ |
From: Christian P. <cp...@us...> - 2005-07-02 11:37:39
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/file In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15270/file Log Message: Directory /cvsroot/pclasses/pclasses2/plugins/LogTarget/file added to the repository |
From: Christian P. <cp...@us...> - 2005-07-02 11:37:39
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15270/console Log Message: Directory /cvsroot/pclasses/pclasses2/plugins/LogTarget/console added to the repository |
From: Christian P. <cp...@us...> - 2005-07-01 14:46:11
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12896/include/pclasses Modified Files: Buffer.h Log Message: - Added documentation to P::Buffer Index: Buffer.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Buffer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Buffer.h 3 Jun 2005 09:47:42 -0000 1.1 +++ Buffer.h 1 Jul 2005 14:46:02 -0000 1.2 @@ -23,19 +23,34 @@ #include <pclasses/Algorithm.h> #include <pclasses/Exception.h> +#include <pclasses/ScopedArrayPtr.h> namespace P { +//! Buffer template-class +/*! + A template class used to buffer items of a given type. + The class implements FIFO semantics. +*/ template <class Type> class Buffer { public: + + //! Default constructor + /*! + Constructs the buffer with the given size and auto-resize policy. + \param size the initial size of the buffer + \param autoResize true if the buffer should grow as required, false + otherwise. + */ Buffer(size_t size = 1024, bool autoResize = true) : _autoResize(autoResize), _buffer((Type*)new char[sizeof(Type) * size]), - _size(size), _count(0) + _size(max((size_t)1, size)), _count(0) { } + //! Copy constructor Buffer(const Buffer& b) : _autoResize(b._autoResize), _buffer((Type*)new char[sizeof(Type) * b._size]), @@ -44,6 +59,7 @@ copy_construct(_buffer, b._buffer, _count); } + //! Destructor ~Buffer() throw() { clear(); @@ -66,37 +82,71 @@ _count = count; } + //! Removes all buffered items void clear() throw() { destruct(_buffer, _count); _count = 0; } + //! Returns the number of buffered items inline size_t size() const throw() { return _count; } + //! Resize the buffer + /*! + Resizes the buffer to the given size which may be greater + or smaller than the current. The new size must be greater or + equal to the current number of buffered items or a OverrunError + will be thrown. + \param sz the new size of the buffer + \throw OverrunError + */ void resize(size_t sz) throw(OverrunError) { + sz = max((size_t)1, sz); + if(_count > sz) throw OverrunError("Buffer overrun", P_SOURCEINFO); + else if(_size == sz) + return; - Type* newBuffer = (Type*)new char[sizeof(Type) * sz]; - copy_construct(newBuffer, _buffer, _count); + ScopedArrayPtr<char> newBuffer(new char[sizeof(Type) * sz]); + copy_construct((Type*)newBuffer.get(), _buffer, _count); destruct(_buffer, _count); delete[] (char*)_buffer; - _buffer = newBuffer; + _buffer = (Type*)newBuffer.release(); _size = sz; } + //! Enable or disable automatic buffer resize + inline void setAutoResize(bool resize) throw() + { _autoResize = resize; } + + //! Test if the buffer resizes automatically + inline bool isAutoResize() const throw() + { return _autoResize; } + + //! Returns the size of the buffer inline size_t capacity() const throw() { return _size; } + //! Test if the buffer is empty inline bool empty() const throw() { return _count == 0; } + //! Returns a pointer to the buffered items inline Type* data() throw() { return _buffer; } + //! Remove items from the buffer + /*! + Removes the given number of items from the front of the buffer. + If the number of currently stored items is less than <count>, + a UnderrunError will be thrown. + \param count the number of items to remove from the buffer + \throw UnderrunError + */ void pop(size_t count) throw(UnderrunError) { if(_count >= count) @@ -110,6 +160,15 @@ throw UnderrunError("Buffer underrun", P_SOURCEINFO); } + //! Add items to the buffer + /*! + Append the given number of items to the buffer. If the buffer is + to small to hold the number of items, the buffer will grow if + auto-resizing is enabled. Otherwise a OverrunError will be thrown. + \param buff pointer to the items to append + \param count number of items to append + \throw OverrunError + */ void push(const Type* buff, size_t count) throw(OverrunError) { if(_size < _count + count) |
From: Christian P. <cp...@us...> - 2005-07-01 14:45:30
|
Update of /cvsroot/pclasses/pclasses2/src/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12434 Modified Files: Makefile.am Removed Files: Variant.cpp Log Message: - Removed Variant.cpp Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Util/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.am 17 Jan 2005 22:50:41 -0000 1.7 +++ Makefile.am 1 Jul 2005 14:45:17 -0000 1.8 @@ -8,7 +8,6 @@ SimplePropertyStore.cpp \ StringTool.cpp \ ThreadPool.cpp \ - Variant.cpp \ WorkQueue.cpp # ^^^^^^ is it legal to backslash-escape newlines in Automake? # 12312004 cproch: it is ! --- Variant.cpp DELETED --- |
From: Christian P. <cp...@us...> - 2005-07-01 14:03:36
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22756 Modified Files: Makefile.am Removed Files: Variant.h LexT.h Log Message: - Removed Variant.h it had the same functionality than LexT - Removed LexT.h it now lives in the core module Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.am 16 Jan 2005 00:08:11 -0000 1.5 +++ Makefile.am 1 Jul 2005 14:03:25 -0000 1.6 @@ -2,4 +2,4 @@ INCLUDES = METASOURCES = AUTO -pclasses_util_include_HEADERS = Any.h LexT.h ManagedThread.h Prefs.h SimplePropertyStore.h SimpleArgvParser.h StringTool.h ThreadPool.h Variant.h WorkQueue.h +pclasses_util_include_HEADERS = Any.h ManagedThread.h Prefs.h SimplePropertyStore.h SimpleArgvParser.h StringTool.h ThreadPool.h WorkQueue.h --- Variant.h DELETED --- --- LexT.h DELETED --- |
From: Christian P. <cp...@us...> - 2005-07-01 13:56:51
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19509/include/pclasses Modified Files: Makefile.am Log Message: - Added LexT.h to Makefile.am Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Makefile.am,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- Makefile.am 29 Jun 2005 20:52:29 -0000 1.17 +++ Makefile.am 1 Jul 2005 13:56:43 -0000 1.18 @@ -22,6 +22,6 @@ SharingContext.h Time.h Date.h DateTime.h TimeSpan.h Callback.h Signal.h \ SignalN1.h SignalN2.h SignalN3.h SignalN4.h \ CallbackN1.h CallbackN2.h CallbackN3.h CallbackN4.h StringList.h \ - Trace.h PropertyMap.h Export.h Buffer.h pclasses-config.h + Trace.h PropertyMap.h Export.h Buffer.h LexT.h pclasses-config.h CLEANFILES = CallbackN1.h CallbackN2.h CallbackN3.h CallbackN4.h SignalN1.h SignalN2.h SignalN3.h SignalN4.h |
From: Christian P. <cp...@us...> - 2005-07-01 13:55:30
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18224/include/pclasses/Unicode Modified Files: String.h Log Message: - Added Traits::LexT<StringList<std::string> >, Traits::LexT<StringList<Unicode::String> >, Traits::LexT<Unicode::String> Index: String.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Unicode/String.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- String.h 22 Jun 2005 11:33:17 -0000 1.8 +++ String.h 1 Jul 2005 13:55:10 -0000 1.9 @@ -25,6 +25,8 @@ #include <pclasses/BasicTypes.h> #include <pclasses/Alloc.h> #include <pclasses/SharedPtr.h> +#include <pclasses/LexT.h> +#include <pclasses/StringList.h> #include <pclasses/Unicode/UnicodeError.h> #include <pclasses/Unicode/Char.h> @@ -85,6 +87,8 @@ size_t size() const throw(); size_t capacity() const throw(); + void reserve(size_t sz); + void resize(size_t sz); Char at(size_t index) const; @@ -156,12 +160,18 @@ static String fromUtf8(const char* str, size_t count = npos) throw(OutOfMemory, UnicodeError); + static String fromUtf8(const std::string& str) + throw(OutOfMemory, UnicodeError); + std::string toCodepage(const char* codepage = 0) const throw(OutOfMemory, UnicodeError); static String fromCodepage(const char* str, size_t count = npos, const char* codepage = 0) throw(OutOfMemory, UnicodeError); + static String fromCodepage(const std::string& str, + const char* codepage = 0) throw(OutOfMemory, UnicodeError); + void acquire(uchar16_t* str, size_t size, size_t length) throw(OutOfMemory); @@ -183,6 +193,27 @@ } // !namespace Unicode + +namespace Traits { + +template < > +struct PUNICODE_EXPORT LexT<Unicode::String> { + static std::string toString(const Unicode::String& val); + static Unicode::String fromString(const std::string& str) + throw(ConversionError); +}; + +template < > +struct PUNICODE_EXPORT LexT<StringList<Unicode::String> > { + static std::string toString(const StringList<Unicode::String>& val); + static StringList<Unicode::String> fromString(const std::string& str) + throw(ConversionError); +}; + + +} // !namespace Traits + + } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-07-01 13:55:26
|
Update of /cvsroot/pclasses/pclasses2/src/Unicode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18224/src/Unicode Modified Files: String.cpp Log Message: - Added Traits::LexT<StringList<std::string> >, Traits::LexT<StringList<Unicode::String> >, Traits::LexT<Unicode::String> Index: String.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/String.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- String.cpp 29 Jun 2005 00:07:44 -0000 1.12 +++ String.cpp 1 Jul 2005 13:55:10 -0000 1.13 @@ -169,6 +169,12 @@ return 0; } +void String::reserve(size_t sz) +{ + if(capacity() < sz) + resize(sz); +} + void String::resize(size_t sz) { if(!sz) @@ -848,6 +854,12 @@ return ret; } +String String::fromUtf8(const std::string& str) + throw(OutOfMemory, UnicodeError) +{ + return fromUtf8(str.c_str(), str.size()); +} + std::string String::toCodepage(const char* codepage) const throw(OutOfMemory, UnicodeError) { @@ -865,6 +877,12 @@ return cvt->toUnicode(str, count); } +String String::fromCodepage(const std::string& str, const char* codepage) + throw(OutOfMemory, UnicodeError) +{ + return fromCodepage(str.c_str(), str.size(), codepage); +} + const uchar16_t* String::data() const throw() { if(!_data.null()) @@ -889,8 +907,47 @@ return os; } +} // !namespace Unicode +namespace Traits { + +std::string LexT<Unicode::String>::toString(const Unicode::String& val) +{ + return val.utf8(); +} + +Unicode::String LexT<Unicode::String>::fromString(const std::string& str) + throw(ConversionError) +{ + Unicode::String ret; + try + { + ret = Unicode::String::fromUtf8(str); + } + catch(...) + { + throw ConversionError("Could not convert to Unicode string", P_SOURCEINFO); + } + + return ret; +} + + +std::string LexT<StringList<Unicode::String> >::toString( + const StringList<Unicode::String>& val) +{ + return val.join(",").utf8(); +} + +StringList<Unicode::String> + LexT<StringList<Unicode::String> >::fromString(const std::string& str) + throw(ConversionError) +{ + return StringList<Unicode::String>(Unicode::String::fromUtf8(str), ","); +} + + +} // !namespace Traits -} // !namespace Unicode } // !namespace P |
From: Christian P. <cp...@us...> - 2005-07-01 13:55:25
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18224/include/pclasses Modified Files: StringList.h Log Message: - Added Traits::LexT<StringList<std::string> >, Traits::LexT<StringList<Unicode::String> >, Traits::LexT<Unicode::String> Index: StringList.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/StringList.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- StringList.h 6 May 2005 15:28:51 -0000 1.3 +++ StringList.h 1 Jul 2005 13:55:09 -0000 1.4 @@ -21,7 +21,11 @@ #ifndef P_StringList_h #define P_StringList_h +#include <pclasses/Trace.h> +#include <pclasses/LexT.h> + #include <list> +#include <string> namespace P { @@ -37,18 +41,37 @@ StringList(const string_list& lst) : string_list(lst) { } + StringList(const StringList& lst) + : string_list(lst) { } + StringList(const StringType& str, const StringType& separator) { - *this = fromString(str, separator); + *this = split(str, separator); } //! Join all strings into a single string StringType join(const StringType& separator) const { - StringType ret; + size_t separatorLen = separator.size(); + size_t stringLen = 0; + + // pre-calculate string-length ... typename string_list::const_iterator i = this->begin(); while(i != this->end()) { + stringLen += (*i).size(); + ++i; + if(i != this->end()) + stringLen += separatorLen; + } + + StringType ret; + ret.reserve(stringLen); + + // now build the string ... + i = this->begin(); + while(i != this->end()) + { ret += *i; ++i; if(i != this->end()) @@ -59,7 +82,7 @@ } //! Tokenize string into list of strings - static string_list fromString(const StringType& str, + static string_list split(const StringType& str, const StringType& separator) { if(str.empty()) @@ -81,9 +104,32 @@ return lst; } + StringList& operator=(const StringList& lst) + { + string_list::operator=(lst); + return *this; + } +}; + + +namespace Traits { + +template < > +struct LexT<StringList<std::string> > { + + static std::string toString(const StringList<std::string>& val) + { return val.join(","); } + + static StringList<std::string> fromString(const std::string& str) + throw(ConversionError) + { return StringList<std::string>(str, ","); } + }; +} // !namespace Traits + + } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-07-01 13:53:02
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16708/include/pclasses/App Modified Files: CmdLine.h Log Message: - Removed std::string from Exception. The base exception should not throw in any case - Fixed CmdLineError and added extra exception info field Index: CmdLine.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/CmdLine.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- CmdLine.h 24 Jan 2005 22:58:38 -0000 1.6 +++ CmdLine.h 1 Jul 2005 13:52:51 -0000 1.7 @@ -103,8 +103,11 @@ class PAPP_EXPORT CmdLineError: public RuntimeError { public: - CmdLineError(const std::string& what, const SourceInfo& si); - ~CmdLineError(); + CmdLineError(const char* what, const std::string& extra, const SourceInfo& si); + ~CmdLineError() throw(); + + private: + std::string _extra; }; //! Advanced command-line parser |
From: Christian P. <cp...@us...> - 2005-07-01 13:53:02
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16708/include/pclasses Modified Files: Exception.h Log Message: - Removed std::string from Exception. The base exception should not throw in any case - Fixed CmdLineError and added extra exception info field Index: Exception.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Exception.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Exception.h 20 Jan 2005 22:16:13 -0000 1.5 +++ Exception.h 1 Jul 2005 13:52:51 -0000 1.6 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004 by Christian Prochnow * + * Copyright (C) 2004,2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -18,16 +18,17 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _P_Exception_h_ -#define _P_Exception_h_ +#ifndef P_Exception_h +#define P_Exception_h -#include <string> #include <pclasses/Export.h> #include <pclasses/SourceInfo.h> +#include <string> namespace P { -/** +//! Exception base class +/*! This is the base Exception class for the P framework. Exception uses a non-traditional ctor, requiring a SourceInfo @@ -35,49 +36,66 @@ throw MyException( "dammit!", P_SOURCEINFO ); +Cause exception objects must not allocate memory when thrown, the +what argument to the Exception ctor must be a statically allocated +string. + Clients may use the what() and where() methods to get information about the exception. - */ class PCORE_EXPORT Exception { public: - /** - Creates an exception with the given what() string - and the given SourceInfo. + //! Constructor + /*! + Creates an exception with the given what() string + and the given SourceInfo. The what argument must be a + statically allocated string cause it's only referenced + by the Exception class. + \param what a statically allocated string describing + what happened + \param si the source location where the exception occured. + use P_SOURCEINFO for ease of use. */ Exception(const char* what, const SourceInfo& si) throw(); - /** - Convenience/compatibility overload. - */ - Exception(const std::string & what, const SourceInfo& si) throw(); + //! Copy constructor Exception(const Exception& err) throw(); - ~Exception() throw(); - Exception& operator=(const Exception& err) throw(); + //! Destructor + ~Exception() throw(); - /** - Returns a description of the exception. + //! Returns the cause auf the exception + /*! + Returns a description of what happened. */ const char* what() const throw(); - /** + /*! Returns a string describing where this exception - was thrown. + was thrown. Note that this method may throw. */ - const char * where() const throw(); + std::string where() const; + + //! Assignment operator + Exception& operator=(const Exception& err) throw(); private: - std::string _what; + const char* _what; const SourceInfo* _source; - mutable std::string _where; // really should be a const char *, but that's not practical here w/o malloc()ing. }; +PCORE_EXPORT std::ostream& operator<<(std::ostream& os, const Exception& err); + + //! Logic error +/*! + This exception class is thrown whenever the framework detects + a logical error. For example when you try to start a Thread which + is already running. +*/ class PCORE_EXPORT LogicError: public Exception { public: LogicError(const char* what, const SourceInfo& si) throw(); - LogicError(const std::string & what, const SourceInfo& si) throw(); ~LogicError() throw(); }; @@ -85,39 +103,39 @@ class PCORE_EXPORT RuntimeError: public Exception { public: RuntimeError(const char* what, const SourceInfo& si) throw(); - RuntimeError(const std::string & what, const SourceInfo& si) throw(); ~RuntimeError() throw(); }; class PCORE_EXPORT OverrunError: public RuntimeError { public: OverrunError(const char* what, const SourceInfo& si) throw(); - OverrunError(const std::string & what, const SourceInfo& si) throw(); ~OverrunError() throw(); }; class PCORE_EXPORT UnderrunError: public RuntimeError { public: UnderrunError(const char* what, const SourceInfo& si) throw(); - UnderrunError(const std::string & what, const SourceInfo& si) throw(); - ~UnderrunError() throw(); }; class PCORE_EXPORT OutOfBounds: public RuntimeError { public: OutOfBounds(const char* what, const SourceInfo& si) throw(); - OutOfBounds(const std::string & what, const SourceInfo& si) throw(); ~OutOfBounds() throw(); }; class PCORE_EXPORT OverflowError: public RuntimeError { public: OverflowError(const char* what, const SourceInfo& si) throw(); - OverflowError(const std::string & what, const SourceInfo& si) throw(); ~OverflowError() throw(); }; +class PCORE_EXPORT ConversionError: public RuntimeError { + public: + ConversionError(const char* what, const SourceInfo& si) throw(); + ~ConversionError() throw(); +}; + } //! namespace P #endif |
From: Christian P. <cp...@us...> - 2005-07-01 13:53:02
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16708/src Modified Files: Exception.cpp Log Message: - Removed std::string from Exception. The base exception should not throw in any case - Fixed CmdLineError and added extra exception info field Index: Exception.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Exception.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Exception.cpp 25 Dec 2004 00:04:38 -0000 1.6 +++ Exception.cpp 1 Jul 2005 13:52:51 -0000 1.7 @@ -19,21 +19,17 @@ ***************************************************************************/ #include "pclasses/Exception.h" +#include <sstream> namespace P { Exception::Exception(const char* what, const SourceInfo& si) throw() - : _what(what?what:""), _source(&si), _where("") -{ -} - -Exception::Exception(const std::string & what, const SourceInfo& si) throw() - : _what(what), _source(&si), _where("") + : _what(what ? what : ""), _source(&si) { } Exception::Exception(const Exception& err) throw() - : _what(err._what), _source(err._source), _where(err._where) + : _what(err._what), _source(err._source) { } @@ -41,41 +37,46 @@ { } -const char * Exception::where() const throw() +std::string Exception::where() const { - if( _where.empty() && _source ) + std::ostringstream where; + + where << "["; + if(_source->file()) { - _where = "["; - if( _source->file() ) - { - _where += "file = "; - _where += _source->file(); - } - if( _source->line() ) - { - _where += ": line = "; - _where += _source->line(); - } -// if( _source->func() ) -// { -// _where += " : function = "; -// _where += _source->func(); // segfault here -// } - _where += "]"; + where << "file = "; + where << _source->file(); } - return _where.c_str(); + + where << ": line = "; + where << _source->line(); + + if(_source->func()) + { + where << " : function = "; + where << _source->func(); + } + + where << "]"; + return where.str(); } const char* Exception::what() const throw() { - return _what.c_str(); + return _what; } Exception& Exception::operator=(const Exception& err) throw() { _what = err._what; _source = err._source; - return *this; + return *this; +} + +std::ostream& operator<<(std::ostream& os, const Exception& err) +{ + os << "Exception: " << err.what() << ' ' << err.where(); + return os; } @@ -94,11 +95,6 @@ { } -RuntimeError::RuntimeError(const std::string & what, const SourceInfo& si) throw() -: Exception(what, si) -{ -} - RuntimeError::~RuntimeError() throw() { } @@ -108,10 +104,6 @@ : RuntimeError(what, si) { } -OutOfBounds::OutOfBounds(const std::string & what, const SourceInfo& si) throw() -: RuntimeError(what, si) -{ -} OutOfBounds::~OutOfBounds() throw() { @@ -122,10 +114,6 @@ : RuntimeError(what, si) { } -OverrunError::OverrunError(const std::string & what, const SourceInfo& si) throw() -: RuntimeError(what, si) -{ -} OverrunError::~OverrunError() throw() { @@ -136,10 +124,6 @@ : RuntimeError(what, si) { } -UnderrunError::UnderrunError(const std::string & what, const SourceInfo& si) throw() -: RuntimeError(what, si) -{ -} UnderrunError::~UnderrunError() throw() { @@ -150,12 +134,18 @@ : RuntimeError(what, si) { } -OverflowError::OverflowError(const std::string & what, const SourceInfo& si) throw() + +OverflowError::~OverflowError() throw() +{ +} + + +ConversionError::ConversionError(const char* what, const SourceInfo& si) throw() : RuntimeError(what, si) { } -OverflowError::~OverflowError() throw() +ConversionError::~ConversionError() throw() { } |
From: Christian P. <cp...@us...> - 2005-07-01 13:53:01
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16708/src/App Modified Files: CmdLine.cpp Log Message: - Removed std::string from Exception. The base exception should not throw in any case - Fixed CmdLineError and added extra exception info field Index: CmdLine.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/CmdLine.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- CmdLine.cpp 24 Jan 2005 22:58:42 -0000 1.6 +++ CmdLine.cpp 1 Jul 2005 13:52:51 -0000 1.7 @@ -164,12 +164,13 @@ return 0; } -CmdLineError::CmdLineError(const std::string& what, const SourceInfo& si) -: RuntimeError(what, si) +CmdLineError::CmdLineError(const char* what, const std::string& extra, + const SourceInfo& si) +: RuntimeError(what, si), _extra(extra) { } -CmdLineError::~CmdLineError() +CmdLineError::~CmdLineError() throw() { } @@ -221,8 +222,8 @@ // unknown option ... if(!opt) - throw CmdLineError("Unknown command-line argument: " + - std::string(argv[i]), P_SOURCEINFO); + throw CmdLineError("Unknown command-line argument", + argv[i], P_SOURCEINFO); // do we have value for this option ....? // it doesnt matter if the option needs a value or not... @@ -263,14 +264,13 @@ if(opt) { std::ostringstream errOs; - errOs << "Value for command-line argument '"; - if(opt->shortName().size() > 0) + if(!opt->shortName().empty()) errOs << "-" << opt->shortName(); else errOs << "--" << opt->longName(); - errOs << "' is missing." << std::endl; - throw CmdLineError(errOs.str(), P_SOURCEINFO); + throw CmdLineError("Missing value for command-line argument", + errOs.str(), P_SOURCEINFO); } // search for required option which where not found @@ -289,14 +289,13 @@ if(_opts[i]->required() && !_opts[i]->isset()) { std::ostringstream errOs; - errOs << "Required command-line argument '"; - if(_opts[i]->shortName().size() > 0) + if(!_opts[i]->shortName().empty()) errOs << "-" << _opts[i]->shortName(); else errOs << "--" << _opts[i]->longName(); - errOs << "' missing." << std::endl; - throw CmdLineError(errOs.str(), P_SOURCEINFO); + throw CmdLineError("Missing required command-line argument", + errOs.str(), P_SOURCEINFO); } } @@ -321,7 +320,7 @@ void CmdLineParser::parse(const std::string& cmdline) throw(CmdLineError) { //@fixme - throw CmdLineError("Not implemented", P_SOURCEINFO); + throw CmdLineError("Not implemented", "", P_SOURCEINFO); } void CmdLineParser::dumpHelp(std::ostream& os) const |
From: Christian P. <cp...@us...> - 2005-07-01 12:17:47
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31120/test Modified Files: LogTest.cpp Log Message: - Fixed LogTest Index: LogTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/LogTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- LogTest.cpp 6 May 2005 22:57:59 -0000 1.2 +++ LogTest.cpp 1 Jul 2005 12:17:36 -0000 1.3 @@ -21,6 +21,7 @@ #include "Test.h" #include "pclasses/IO/URL.h" #include "pclasses/System/Plugin.h" +#include "pclasses/System/Path.h" #include "pclasses/App/LogManager.h" #include "pclasses/App/LogTarget.h" #include "pclasses/App/LogChannel.h" @@ -40,11 +41,13 @@ App::LogManager& logMgr = App::LogManager::instance(); App::LogChannel* globalChannel = logMgr.addChannel("global"); - App::LogTarget* target = logMgr.addTarget(globalChannel, "console", "ConsoleLogTarget"); + App::LogTarget* target = logMgr.addTarget("console", "ConsoleLogTarget"); target->open(IO::URL()); + globalChannel->addTarget(target); - App::LogTarget* target2 = logMgr.addTarget(globalChannel, "file", "FileLogTarget"); + App::LogTarget* target2 = logMgr.addTarget("file", "FileLogTarget"); target2->open(IO::URL("file:/home/cproch/logtest.log")); + globalChannel->addTarget(target2); (*globalChannel)(App::LogMessage::Debug) << "test" << std::endl; (*globalChannel)(App::LogMessage::Info) << "test" << std::endl; @@ -52,8 +55,8 @@ (*globalChannel)(App::LogMessage::Notice) << "test" << std::endl; (*globalChannel)(App::LogMessage::Error) << "test" << std::endl; - logMgr.removeTarget(globalChannel, "console"); - logMgr.removeTarget(globalChannel, "file"); + logMgr.removeTarget("console"); + logMgr.removeTarget("file"); } }; |
From: Christian P. <cp...@us...> - 2005-07-01 12:16:16
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27116/src/App Modified Files: Config.cpp Log Message: - Removed ConfigValue and use LexT instead, as it adds unneeded complexity Index: Config.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/Config.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Config.cpp 29 Jun 2005 00:11:10 -0000 1.2 +++ Config.cpp 1 Jul 2005 12:16:05 -0000 1.3 @@ -36,39 +36,6 @@ } -ConfigValue::ConfigValue() -{ -} - -ConfigValue::ConfigValue(const std::string& value) -: _value(value) -{ -} - -ConfigValue::ConfigValue(const Unicode::String& value) -: _value(value) -{ -} - -ConfigValue::ConfigValue(double value) -{ - //@todo -} - -ConfigValue::~ConfigValue() throw() -{ -} - -const Unicode::String& ConfigValue::toString() const throw() -{ - return _value; -} - -StringList<Unicode::String> ConfigValue::toStringList() const -{ - return StringList<Unicode::String>(_value, ","); -} - ConfigSection::ConfigSection(Config* cfg, const std::string& name) : _cfg(cfg), _name(name) { @@ -224,7 +191,7 @@ return i; } -const ConfigValue& ConfigSection::value(const std::string& name, +const LexT& ConfigSection::value(const std::string& name, bool add) throw(ConfigError) { value_iterator i = findValue(name); @@ -234,32 +201,32 @@ if(!add) throw ConfigError("Value not found", P_SOURCEINFO); - const ConfigValue& val = - (*_values.insert(_values.begin(), std::make_pair(name, ConfigValue()))).second; + const LexT& val = + (*_values.insert(_values.begin(), std::make_pair(name, LexT()))).second; _cfg->setModified(); return val; } -const ConfigValue& ConfigSection::value(const std::string& name, - const ConfigValue& defaultVal, bool add) +const LexT& ConfigSection::value(const std::string& name, + const LexT& defaultVal, bool add) { value_iterator i = findValue(name); if(i != _values.end()) return i->second; - const ConfigValue* v = &defaultVal; + const LexT* v = &defaultVal; if(add) { - v = &(*_values.insert(_values.begin(), std::make_pair(name, ConfigValue()))).second; + v = &(*_values.insert(_values.begin(), std::make_pair(name, defaultVal))).second; _cfg->setModified(); } return *v; } -void ConfigSection::setValue(const std::string& name, const ConfigValue& val) +void ConfigSection::setValue(const std::string& name, const LexT& val) { value_iterator i = findValue(name); if(i != _values.end()) |
From: Christian P. <cp...@us...> - 2005-07-01 12:16:13
|
Update of /cvsroot/pclasses/pclasses2/plugins/ConfigStore/ini In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27116/plugins/ConfigStore/ini Modified Files: ConfigStore_ini.cpp Makefile.am Log Message: - Removed ConfigValue and use LexT instead, as it adds unneeded complexity Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/plugins/ConfigStore/ini/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.am 29 Jun 2005 00:08:47 -0000 1.2 +++ Makefile.am 1 Jul 2005 12:16:05 -0000 1.3 @@ -2,15 +2,10 @@ METASOURCES = AUTO pkglib_LTLIBRARIES = ConfigStore_ini.la -noinst_PROGRAMS = lextest ConfigStore_ini_la_SOURCES = ConfigStore_ini.cpp ConfigStore_ini_la_LDFLAGS = -module -avoid-version -AM_YFLAGS = -d - -lextest_SOURCES = ini_lex.l ini_yacc.y - ConfigStore_ini_la_LIBADD = $(top_builddir)/src/libpclasses.la \ $(top_builddir)/src/Unicode/libpclasses_unicode.la \ $(top_builddir)/src/IO/libpclasses_io.la \ Index: ConfigStore_ini.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/plugins/ConfigStore/ini/ConfigStore_ini.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ConfigStore_ini.cpp 29 Jun 2005 00:08:47 -0000 1.2 +++ ConfigStore_ini.cpp 1 Jul 2005 12:16:05 -0000 1.3 @@ -147,7 +147,7 @@ ConfigSection::value_const_iterator vi = section.valuesBegin(); while(vi != section.valuesEnd()) { - std::string valueStr = vi->second.toString().utf8(); + std::string valueStr = vi->second; size_t valueStrLen = valueStr.size(); strm << vi->first << " = "; |
From: Christian P. <cp...@us...> - 2005-07-01 12:16:12
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27116/include/pclasses/App Modified Files: Config.h Log Message: - Removed ConfigValue and use LexT instead, as it adds unneeded complexity Index: Config.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/Config.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Config.h 29 Jun 2005 00:11:09 -0000 1.2 +++ Config.h 1 Jul 2005 12:16:04 -0000 1.3 @@ -24,6 +24,7 @@ #include <pclasses/Export.h> #include <pclasses/Exception.h> #include <pclasses/StringList.h> +#include <pclasses/LexT.h> #include <pclasses/Unicode/String.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/URL.h> @@ -40,46 +41,15 @@ ~ConfigError() throw(); }; -class PAPP_EXPORT ConfigValue { - public: - ConfigValue(); - ConfigValue(const std::string& value); - ConfigValue(const Unicode::String& value); - - template <class StringType> - ConfigValue(const StringList<StringType>& value) - : _value(value.join(",")) - { } - - ConfigValue(double value); - ConfigValue(Int32 value); - ConfigValue(UInt32 value); - - ~ConfigValue() throw(); - - const Unicode::String& toString() const throw(); - - StringList<Unicode::String> toStringList() const; - - double toDouble() const; - - Int32 toInt() const; - - UInt32 toUInt() const; - - private: - Unicode::String _value; -}; - class PAPP_EXPORT ConfigSection { public: typedef std::list<ConfigSection*> section_list; typedef section_list::iterator section_iterator; typedef section_list::const_iterator section_const_iterator; - typedef std::list<std::pair<std::string, ConfigValue> > value_map; - typedef value_map::iterator value_iterator; - typedef value_map::const_iterator value_const_iterator; + typedef std::list<std::pair<std::string, LexT> > value_list; + typedef value_list::iterator value_iterator; + typedef value_list::const_iterator value_const_iterator; const std::string& name() const throw(); @@ -110,13 +80,13 @@ value_const_iterator findValue(const std::string& name) const throw(); - const ConfigValue& value(const std::string& name, bool add = false) + const LexT& value(const std::string& name, bool add = false) throw(ConfigError); - const ConfigValue& value(const std::string& name, - const ConfigValue& defaultVal, bool add = false); + const LexT& value(const std::string& name, + const LexT& defaultVal, bool add = false); - void setValue(const std::string& name, const ConfigValue& val); + void setValue(const std::string& name, const LexT& val); bool removeValue(const std::string& name) throw(); @@ -132,7 +102,7 @@ Config* _cfg; std::string _name; section_list _sections; - value_map _values; + value_list _values; }; class PAPP_EXPORT Config { |
From: Christian P. <cp...@us...> - 2005-07-01 12:07:11
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24145/src/App Modified Files: LogChannel.cpp LogManager.cpp Log Message: - Fixed some design flaws (LogTargets could not be added to multiple LogChannels) - Added documentation to LogManager, LogTarget, LogChannel - Added locking to LogManager, LogChannel Index: LogManager.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogManager.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- LogManager.cpp 6 May 2005 15:24:35 -0000 1.4 +++ LogManager.cpp 1 Jul 2005 12:07:00 -0000 1.5 @@ -33,15 +33,7 @@ LogManager::~LogManager() throw() { - // delete our LogTargets ... - TargetMap::iterator ti = _targets.begin(); - while(ti != _targets.end()) - { - delete ti->second; - TargetMap::iterator del = ti; - ++ti; - _targets.erase(del); - } + System::CriticalSection::ScopedLock lck(_channelsMtx); // delete our LogChannels ... ChannelMap::iterator ci = _channels.begin(); @@ -51,112 +43,144 @@ ChannelMap::iterator del = ci; ++ci; _channels.erase(del); - } + } + + System::CriticalSection::ScopedLock lck2(_targetsMtx); + + // delete our LogTargets ... + TargetMap::iterator ti = _targets.begin(); + while(ti != _targets.end()) + { + delete ti->second; + TargetMap::iterator del = ti; + ++ti; + _targets.erase(del); + } } void LogManager::reload() throw() { - for(ChannelMap::const_iterator i = _channels.begin(); - i != _channels.end(); ++i) + System::CriticalSection::ScopedLock lck(_targetsMtx); + + for(TargetMap::const_iterator i = _targets.begin(); + i != _targets.end(); ++i) { - LogChannel* channel = i->second; - channel->reload(); + LogTarget* target = i->second; + target->reload(); } } LogChannel* LogManager::addChannel(const std::string& name) { - LogChannel* chan = channel(name); - if(!chan) + System::CriticalSection::ScopedLock lck(_channelsMtx); + + LogChannel* chan = 0; + ChannelMap::const_iterator i = _channels.find(name); + if(i != _channels.end()) + { + chan = i->second; + } + else { chan = new LogChannel(name); - _channels[name] = chan; + _channels.insert(std::make_pair(name, chan)); } return chan; } -bool LogManager::removeChannel(const std::string& name) +bool LogManager::removeChannel(const std::string& name) throw() { + System::CriticalSection::ScopedLock lck(_channelsMtx); + ChannelMap::iterator i = _channels.find(name); if(i != _channels.end()) { - LogChannel* chan = i->second; - - // delete all our LogTargets for this channel ... - TargetMap::iterator ti = _targets.begin(); - while(ti != _targets.end()) - { - if(ti->first.first == chan) - { - delete ti->second; - TargetMap::iterator del = ti; - ++ti; - _targets.erase(del); - } - else - { - ++ti; - } - } - + delete i->second; _channels.erase(i); - delete chan; - return true; } return false; } -LogTarget* LogManager::addTarget(LogChannel* channel, const std::string& name, const std::string& type) +LogChannel* LogManager::channel(const std::string& name) const throw() { - LogTarget* target = LogTargetFactory::instance().create(type); - if(target) - { - if(!channel->addTarget(name, target)) - { - delete target; - target = 0; - } + System::CriticalSection::ScopedLock lck(_channelsMtx); - _targets[make_pair(channel, name)] = target; - } + LogChannel* chan = 0; + ChannelMap::const_iterator i = _channels.find(name); + if(i != _channels.end()) + chan = i->second; - return target; + return chan; } -bool LogManager::removeTarget(LogChannel* channel, const std::string& name) +LogTarget* LogManager::addTarget(const std::string& name, const std::string& type) { - TargetMap::iterator i = _targets.find(make_pair(channel, name)); + System::CriticalSection::ScopedLock lck(_targetsMtx); + + LogTarget* target = 0; + TargetMap::const_iterator i = _targets.find(name); + + // target already exists ... if(i != _targets.end()) { - LogTarget* target = channel->removeTarget(name); + target = i->second; + } + // create the new target ... + else + { + target = LogTargetFactory::instance().create(type); + if(target) + _targets.insert(std::make_pair(name, target)); + } + + return target; +} + +bool LogManager::removeTarget(const std::string& name) +{ + System::CriticalSection::ScopedLock lck(_targetsMtx); + + TargetMap::iterator ti = _targets.find(name); + if(ti != _targets.end()) + { + LogTarget* target = ti->second; + + // remove target from channels ... + System::CriticalSection::ScopedLock lck2(_channelsMtx); + + ChannelMap::iterator ci = _channels.begin(); + while(ci != _channels.end()) + { + ci->second->removeTarget(target); + ++ci; + } + delete target; - _targets.erase(i); + _targets.erase(ti); return true; } return false; } -LogChannel* LogManager::channel(const std::string& name) const +LogTarget* LogManager::target(const std::string& name) const throw() { - LogChannel* chan = 0; - ChannelMap::const_iterator i = _channels.find(name); - if(i != _channels.end()) - chan = i->second; + System::CriticalSection::ScopedLock lck(_targetsMtx); - return chan; + LogTarget* target = 0; + TargetMap::const_iterator i = _targets.find(name); + if(i != _targets.end()) + target = i->second; + + return target; } LogChannel& LogManager::operator()(const std::string& chanName) { - LogChannel* chan = channel(chanName); - if(!chan) - chan = addChannel(chanName); - - return *chan; + return *addChannel(chanName); } struct LogManagerContext { }; Index: LogChannel.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogChannel.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- LogChannel.cpp 28 Apr 2005 10:34:06 -0000 1.3 +++ LogChannel.cpp 1 Jul 2005 12:06:59 -0000 1.4 @@ -143,36 +143,29 @@ return _name; } -bool LogChannel::addTarget(const std::string& name, LogTarget* target) -{ - TargetMap::const_iterator i = _targets.find(name); - if(i != _targets.end()) - return false; - - _targets[name] = target; - return true; -} - -LogTarget* LogChannel::removeTarget(const std::string& name) throw() +bool LogChannel::addTarget(LogTarget* target) { - LogTarget* target = 0; + System::CriticalSection::ScopedLock lck(_mutex); - TargetMap::iterator i = _targets.find(name); - if(i != _targets.end()) + for(TargetList::iterator i = _targets.begin(); + i != _targets.end(); ++i) { - target = i->second; - _targets.erase(i); + if(*i == target) + return false; } - return target; + _targets.push_back(target); + return true; } bool LogChannel::removeTarget(LogTarget* target) throw() { - for(TargetMap::iterator i = _targets.begin(); + System::CriticalSection::ScopedLock lck(_mutex); + + for(TargetList::iterator i = _targets.begin(); i != _targets.end(); ++i) { - if(i->second == target) + if(*i == target) { _targets.erase(i); return true; @@ -182,31 +175,17 @@ return false; } -void LogChannel::reload() const throw() -{ - for(TargetMap::const_iterator i = _targets.begin(); - i != _targets.end(); ++i) - { - LogTarget* target = i->second; - try - { - target->reload(); - } - catch(IO::IOError& err) - { - } - } -} - void LogChannel::output(const LogMessage& msg) const throw() { if(msg.level() >= _logLevel) { + System::CriticalSection::ScopedLock lck(_mutex); + // output to all registered LogTargets ... - for(TargetMap::const_iterator i = _targets.begin(); + for(TargetList::const_iterator i = _targets.begin(); i != _targets.end(); ++i) { - LogTarget* target = i->second; + LogTarget* target = *i; try { if(target->valid() && msg.level() >= target->logLevel()) @@ -223,11 +202,13 @@ LogMessage::Level LogChannel::logLevel() const throw() { + System::CriticalSection::ScopedLock lck(_mutex); return _logLevel; } void LogChannel::setLogLevel(LogMessage::Level l) throw() { + System::CriticalSection::ScopedLock lck(_mutex); _logLevel = l; } |
From: Christian P. <cp...@us...> - 2005-07-01 12:07:11
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24145/include/pclasses/App Modified Files: LogChannel.h LogManager.h LogTarget.h Log Message: - Fixed some design flaws (LogTargets could not be added to multiple LogChannels) - Added documentation to LogManager, LogTarget, LogChannel - Added locking to LogManager, LogChannel Index: LogManager.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/LogManager.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- LogManager.h 24 Apr 2005 11:36:31 -0000 1.2 +++ LogManager.h 1 Jul 2005 12:06:59 -0000 1.3 @@ -22,6 +22,7 @@ #define P_LogManager_h #include <pclasses/Export.h> +#include <pclasses/System/CriticalSection.h> #include <pclasses/App/LogTarget.h> #include <pclasses/App/LogChannel.h> @@ -32,66 +33,123 @@ namespace App { -//! Log manager +//! Logging manager +/*! + The LogManager class provides a container for easy management of + LogChannel and LogTarget objects. Together with these classes the + LogManager forms the logging framework of P::Classes. + + All methods in this class a thread-safe. +*/ class PAPP_EXPORT LogManager { public: //! Map of LogChannels typedef std::map<std::string,LogChannel*> ChannelMap; //! Map of owned LogTargets - typedef std::map< - std::pair<LogChannel*, std::string>, - LogTarget* - > TargetMap; + typedef std::map<std::string,LogTarget*> TargetMap; + //! Constructor LogManager(); + + //! Destructor + /*! + The destructor deletes all channels and targets + wich have been previously added. + */ ~LogManager() throw(); //! Close and re-open all LogTargets void reload() throw(); - //! Add logging channel + //! Add a logging channel /*! - Returns NULL if the named LogChannel already exists. - The LogChannel is owned by the LogManager. + Adds a LogChannel to the LogManager which is identified + by the given name. If the method is called twice for the + same name, it simply returns a pointer to the previously + added LogChannel. + The LogChannel is owned by the LogManager and must not be + deleted by the client code. + \param name the name for the added LogChannel + \return returns a pointer to the LogChannel object */ LogChannel* addChannel(const std::string& name); //! Remove logging channel - bool removeChannel(const std::string& name); + /*! + Removes a previously added LogChannel object identified by the + given name. Returns true if the channel was removed, false if + the channel is unknown. + \param name the name of the LogChannel to remove + \return returns true if the channel was removed, false otherwise + */ + bool removeChannel(const std::string& name) throw(); //! Returns a pointer to the named LogChannel /*! - Returns NULL if the named LogChannel does not exist. + Returns a pointer to the LogChannel object identified by the + given name. Returns NULL if the named LogChannel does not exist. + \param name the name of the LogChannel which should be returned + \return a pointer to the LogChannel object identified by the given name */ - LogChannel* channel(const std::string& name) const; + LogChannel* channel(const std::string& name) const throw(); - //! Add a logging target + //! Add logging target /*! - Returns NULL if the target already exists, or the LogTarget - type is not registered. - The LogTarget is owned by the LogManager. + Adds a LogTarget to the LogManager which is identified by the given + name. If the method is called twice for the same name, it simply + returns a pointer to the previously added LogTarget. + The LogTarget is created by a call to Factory<LogTarget>::create(type) + If the LogTarget could not be created by the Factory, a NULL + pointer is returned. + The LogTarget is owned by the LogManager and must not be + deleted by the client code. + \param name the name for the added LogTarget + \param type the type of the LogTarget to create + \return returns a pointer to the LogTarget object */ - LogTarget* addTarget(LogChannel* chan, const std::string& name, - const std::string& type); + LogTarget* addTarget(const std::string& name, const std::string& type); - //! Remove a logging target - bool removeTarget(LogChannel* chan, const std::string& name); + //! Remove logging target + /*! + Removes a previously added LogTarget object identified by the + given name. Returns true if the target was removed, false if + the channel is unknown. + \param name the name of the LogTarget to remove + \return returns true if the target was removed, false otherwise + */ + bool removeTarget(const std::string& name); + + //! Returns a pointer to the named LogTarget + /*! + Returns a pointer to the LogTarget object identified by the + given name. Returns NULL if the named LogTarget does not exist. + \param name the name of the LogTarget which should be returned + \return a pointer to the LogTarget object identified by the given name + */ + LogTarget* target(const std::string& name) const throw(); //! Returns a refernce to the named LogChannel /*! - If the channel does not exist it is created. + This method does basically the same as channel(chanName); + Except it adds the LogChannel if it does not exist. + \param chanName name of the LogChannel to retrieve + \return a reference to the named LogChannel */ - LogChannel& operator()(const std::string& channel); + LogChannel& operator()(const std::string& chanName); //! Returns the instance of the LogManager static LogManager& instance(); private: - ChannelMap _channels; - TargetMap _targets; + mutable System::CriticalSection + _channelsMtx, _targetsMtx; + + ChannelMap _channels; + TargetMap _targets; }; +#define P_LOG(channel) P::App::LogManager::instance()(channel) } // !namespace App Index: LogTarget.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/LogTarget.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- LogTarget.h 6 May 2005 15:24:34 -0000 1.3 +++ LogTarget.h 1 Jul 2005 12:06:59 -0000 1.4 @@ -31,7 +31,16 @@ namespace App { -//! Log message target +//! Logging target +/*! + The LogTarget interface is used by the LogChannel class to output + it's log messages. Log messages are usally written to a LogChannel + which then output's the message to it's known LogTarget's. + Note that a LogTarget object may be added to multiple LogChannel's + which in turn may output messages simultanously from multiple + threads, therefore a class inherited from LogTarget must implement + locking by itself. +*/ class PAPP_EXPORT LogTarget { public: LogTarget(); Index: LogChannel.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/LogChannel.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- LogChannel.h 28 Apr 2005 10:34:06 -0000 1.3 +++ LogChannel.h 1 Jul 2005 12:06:59 -0000 1.4 @@ -23,10 +23,11 @@ #include <pclasses/Export.h> #include <pclasses/IO/IOError.h> +#include <pclasses/System/CriticalSection.h> #include <pclasses/App/LogMessage.h> #include <string> -#include <map> +#include <list> #include <iostream> namespace P { @@ -35,10 +36,18 @@ class LogTarget; -//! Log message channel +//! Logging channel +/*! + The LogChannel class is used to output LogMessage's to its + registered LogTarget's. + Messages are only written to its targets if the level of the + message is greater or equal to the log-level of the LogChannel. + + All methods in this class are thread-safe. +*/ class PAPP_EXPORT LogChannel: public std::ostream { public: - typedef std::map<std::string, LogTarget*> TargetMap; + typedef std::list<LogTarget*> TargetList; LogChannel(const std::string& name); ~LogChannel() throw(); @@ -46,18 +55,11 @@ const std::string& name() const; //! Add a logging target - bool addTarget(const std::string& name, - LogTarget* target); - - //! Remove named logging target - LogTarget* removeTarget(const std::string& name) throw(); + bool addTarget(LogTarget* target); //! Remove logging target by pointer bool removeTarget(LogTarget* target) throw(); - //! Close and re-open all targets - void reload() const throw(); - //! Output log message to all targets void output(const LogMessage& msg) const throw(); @@ -71,9 +73,10 @@ LogChannel& operator()(LogMessage::Level) throw(); private: - std::string _name; - TargetMap _targets; - LogMessage::Level _logLevel; + mutable System::CriticalSection _mutex; + std::string _name; + TargetList _targets; + LogMessage::Level _logLevel; }; |