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: stephan b. <sg...@us...> - 2004-12-25 18:58:41
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17734/include/pclasses/System Modified Files: Mime.h Log Message: Added i/ostream operators for MimeType. Fixed mimeType() to return an empty string on an invalid (empty) type. Index: Mime.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Mime.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Mime.h 25 Dec 2004 18:08:03 -0000 1.8 +++ Mime.h 25 Dec 2004 18:58:32 -0000 1.9 @@ -57,9 +57,14 @@ ~MimeType(); - //! Return the full MIME type + /** + Return the full MIME type string, in the format mediatype/subtype. + + If called on a default-constructed object it returns an + empty string. + */ inline const std::string mimeType() const - { return m_mediaType + "/" + m_subType; } + { return m_mediaType.empty() ? "" : (m_mediaType + "/" + m_subType); } //! Returns the MIME media type inline const std::string& mediaType() const @@ -91,7 +96,25 @@ Returns the equivalent of (lhs.mimeType() == rhs). */ bool operator==( const MimeType & lhs, const std::string & rhs ); - + +/** + Writes m.mimeType() to os. +*/ +std::ostream & operator<<( std::ostream &, const MimeType & m ); +/** + Reads one token from the stream, assuming it is + in the format media/subtype. The mimetype object + is then reconstructed with that data. + + On error (token not in correct format or IO error) m is not + modified. If parsing of the token fails then the stream's failbit + flag is set, though this behaviour is arguable and may be removed + after discussing it with other coders. + + This function reads char-by-char from the stream to avoid + depending on the stream's skipws flag. +*/ +std::istream & operator>>( std::istream &, MimeType & m ); //! MIME type database /*! |
From: stephan b. <sg...@us...> - 2004-12-25 18:08:22
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10782/src/System Modified Files: Mime.cpp Log Message: Moved the comparison ops into namespace-scope funcs, non-friends. i'm not sure why, but C++ gurus making them free funcs if possible, as opposed to members. Index: Mime.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Mime.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Mime.cpp 24 Dec 2004 16:23:24 -0000 1.7 +++ Mime.cpp 25 Dec 2004 18:08:03 -0000 1.8 @@ -94,39 +94,31 @@ { } -bool MimeType::operator<( const MimeType & rhs ) const +bool operator<( const MimeType &lhs, const MimeType & rhs ) { - if( &rhs == this ) return false; - return this->mimeType() < rhs.mimeType(); - if( m_mediaType < rhs.m_mediaType) - { - return true; - } - else if( m_mediaType == rhs.m_mediaType) - { - return (m_subType < rhs.m_subType); - } - return false; + if( &rhs == &lhs ) return false; + return lhs.mimeType() < rhs.mimeType(); } -bool MimeType::operator==( const MimeType & rhs ) const +bool operator==( const MimeType & lhs, const MimeType & rhs ) { - return (m_mediaType == rhs.m_mediaType) - && - (m_subType == rhs.m_subType) - ; + return (lhs.mimeType() == rhs.mimeType()); } +bool operator==( const MimeType & lhs, const std::string & rhs ) +{ + return lhs.mimeType() == rhs; +} + + MimeTypeDb::MimeTypeDb() { } MimeTypeDb::~MimeTypeDb() { - m_types.clear(); - m_exts.clear(); - m_rexts.clear(); + this->clear(); } @@ -175,7 +167,7 @@ this->insert(mtype); return true; } - + void MimeTypeDb::mapExtension(const MimeType& mimet, const std::string & file_ext ) { // CERR << "mapping extension ["<<file_ext<<"] \t==>\t[" << mimet.mimeType()<<"]\n"; |
From: stephan b. <sg...@us...> - 2004-12-25 18:08:17
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10782/include/pclasses/System Modified Files: Mime.h Log Message: Moved the comparison ops into namespace-scope funcs, non-friends. i'm not sure why, but C++ gurus making them free funcs if possible, as opposed to members. Index: Mime.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Mime.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Mime.h 25 Dec 2004 00:06:01 -0000 1.7 +++ Mime.h 25 Dec 2004 18:08:03 -0000 1.8 @@ -57,20 +57,6 @@ ~MimeType(); - /** - For compatibility with containers. - - Returns the equivalent of mimeType()<rhs.mimeType(). - */ - bool operator<( const MimeType & rhs ) const; - - /** - For compatibility with containers. - Returns true if this object's media- and sub-types are the - same as rhs'. - */ - bool operator==( const MimeType & rhs ) const; - //! Return the full MIME type inline const std::string mimeType() const { return m_mediaType + "/" + m_subType; } @@ -88,6 +74,24 @@ std::string m_subType; }; +/** + For compatibility with sorted containers. + + Returns the equivalent of (lhs.mimeType() < rhs.mimeType()). + +*/ +bool operator<( const MimeType & lhs, const MimeType & rhs ) ; + +/** + Returns the equivalent of (lhs.mimeType() == rhs.mimeType()). +*/ +bool operator==( const MimeType & lhs, const MimeType & rhs ); + +/** + Returns the equivalent of (lhs.mimeType() == rhs). +*/ +bool operator==( const MimeType & lhs, const std::string & rhs ); + //! MIME type database /*! @@ -124,7 +128,7 @@ @fixme: should not re-insert existing file extension mappings into mimeToFilesMap(). - @fixme: allow file_ext to e ba space-separated list of extensions. + @fixme: allow file_ext to be a space-separated list of extensions. */ void mapExtension(const MimeType& type, const std::string & file_ext ); @@ -263,9 +267,15 @@ Parses in a mime.types-format file from the given stream. Returns the number of mime type entries parsed from the stream. + + Does not clear existing entries - they are appended + to the current db. */ size_t readDatabase( std::istream & ); + /** + Cleares all mime type mappings in this database. + */ void clear(); private: @@ -289,14 +299,13 @@ } } // P::System -#include "pclasses/Factory.h" -#include "pclasses/SharingContext.h" +#include "pclasses/Plugin/Plugin.h" namespace P { namespace System { template <typename InterfaceT> - class MimeHandlerFactory : public ::P::Factory< InterfaceT, MimeType, ::P::Sharing::FactoryContext > + class MimeHandlerFactory : public ::P::Plugin::PluginManager< InterfaceT > { }; |
From: stephan b. <sg...@us...> - 2004-12-25 17:06:55
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2716/include/pclasses/IO Added Files: IOManager.h Log Message: First draft of IOPluginManager. Untested. --- NEW FILE: IOManager.h --- #ifndef P_IOMANAGER_HPP_INCLUDED #define P_IOMANAGER_HPP_INCLUDED 1 #include "pclasses/Phoenix.h" #include "pclasses/Plugin/Plugin.h" #include "pclasses/Net/URL.h" namespace P { namespace IO { /** IOManager is a PluginManager intended specifically for use with the P::IO layer. */ template <typename InterfaceT> class IOPluginManager : public ::P::PluginManager<InterfaceT> { public: typdef IOPluginManager<InterfaceT> ThisType; typedef ::P::PluginManager<InterfaceT> ParentType; typedef typename ParentType::factory_type factory_type; typedef typename ParentType::result_type result_type; using ::P::Net::URL; IOPluginManager(){} virtual ~IOPluginManager(){} /** Returns a shared instance of this object. */ static ThisType & instance() { typedef ::P::Phoenix<ThisType, ::P::Sharing::FactoryContext > PHX; return PHX::instance(); } /** Returns this->registerFactory(_protocol.protocol()). */ void registerFactory(const URL &_protocol, factory_type fp) { this->registerFactory( _protocol.protocol(), fp ) } /** Returns this->create(_protocol.protocol()). */ result_type create( const URL & _protocol ) { return this->create( _protocol.protocol() ); } /** Returns this->provides(_protocol.protocol()). */ bool provides(const URL &_protocol) const { return this->provides( _protocol.protocol() ); } }; // class IOPluginManager } } // namespace P::IO #endif // P_IOMANAGER_HPP_INCLUDED |
From: stephan b. <sg...@us...> - 2004-12-25 16:47:20
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32749 Modified Files: configure.pclasses2 Log Message: Removed PCLASSES_PLATFORM_SHARED_LIB_EXTENSION config var, as we now have SharedLib::extension(). Index: configure.pclasses2 =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.pclasses2,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- configure.pclasses2 25 Dec 2004 01:57:50 -0000 1.9 +++ configure.pclasses2 25 Dec 2004 16:47:11 -0000 1.10 @@ -145,8 +145,6 @@ -toc_export PCLASSES_PLATFORM_SHARED_LIB_EXTENSION="so" # TODO: change by platform - ######################################################################## # removeDupes is a helper app to remove duplicate entries from linker/ # includes arguments. |
From: stephan b. <sg...@us...> - 2004-12-25 16:47:20
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32749/include/pclasses Modified Files: pclasses-config.h.at Log Message: Removed PCLASSES_PLATFORM_SHARED_LIB_EXTENSION config var, as we now have SharedLib::extension(). Index: pclasses-config.h.at =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/pclasses-config.h.at,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pclasses-config.h.at 25 Dec 2004 01:55:46 -0000 1.5 +++ pclasses-config.h.at 25 Dec 2004 16:47:11 -0000 1.6 @@ -9,7 +9,6 @@ # undef _ALL_SOURCE #endif -#define PCLASSES_PLATFORM_SHARED_LIB_EXTENSION "@PCLASSES_PLATFORM_SHARED_LIB_EXTENSION@" #define PCLASSES_INSTALL_PREFIX "@prefix@" #define PCLASSES_LIB_DIR "@prefix@/lib" #define PCLASSES_SHARED_DATA_DIR "@prefix@/share/pclasses" |
From: stephan b. <sg...@us...> - 2004-12-25 16:47:20
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32749/include/pclasses/Plugin Modified Files: Plugin.h Log Message: Removed PCLASSES_PLATFORM_SHARED_LIB_EXTENSION config var, as we now have SharedLib::extension(). Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Plugin.h 25 Dec 2004 16:37:47 -0000 1.7 +++ Plugin.h 25 Dec 2004 16:47:11 -0000 1.8 @@ -214,7 +214,7 @@ this->m_path.addPath( "." ); this->m_path.addPath( PCLASSES_PLUGINS_DIR ); this->m_path.addPath( PCLASSES_LIB_DIR ); - this->m_path.addExtension(std::string(".")+std::string(PCLASSES_PLATFORM_SHARED_LIB_EXTENSION)); + this->m_path.addExtension(std::string(".")+::P::System::SharedLib::extension()); } PluginList m_holder; ::P::System::PathFinder m_path; |
From: stephan b. <sg...@us...> - 2004-12-25 16:37:57
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31576/include/pclasses Modified Files: Factory.h Log Message: More tweaking of the interface. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Factory.h 25 Dec 2004 02:45:48 -0000 1.9 +++ Factory.h 25 Dec 2004 16:37:47 -0000 1.10 @@ -51,7 +51,7 @@ The type returned by create() and operator(). */ - typedef T * result_type; + typedef T * ResultType; /** A typedef for the second template parameter for this @@ -72,7 +72,7 @@ The caller owns the returned pointer, which may be 0. */ - static result_type create() + static ResultType create() { return new actual_type; } @@ -80,7 +80,7 @@ /** Same as create(). */ - result_type operator()() + ResultType operator()() { return create(); } @@ -195,7 +195,7 @@ Same as (InterfaceT *), for conformance with the Adaptable Unary Functor model. */ - typedef InterfaceT * result_type; + typedef InterfaceT * ResultType; /** @@ -222,13 +222,13 @@ todo: implement proper functor support. */ - typedef result_type ( *factory_type ) (); + typedef ResultType ( *factory_func_type ) (); /** Internal container type used for mapping keys to factories. */ - typedef std::map < key_type, factory_type > FactoryMap; + typedef std::map < key_type, factory_func_type > FactoryMap; /** @@ -238,7 +238,7 @@ Subtypes are free to implement, e.g., DLL lookups. */ - virtual result_type create( const key_type & key ) + virtual ResultType create( const key_type & key ) { typename FactoryMap::const_iterator it = factoryMap().find( key ); if ( it != factoryMap().end() ) // found a factory? @@ -261,7 +261,7 @@ Subclasses are free to dictate a must-destroy() policy if they wish. */ - virtual void destroy( result_type obj ) + virtual void destroy( ResultType obj ) { delete obj; } @@ -269,7 +269,7 @@ /** Returns this->create(key). */ - result_type operator()( const key_type & key ) + ResultType operator()( const key_type & key ) { return this->internal( key ); } @@ -284,7 +284,7 @@ value_type. See the FactoryCreateHook class for a factory which does this subtype-to-base conversion. */ - void registerFactory( const key_type & key, factory_type fp ) + virtual void registerFactory( const key_type & key, factory_func_type fp ) { // CERR << "registerFactory("<<key<<",facfunc)\n"; factoryMap().insert( FactoryMap::value_type( key, fp ) ); @@ -342,6 +342,11 @@ template <typename InterfaceT> struct NamedTypeFactory : public Factory< InterfaceT, Sharing::FactoryContext, std::string > { + typedef Factory< InterfaceT, Sharing::FactoryContext, std::string > ParentType; + + typedef typename ParentType::ResultType ResultType; + typedef typename ParentType::factory_func_type factory_func_type; + virtual ~NamedTypeFactory(){} }; |
From: stephan b. <sg...@us...> - 2004-12-25 16:37:56
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31576/include/pclasses/Plugin Modified Files: Plugin.h Log Message: More tweaking of the interface. Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Plugin.h 25 Dec 2004 02:44:57 -0000 1.6 +++ Plugin.h 25 Dec 2004 16:37:47 -0000 1.7 @@ -16,50 +16,6 @@ namespace P { namespace Plugin { - - - /** - An internal helper type to clean up a list of pointers to - objects. - - ContainterT must be compatible with list<T *> - and calling 'delete Tobj' must be well-behaved. - */ - template <typename ContainterT> - struct PluginCleaner : public ::P::NonCopyable - { - typedef ContainterT ListType; - PluginCleaner() - { - } - - /** - Does nothing. - */ - ~PluginCleaner() throw() - { - // Reminder: System::openSharedLib() owns them! -// typename ListType::iterator it = m_list.begin(); -// while( m_list.end() != it ) -// { -// delete( (*it) ); -// ++it; -// } -// m_list.clear(); - } - - /** - Returns this object's container. - */ - ListType & container() - { - return this->m_list; - } - - private: - ListType m_list; - }; - /** @@ -81,6 +37,8 @@ typedef InterfaceT InterfaceType; typedef ::P::NamedTypeFactory< InterfaceT > ParentType; typedef PluginManager<InterfaceType> ThisType; + typedef typename ParentType::factory_func_type factory_func_type; + typedef typename ParentType::ResultType ResultType; /** Creates a PluginManager with a default search path @@ -93,21 +51,12 @@ } /** - When a PluginManager goes out of scope it deletes - all SharedLib objects it opened via - addPlugin(). The exact behaviour of this depends on - the platform-specific SharedLib implementation. It - is never safe to use symbols from a DLL once the - DLL has been closed, but it is also impossible for - us to track every single dll-registered - symbol. Thus the safest thing to do is never use - standlone PluginManager instances, and use the one - available via instance() instead. + Does nothing. */ virtual ~PluginManager() throw() { - // reminder: m_holder goes out of scope - // and cleans up it's container() now... + // reminder: openSharedLib() owns + // the objects in m_holder. } @@ -124,7 +73,7 @@ The caller owns the returned object, which may be 0. */ virtual - InterfaceType * create( const std::string & feature ) + ResultType create( const std::string & feature ) { InterfaceType * ret = ParentType::create( feature ); if( ret ) return ret; @@ -189,7 +138,7 @@ } ::P::System::SharedLib * shl = ::P::System::openSharedLib( fn ); //CERR << "Opened fn="<<fn<<"\n"; - this->m_holder.container().push_back( shl ); + this->m_holder.push_back( shl ); return shl; } @@ -240,12 +189,12 @@ */ PluginList & sharedLibs() { - return this->m_holder.container(); + return this->m_holder; } const PluginList & sharedLibs() const { - return this->m_holder.container(); + return this->m_holder; } /** @@ -267,7 +216,7 @@ this->m_path.addPath( PCLASSES_LIB_DIR ); this->m_path.addExtension(std::string(".")+std::string(PCLASSES_PLATFORM_SHARED_LIB_EXTENSION)); } - PluginCleaner<PluginList> m_holder; + PluginList m_holder; ::P::System::PathFinder m_path; // ^^^^ todo: consider making this static. }; |
From: stephan b. <sg...@us...> - 2004-12-25 16:04:39
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26827/include/pclasses/System Modified Files: File.h SharedLib.h Log Message: Added API docs. @Christian: Please grep them for @fixme notes! Index: SharedLib.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/SharedLib.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SharedLib.h 25 Dec 2004 07:02:16 -0000 1.6 +++ SharedLib.h 25 Dec 2004 16:04:21 -0000 1.7 @@ -40,7 +40,7 @@ The example below shows how to retrieve the address of the cos function in the math library: \code -SharedLib shl("libm"); +SharedLib shl("libm.so"); double (*cosine)(double); cosine = shl["cos"]; (*cosine)(2.0); @@ -81,9 +81,15 @@ returns a pointer to the symbol. \return the address of the symbol NULL if it was not found + + Throws if symbol is not found or if symbol itself is NULL. */ void* operator[](const char* symbol) throw(RuntimeError); + /** + Equivalent to the (const char *) version, provided for + convenience. Throws if symbol is empty. + */ void* operator[](const std::string& symbol) throw(RuntimeError); //! Returns the platform-specific shared lib extension Index: File.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/File.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- File.h 23 Dec 2004 05:56:09 -0000 1.3 +++ File.h 25 Dec 2004 16:04:21 -0000 1.4 @@ -24,54 +24,105 @@ #include <pclasses/Unicode/String.h> #include <pclasses/IO/IODevice.h> -#ifdef PCLASSES_WITH_STL -# include <string> -#endif +#include <string> namespace P { namespace System { +/** + File is a cross-platform abstraction for filesystem-based files. +*/ class File: public IO::IODevice { public: File() throw(); File(const File& f) throw(IO::IOError); + /** + Creates a file with the given name and access modes. Throws on error. + */ File(const Unicode::String& name, OpenMode omode, AccessMode amode, ShareMode smode) throw(IO::IOError); -#ifdef PCLASSES_WITH_STL + /** + Creates a file with the given name and access modes. Throws on error. + */ File(const std::string& name, OpenMode omode, AccessMode amode, ShareMode smode) throw(IO::IOError); -#endif ~File() throw(); + /** + */ void open(const Unicode::String& name, OpenMode omode, AccessMode amode, ShareMode smode) throw(LogicError, IO::IOError); -#ifdef PCLASSES_WITH_STL + /** + Opens this file. + + @fixme: does this reopen using the new name if open() an already-open()ed + File? + */ void open(const std::string& name, OpenMode omode, AccessMode amode, ShareMode smode) throw(LogicError, IO::IOError); -#endif + /** + Frees any resources associated with this object, like filehandles. + */ void close() throw(LogicError, IO::IOError); + /** + Reads up to count bytes and stores them in + buffer. Returns the number of bytes read. + */ size_t read(char* buffer, size_t count) throw(IO::IOError); + /** + Tries to extract up to count bytes from this object + without consuming them. The bytes are stored in + buffer, and the number of bytes read is returned. + + */ size_t peek(char* buffer, size_t count) throw(IO::IOError); + /** + Writes count bytes from buffer to this object's + internal representation. + */ size_t write(const char* buffer, size_t count) throw(IO::IOError); + /** + Tries to move the current read position to the given offset. + SeekMode determines the relative starting point of offset. + + */ offset_t seek(offset_t offset, SeekMode mode) throw(IO::IOError); + /** + Returns true if seek() is supported. + */ bool isSeekable() const throw(); + /** + @fixme: Same as conventional sync() functions??? + + */ void commit() const throw(IO::IOError); + /** + Returns the size of this File on disk. + */ offset_t size() const throw(IO::IOError); + /** + Copies f. + + @fixme: what are the semantics for copying the + read/write mode? Does copying a file this way + really make sense? If f is locked then this ctor + cannot succeed, right? + */ File& operator=(const File& f) throw(IO::IOError); private: |
From: stephan b. <sg...@us...> - 2004-12-25 16:03:02
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26508/src/System Modified Files: SharedLib.dl.cpp SharedLib.dyld.cpp SharedLib.generic.cpp SharedLib.shl.cpp SharedLib.win32.cpp Log Message: Added throw RuntimeError when operator[](const char *) is passed 0. Changed op[](string) to pass 0 to op[](char*) when string is empty, so that it inherits the platform-specific throw behaviour (string version is in SharedLib.generic.cpp). Index: SharedLib.dyld.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dyld.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SharedLib.dyld.cpp 25 Dec 2004 07:02:16 -0000 1.5 +++ SharedLib.dyld.cpp 25 Dec 2004 16:02:51 -0000 1.6 @@ -83,16 +83,21 @@ SharedLib::~SharedLib() throw() { - NSUnLinkModule((NSModule)_handle, NSUNLINKMODULE_OPTION_NONE); + NSUnLinkModule((NSModule)_handle, NSUNLINKMODULE_OPTION_NONE); } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { - NSSymbol addr = NSLookupSymbolInModule((NSModule)_handle, symbol); - if(!addr) + if( ! symbol ) + { + throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); + } + + NSSymbol addr = NSLookupSymbolInModule((NSModule)_handle, symbol); + if(!addr) throw RuntimeError("Symbol not found in shared library", P_SOURCEINFO); - return (void*)addr; + return (void*)addr; } const char* SharedLib::extension() Index: SharedLib.generic.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.generic.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- SharedLib.generic.cpp 25 Dec 2004 07:02:16 -0000 1.7 +++ SharedLib.generic.cpp 25 Dec 2004 16:02:51 -0000 1.8 @@ -11,7 +11,10 @@ void* SharedLib::operator[](const std::string& symbol) throw(RuntimeError) { - return operator[](symbol.c_str()); + return operator[](symbol.empty() ? 0 : symbol.c_str()); + // ^^^ the 0 is to force operator[const char*] to throw a + // runtime error. We don't throw it here because we want to + // inherit the platform-specific op[char*]'s throw behaviour. } /** Index: SharedLib.dl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dl.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- SharedLib.dl.cpp 25 Dec 2004 07:02:16 -0000 1.7 +++ SharedLib.dl.cpp 25 Dec 2004 16:02:51 -0000 1.8 @@ -129,6 +129,10 @@ void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { + if( ! symbol ) + { + throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); + } void* addr = dlsym((void*)_handle, symbol); if(!addr) throw RuntimeError("Symbol not found in shared library", P_SOURCEINFO); Index: SharedLib.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.win32.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SharedLib.win32.cpp 25 Dec 2004 07:02:16 -0000 1.5 +++ SharedLib.win32.cpp 25 Dec 2004 16:02:51 -0000 1.6 @@ -82,6 +82,10 @@ void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { + if( ! symbol ) + { + throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); + } void* addr = GetProcAddress((HMODULE)_handle, symbol); if(!addr) throw RuntimeError("Symbol not found in shared library", P_SOURCEINFO); Index: SharedLib.shl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.shl.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SharedLib.shl.cpp 25 Dec 2004 07:02:16 -0000 1.5 +++ SharedLib.shl.cpp 25 Dec 2004 16:02:51 -0000 1.6 @@ -104,6 +104,11 @@ void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { + if( ! symbol ) + { + throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); + } + void* address = 0; if(shl_findsym((shl_t*)&_handle, symbol, TYPE_UNDEFINED, (void*)&address)) != 0) throw RuntimeError("Symbol not found in shared library", P_SOURCEINFO); |
From: Christian P. <cp...@us...> - 2004-12-25 07:06:14
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20327/src/System Modified Files: SharedLibCache.h Log Message: Added missing include Index: SharedLibCache.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLibCache.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SharedLibCache.h 25 Dec 2004 07:02:16 -0000 1.1 +++ SharedLibCache.h 25 Dec 2004 07:05:59 -0000 1.2 @@ -22,6 +22,7 @@ #define P_System_SharedLibCache_h #include "pclasses/Phoenix.h" +#include "pclasses/System/CriticalSection.h" #include <map> #include <string> |
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19443/src/System Modified Files: SharedLib.dl.cpp SharedLib.dyld.cpp SharedLib.generic.cpp SharedLib.ltdl.cpp SharedLib.shl.cpp SharedLib.win32.cpp Added Files: SharedLibCache.h Log Message: Added SharedLibCache to dl, shl, win32 impls. Added SharedLib::extension() --- NEW FILE: SharedLibCache.h --- /*************************************************************************** * 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. * ***************************************************************************/ #ifndef P_System_SharedLibCache_h #define P_System_SharedLibCache_h #include "pclasses/Phoenix.h" #include <map> #include <string> namespace P { namespace System { // Shared library handle cache template <typename destroyF> struct SharedLibCache { typedef std::map<std::string, unsigned long> map_t; enum { InvalidHandle = (unsigned long)-1 }; SharedLibCache() { } ~SharedLibCache() { destroyF fun; typename map_t::iterator it = _handles.begin(); while(_handles.end() != it) { fun(it->second); ++it; } _handles.clear(); } void add(const std::string& name, unsigned long handle) { map_t::iterator i = _handles.find(name); if(i == _handles.end()) _handles[name] = handle; } unsigned long lookup(const std::string& name) const { map_t::const_iterator i = _handles.find(name); if(i == _handles.end()) return InvalidHandle; return i->second; } CriticalSection mutex; private: map_t _handles; }; /** Internal marker type. */ struct cached_libs_context {}; template <typename destroyF> SharedLibCache<destroyF> & shared_lib_cache() { return ::P::Phoenix< SharedLibCache<destroyF>, cached_libs_context> ::instance(); } } // !namespace System } // !namespace P #endif Index: SharedLib.dl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dl.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SharedLib.dl.cpp 24 Dec 2004 23:03:40 -0000 1.6 +++ SharedLib.dl.cpp 25 Dec 2004 07:02:16 -0000 1.7 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/System/SharedLib.h" +#include "SharedLibCache.h" #include <dlfcn.h> #include <errno.h> @@ -36,6 +37,16 @@ } int libdl_init_placeholder = (libdl_init(),0); +struct SharedLibCloser +{ + void operator()(unsigned long handle) + { + dlclose((void*)handle); + } +}; + +typedef SharedLibCache<SharedLibCloser> Cache; + int BindMode2Flags(SharedLib::BindMode mode) { int flags = 0; @@ -66,9 +77,24 @@ SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) { - _handle = (unsigned long)dlopen(name.c_str(), BindMode2Flags(mode)); - if(!_handle) - throw SystemError(errno, dlerror(), P_SOURCEINFO); + Cache& cache = shared_lib_cache<SharedLibCloser>(); + CriticalSection::ScopedLock lck(cache.mutex); + + // se if we can get it from the handle cache ... + unsigned long handle = cache.lookup(name); + if(handle == Cache::InvalidHandle) + { + _handle = (unsigned long)dlopen(name.c_str(), BindMode2Flags(mode)); + if(!_handle) + throw SystemError(errno, dlerror(), P_SOURCEINFO); + + // add it to the handle cache + cache.add(name, _handle); + } + else + { + _handle = handle; + } } SharedLib::~SharedLib() throw() @@ -110,6 +136,12 @@ return addr; } +const char* SharedLib::extension() +{ + static const char* ext = "so"; + return ext; +} + } // !namespace System } // !namespace P Index: SharedLib.generic.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.generic.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SharedLib.generic.cpp 25 Dec 2004 02:44:05 -0000 1.6 +++ SharedLib.generic.cpp 25 Dec 2004 07:02:16 -0000 1.7 @@ -83,5 +83,6 @@ return sh; } +} // !namespace System -} } // namespace P::System +} // !namespace P Index: SharedLib.dyld.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dyld.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SharedLib.dyld.cpp 25 Dec 2004 00:21:13 -0000 1.4 +++ SharedLib.dyld.cpp 25 Dec 2004 07:02:16 -0000 1.5 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/System/Sharedlib.h" +#include "SharedLibCache.h" #include <mach-o/dyld.h> @@ -94,6 +95,11 @@ return (void*)addr; } +const char* SharedLib::extension() +{ + static const char* ext = "dyld"; + return ext; +} } // !namespace System Index: SharedLib.ltdl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.ltdl.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SharedLib.ltdl.cpp 25 Dec 2004 00:11:49 -0000 1.4 +++ SharedLib.ltdl.cpp 25 Dec 2004 07:02:16 -0000 1.5 @@ -127,6 +127,13 @@ return addr; } +const char* SharedLib::extension() +{ + static const char* ext = "so"; + /*@fixme .. as far as i know libltdl is a sharedlib api abstraction lib, + where to get the default lib extension? */ + return ext; +} } // !namespace System Index: SharedLib.shl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.shl.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SharedLib.shl.cpp 25 Dec 2004 00:21:13 -0000 1.4 +++ SharedLib.shl.cpp 25 Dec 2004 07:02:16 -0000 1.5 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/System/SharedLib.h" +#include "SharedLibCache.h" #include <dl.h> #include <errno.h> @@ -30,6 +31,16 @@ namespace System { +struct SharedLibCloser +{ + void operator()(unsigned long handle) + { + shl_unload((shl_t*)handle); + } +}; + +typedef SharedLibCache<SharedLibCloser> Cache; + int BindMode2Flags(SharedLib::BindMode mode) { int flags = 0; @@ -64,18 +75,31 @@ // std::ostringstream realName; // realName << name; // realName << ".sl"; + Cache& cache = shared_lib_cache<SharedLibCloser>(); + CriticalSection::ScopedLock lck(cache.mutex); - _handle = (unsigned long)shl_load(name.str().c_str(), - BindMode2Flags(mode)); + // se if we have the handle cached ... + unsigned long handle = cache.lookup(name); + if(handle == Cache::InvalidHandle) + { + _handle = (unsigned long)shl_load(name.str().c_str(), + BindMode2Flags(mode)); - //@fixme dlerror() on hpux ?? - if(!_handle) - throw SystemError(errno, dlerror(), P_SOURCEINFO); + //@fixme dlerror() on hpux ?? + if(!_handle) + throw SystemError(errno, dlerror(), P_SOURCEINFO); + + // add the handle to the cache + cache.add(name, _handle); + } + else + { + _handle = handle; + } } SharedLib::~SharedLib() throw() { - shl_unload((shl_t*)_handle); } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) @@ -87,6 +111,12 @@ return address; } +const char* SharedLib::extension() +{ + static const char* ext = "sl"; + return ext; +} + } // !namespace System } // !namespace P Index: SharedLib.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.win32.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SharedLib.win32.cpp 25 Dec 2004 00:21:13 -0000 1.4 +++ SharedLib.win32.cpp 25 Dec 2004 07:02:16 -0000 1.5 @@ -19,6 +19,8 @@ ***************************************************************************/ #include "pclasses/System/SharedLib.h" +#include "SharedLibCache.h" + #include <windows.h> #include <string> @@ -28,6 +30,16 @@ namespace System { +struct SharedLibCloser +{ + void operator()(unsigned long handle) + { + FreeLibrary((HMODULE)handle); + } +}; + +typedef SharedLibCache<SharedLibCloser> Cache; + SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) { // Unicode::String realName = name; @@ -44,15 +56,28 @@ // realName << name; // realName << ".dll"; - _handle = (unsigned long)LoadLibrary(name.c_str()); + Cache& cache = shared_lib_cache<SharedLibCloser>(); + CriticalSection::ScopedLock lck(cache.mutex); - if(!_handle) - throw SystemError(GetLastError(), "Could not load shared library", P_SOURCEINFO); + // se if we can get it from the handle cache ... + unsigned long handle = cache.lookup(name); + if(handle == Cache::InvalidHandle) + { + _handle = (unsigned long)LoadLibrary(name.c_str()); + if(!_handle) + throw SystemError(GetLastError(), "Could not load shared library", P_SOURCEINFO); + + // add the handle to the cache + cache.add(name, _handle); + } + else + { + _handle = handle; + } } SharedLib::~SharedLib() throw() { - FreeLibrary((HMODULE)_handle); } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) @@ -64,6 +89,12 @@ return addr; } +const char* SharedLib::extension() +{ + static const char* ext = "dll"; + return ext; +} + } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2004-12-25 07:02:34
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19443/include/pclasses/System Modified Files: SharedLib.h Log Message: Added SharedLibCache to dl, shl, win32 impls. Added SharedLib::extension() Index: SharedLib.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/SharedLib.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SharedLib.h 24 Dec 2004 19:17:45 -0000 1.5 +++ SharedLib.h 25 Dec 2004 07:02:16 -0000 1.6 @@ -86,15 +86,13 @@ void* operator[](const std::string& symbol) throw(RuntimeError); - // TODO: - // static std::string sharedLibExtension(); - // returns "so", "dll", etc. + //! Returns the platform-specific shared lib extension + static const char* extension(); private: - unsigned long _handle; + unsigned long _handle; }; -#ifdef PCLASSES_WITH_STL /** Simply opens the given DLL name, using the platform-specific SharedLib handler. @@ -103,8 +101,7 @@ by this function and will be cleaned up during application shut-down (post-main()). */ - SharedLib * openSharedLib( const std::string & path ) throw(RuntimeError); -#endif // PCLASSES_WITH_STL +SharedLib *openSharedLib( const std::string & path ) throw(RuntimeError); } // !namespace System |
From: stephan b. <sg...@us...> - 2004-12-25 02:45:57
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13361/include/pclasses Modified Files: Factory.h Log Message: Doc additions and naming convention corrections. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Factory.h 25 Dec 2004 01:45:14 -0000 1.8 +++ Factory.h 25 Dec 2004 02:45:48 -0000 1.9 @@ -170,15 +170,17 @@ foo = fac.create( "my_key" ); // == a new MyClass object </pre> - Note that all instantiators of the same type use the same - object factories. The ContextType template parameter can be - used to limit the scope of the object factory registrations - to a specific context: Factories with different Contexts - use different maps. ContextType is only used as a marker type, - and is never instantiated by this class. + Note that all instantiations of the same Factory type use + the same object factories map. The ContextType template + parameter can be used to limit the scope of a + Factory<InterfaceT>, such that it it does not collide with + other Factory<InterfaceT> instantiations. ContextType is + only used as a marker type, and is never instantiated by + this class. Used cleverly, it can allow you quite a bit + of freedome in what code has access to which factories. */ template < class InterfaceT, - class ContextType = Sharing::FactoryContext, + class ContextT = Sharing::FactoryContext, class KeyType = std::string > class Factory @@ -202,7 +204,7 @@ typedef KeyType key_type; /** Same as ContextType */ - typedef ContextType context_type; + typedef ContextT ContextType; /** Convenience typedef. @@ -297,10 +299,14 @@ It is safe to call this post-main(), but such calls may return an empty map! + + TODO: use a Hook or Traits type to allow the user + to replace this object with his own, so that he can + control the scope of the map more fully. */ static FactoryMap & factoryMap() { - return Phoenix<FactoryMap,context_type>::instance(); + return Phoenix<FactoryMap,ContextType>::instance(); } /** |
From: stephan b. <sg...@us...> - 2004-12-25 02:45:06
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13162/include/pclasses/Plugin Modified Files: Plugin.h Log Message: Removed the deletion of SharedLibs at shutdown - they are owned by System::openSharedLib(). Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Plugin.h 25 Dec 2004 01:46:04 -0000 1.5 +++ Plugin.h 25 Dec 2004 02:44:57 -0000 1.6 @@ -34,17 +34,18 @@ } /** - Calls delete() on each entry in container(). + Does nothing. */ ~PluginCleaner() throw() { - typename ListType::iterator it = m_list.begin(); - while( m_list.end() != it ) - { - delete( (*it) ); - ++it; - } - m_list.clear(); + // Reminder: System::openSharedLib() owns them! +// typename ListType::iterator it = m_list.begin(); +// while( m_list.end() != it ) +// { +// delete( (*it) ); +// ++it; +// } +// m_list.clear(); } /** @@ -247,6 +248,11 @@ return this->m_holder.container(); } + /** + Searches for name using this object's searchPath(). + Returns a path to a plugin file on success or + an empty string on error. + */ std::string findPlugin( const std::string & name ) const { return this->searchPath().find( name ); @@ -294,6 +300,9 @@ return pluginManager<T>().addPlugin( pluginname ); } + /** + Convenience function to call pluginManager<T>().findPlugin(name). + */ template <typename T> std::string findPlugin( const std::string & name ) { |
From: stephan b. <sg...@us...> - 2004-12-25 02:44:13
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13019/src/System Modified Files: SharedLib.generic.cpp Log Message: Re-added delete() on the libs at shutdown - i found the double-deletion culprit (PluginManager). Index: SharedLib.generic.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.generic.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SharedLib.generic.cpp 24 Dec 2004 23:02:43 -0000 1.5 +++ SharedLib.generic.cpp 25 Dec 2004 02:44:05 -0000 1.6 @@ -36,10 +36,7 @@ typename list_t::iterator it = m_list.begin(); while( m_list.end() != it ) { - // weird: deleting these - // causes a double-delete error - // from glibc - // delete( (*it) ); + delete( (*it) ); ++it; } m_list.clear(); |
From: stephan b. <sg...@us...> - 2004-12-25 02:38:49
|
Update of /cvsroot/pclasses/pclasses2/doc/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11970 Modified Files: pclasses2.lyx Log Message: Added basic Factory and Plugin docs. Index: pclasses2.lyx =================================================================== RCS file: /cvsroot/pclasses/pclasses2/doc/manual/pclasses2.lyx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pclasses2.lyx 24 Dec 2004 01:03:01 -0000 1.2 +++ pclasses2.lyx 25 Dec 2004 02:38:39 -0000 1.3 @@ -21,8 +21,8 @@ \headheight 2cm \headsep 1cm \footskip 1cm -\secnumdepth 3 -\tocdepth 3 +\secnumdepth 5 +\tocdepth 4 \paragraph_separation skip \defskip medskip \quotes_language swedish @@ -299,13 +299,135 @@ Phoenix \layout Standard -A shared object provider. +A shared object provider, providing +\begin_inset Quotes sld +\end_inset + +phoenixing +\begin_inset Quotes srd +\end_inset + + behaviour on served objects. +\layout Standard + +i can't bear to type all of this again. + See the huge amount of documentation in the API docs and at: +\layout Itemize + +http://s11n.net/phoenix/ +\layout Itemize + +The +\begin_inset Quotes sld +\end_inset + +Context Singletons +\begin_inset Quotes srd +\end_inset + + paper at http://s11n.net/papers/ - that paper is where Phoenix was born. +\layout Standard + + +\series bold +Achtung +\series default +: the Phoenix interface may be changed later to include Mutex/CriticalSection + support. \layout Subsection Factory \layout Standard -Object factory interface. +The Factory template type plays a major role in P, providing the interface + for key-based lookup of object factories. + What does that mean? It means the ability to dynamically load classes. +\layout Subsubsection + +Registration +\layout Standard + +To be loadable from Factory a type must register with the appropriate Factory. + All Factories parameterized on the same types share the same factories. + For the following examples we will assume Factory<MyType> is our Factory + type. +\layout Standard + +There are several approaches to registering MyType (and it's subtypes) with + Factory<MyType>. + Here are some of the options: +\layout Paragraph + +Supermacro +\layout Standard + +Simply do the following: +\layout Quote + +#define PFACREG_TYPE MyType +\layout Quote + +#define PFACREG_TYPE_NAME +\begin_inset Quotes sld +\end_inset + +MyType +\begin_inset Quotes srd +\end_inset + + +\layout Quote + +#include <pclasses/FactoryReg.h> +\layout Standard + +This should preferably (for linking reasons) be in MyType's header, but + it may actually be done in any number of places, including MyType's implementat +ion file or a completely separate file which is linked in to your app or + a DLL. +\layout Standard + +The FactorReg.h supermacro takes several options: +\layout Itemize + +PFACREG_TYPE = the type you want to register. +\layout Itemize + +PFACREG_TYPE_NAME = the string form of the name to use for classloading. +\layout Itemize + +PFACREG_TYPE_INTERFACE = dubtypes of MyType should define this to MyType, + so that they get registered with the proper base classloader. +\layout Itemize + +PFACREG_TYPE_IS_ABSTRACT = define this to any value if PFACREG_TYPE is abstract. + This installs a no-op factory for it. +\layout Itemize + +PFACREG_CONTEXT = the factory context. + Don't set this unless you really, really know what you're doing. +\layout Paragraph + +Factory::registerFactory() +\layout Standard + +Factory::registerFactory() maps a class name to a factory. + See the class P::Hook::FactoryCreateHook for a class which provides simple + factory functions. +\layout Standard + +It is common to call registerFactory() from global-scope initialization + code which gets activated during the static init phase of the code (pre-main() + or as a DLL is opened). + See +\family typewriter +<pclasses/FactoryReg.h> +\family default + or +\family typewriter +/srctree/test/CType.cpp +\family default + for examples. \layout Subsection Signals and Slots @@ -344,14 +466,38 @@ Plugin Module \layout Standard -The types in this section all live in the namespace -\color red -P::??? -\color default -. +The types in this section all live in the namespace P::Plugin. \layout Standard -The Plugin module provides per-protocol, per-mime-type dynamic object loading. +The Plugin module is an extension of the basic Factory support, extending + Factory to allow loading new types from DLLs. +\layout Subsection + +Helpful free functions +\layout Standard + +The following functions, all defined in namespace P::Plugin, all operate + on PluginManager<T>::instance(). +\layout Itemize + +pluginManager<T>() returns PluginManager<T>::instance(). +\layout Itemize + +addPluginDir<T>(string) adds a plugin dir. +\layout Itemize + +addPlugin<T>( string ) loads the given plugin. +\layout Itemize + +findPlugin<T>( string ) tries to locate a DLL for the given string, returning + the path on success. +\layout Standard + +Note that addXXX() throw exceptions on errors. + This decision is under consideration, and it is possible that these functions + will be changed to never throw, for ease of client use. + Those who always want throwing behaviour may use PluginManager<T>'s API + directly. \layout Section System Module @@ -363,23 +509,19 @@ Filesystems \layout Subsubsection -File ( -\color red -FSFile, for consistency? -\color default -) +File \layout Standard Encapsulates a filesystem file. \layout Subsubsection -FSDirectory +Directory \layout Standard Encapsulates a filesystem directory. \layout Subsubsection -FSPath +Path \layout Standard Encapsulates a filesystem path. |
From: stephan b. <sg...@us...> - 2004-12-25 01:58:00
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5077 Modified Files: configure.pclasses2 Log Message: Added PCLASSES_PLATFORM_SHARED_LIB_EXTENSION (e.g. "dll" or "so"). Index: configure.pclasses2 =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.pclasses2,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- configure.pclasses2 25 Dec 2004 00:10:15 -0000 1.8 +++ configure.pclasses2 25 Dec 2004 01:57:50 -0000 1.9 @@ -144,6 +144,9 @@ toc_export PACKAGE_LICENSE="GNU LGPL" + +toc_export PCLASSES_PLATFORM_SHARED_LIB_EXTENSION="so" # TODO: change by platform + ######################################################################## # removeDupes is a helper app to remove duplicate entries from linker/ # includes arguments. |
From: stephan b. <sg...@us...> - 2004-12-25 01:57:20
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4987/test Modified Files: CType.cpp FactoryTest.cpp FactoryTest.h Log Message: Accomodated changes in Factory. Index: FactoryTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- FactoryTest.cpp 24 Dec 2004 23:26:40 -0000 1.5 +++ FactoryTest.cpp 25 Dec 2004 01:57:09 -0000 1.6 @@ -21,38 +21,51 @@ TheBase * a = 0; -#define CLOAD(CN) a = P::NamedTypeFactory<TheBase>::instance().create( CN ); \ - CERR << CN << " classload()ed? == " << a << "\n"; \ +#define CLOAD(CN) a = P::CL::classload<TheBase>( CN ); \ + CERR << CN << " classload("<<CN<<")ed? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; - /************************* -Can't test until linking the libpclasses_xxx works. - *************************/ - typedef P::Plugin::PluginManager<TheBase> PM; + typedef P::NamedTypeFactory<TheBase> NTF; +#define NTLOAD(CN) a = NTF::instance().create( CN ); \ + CERR << CN << " NamedTypeFactory::create("<<CN<<")ed? == " << a << "\n"; \ + if( a ) CERR << "classname="<<a->classname()<<"\n"; \ + delete( a ); a = 0; - PM & pm = PM::instance(); -#define PLOAD(CN) a = pm.create( CN ); \ - CERR << CN << " plugin-create()ed? == " << a << "\n"; \ + typedef P::Plugin::PluginManager<TheBase> PM; + +#define PLOAD(CN) a = PM::instance().create( CN ); \ + CERR << CN << " PluginManager::create("<<CN<<")ed? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; -#define LOAD(CN) CLOAD(CN); PLOAD(CN); +#define LOAD(CN) NTLOAD(CN); CLOAD(CN); +#if 0 try { - ::P::System::SharedLib * sh = pm.addPlugin( "CType" ); - CERR << "CType lib = " << sh << "\n"; - // throw P::Exception( "Foo!", P_SOURCEINFO ); + std::string sofile = pm.findPlugin( "CType" ); + CERR << "sofile="<<sofile<<"\n"; + if( sofile.empty() ) + { + throw P::Exception( "Plugin not found!", P_SOURCEINFO ); + } + ::P::System::SharedLib * sh = 0; + sh = pm.addPlugin( sofile ); + // sh = ::P::Plugin::addPlugin<TheBase>( "CType" ); + CERR << "plugged in lib: " << sh << "\n"; + CERR << "Symbol lookup test: " << (*sh)["new_CType"] << "\n"; + //throw P::Exception( "Foo!", P_SOURCEINFO ); } catch( const ::P::Exception & ex ) { - CERR << "Exception:\n"<<ex.where()<<"\n"<<ex.what()<<"\n"; + CERR << "Exception:\n"<<ex.what()<<"\n"<<ex.where()<<"\n"; } +#endif + LOAD("DefaultDocumentType"); LOAD("CType"); - LOAD("XtraType"); LOAD("TheBase"); LOAD("AType"); LOAD("BType"); Index: FactoryTest.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FactoryTest.h 24 Dec 2004 23:25:55 -0000 1.1 +++ FactoryTest.h 25 Dec 2004 01:57:09 -0000 1.2 @@ -20,6 +20,45 @@ virtual std::string classname() const = 0; }; +struct AType : public TheBase +{ + AType() + { + CERR << "AType()\n"; + } + virtual ~AType() + { + CERR << "~AType()\n"; + } + + virtual std::string classname() const { return "AType"; } + +}; + + + +#define PFACREG_TYPE AType +#define PFACREG_TYPE_INTERFACE TheBase +// #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType +#define PFACREG_TYPE_NAME "AType" +#include <pclasses/FactoryReg.h> + +struct BType : public AType +{ + BType() + { + CERR << "BType()\n"; + } + virtual ~BType() + { + CERR << "~BType()\n"; + } + virtual std::string classname() const { return "BType"; } +}; +#define PFACREG_TYPE BType +#define PFACREG_TYPE_INTERFACE TheBase +#define PFACREG_TYPE_NAME "BType" +#include <pclasses/FactoryReg.h> #endif // ptest_FACTORYTEST_HPP_INCLUDED Index: CType.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/CType.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CType.cpp 24 Dec 2004 23:25:55 -0000 1.1 +++ CType.cpp 25 Dec 2004 01:57:09 -0000 1.2 @@ -1,44 +1,6 @@ #include "FactoryTest.h" -struct AType : public TheBase -{ - AType() - { - CERR << "AType()\n"; - } - virtual ~AType() - { - CERR << "~AType()\n"; - } - - virtual std::string classname() const { return "AType"; } - -}; - -struct BType : public AType -{ - BType() - { - CERR << "BType()\n"; - } - virtual ~BType() - { - CERR << "~BType()\n"; - } - virtual std::string classname() const { return "BType"; } -}; - - -#define PFACREG_TYPE AType -#define PFACREG_TYPE_INTERFACE TheBase -// #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType -#define PFACREG_TYPE_NAME "AType" -#include <pclasses/FactoryReg.h> -#define PFACREG_TYPE BType -#define PFACREG_TYPE_INTERFACE TheBase -#define PFACREG_TYPE_NAME "BType" -#include <pclasses/FactoryReg.h> struct CType : public BType { @@ -54,15 +16,17 @@ }; -TheBase * new_CType() -{ - return new CType; +extern "C" { + TheBase * new_CType() + { + return new CType; + } } void CType_bogo_init() { CERR << "CType_bogo_init()\n"; - ::P::NamedTypeFactory<TheBase>::instance().registerFactory( "XtraType", new_CType ); + ::P::NamedTypeFactory<TheBase>::instance().registerFactory( "DefaultDocumentType", new_CType ); } int CType_bogo_init_placeholder = ( CType_bogo_init(), 0 ); |
From: stephan b. <sg...@us...> - 2004-12-25 01:55:55
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4763/include/pclasses Modified Files: pclasses-config.h.at Log Message: Added PCLASSES_PLATFORM_SHARED_LIB_EXTENSION (e.g. "dll" or "so"). Index: pclasses-config.h.at =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/pclasses-config.h.at,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pclasses-config.h.at 24 Dec 2004 19:16:19 -0000 1.4 +++ pclasses-config.h.at 25 Dec 2004 01:55:46 -0000 1.5 @@ -9,6 +9,7 @@ # undef _ALL_SOURCE #endif +#define PCLASSES_PLATFORM_SHARED_LIB_EXTENSION "@PCLASSES_PLATFORM_SHARED_LIB_EXTENSION@" #define PCLASSES_INSTALL_PREFIX "@prefix@" #define PCLASSES_LIB_DIR "@prefix@/lib" #define PCLASSES_SHARED_DATA_DIR "@prefix@/share/pclasses" |
From: stephan b. <sg...@us...> - 2004-12-25 01:46:14
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3409/include/pclasses/Plugin Modified Files: Plugin.h Log Message: Added an experimental FactoryInstanceHook partial specialization which adds DLL-lookup support to the default Factory::instance()es. Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Plugin.h 25 Dec 2004 01:08:58 -0000 1.4 +++ Plugin.h 25 Dec 2004 01:46:04 -0000 1.5 @@ -14,7 +14,8 @@ #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " #endif -namespace P { namespace Plugin { +namespace P { +namespace Plugin { /** @@ -65,7 +66,7 @@ provide a platform-neutral Plugin interface. Note that it inherits a "context type" from NamedTypeFactory, - and shares factory maps with Factory<InterfaceT,string,ContextT>. + and shares factory maps with Factory<InterfaceT,ContextT,string>. The main implication of this is that one a PluginManager loads a plugin it may enable lower-level Factory objects to load types the plugin just loaded. @@ -108,6 +109,41 @@ // and cleans up it's container() now... } + + /** + Reimplemented to do DLL lookups. + + If a factory for feature is found then it is called + and the result is returned. If one is not found, we + look for a plugin via findPlugin( feature ). If + that finds a plugin, we open it and look again for + a factory for feature. If found, it is called, + otherwise we give up. + + The caller owns the returned object, which may be 0. + */ + virtual + InterfaceType * create( const std::string & feature ) + { + InterfaceType * ret = ParentType::create( feature ); + if( ret ) return ret; + std::string dll = this->findPlugin( feature ); + if( dll.empty() ) + { + return 0; + } + try + { + this->addPlugin( dll ); + ret = ParentType::create( feature ); + } + catch(...) + { + return 0; + } + return ret; + } + /** Adds dir to the lib search path. @@ -218,9 +254,6 @@ private: -// PluginManager( const ThisType & ); // not impl. -// ThisType & operator=( const ThisType & ); // not impl. - void init() { this->m_path.addPath( "." ); @@ -268,7 +301,44 @@ } -} } // namespace P:: Plugin +} // namespace Plugin + + +namespace Hook +{ + /** + This hook will cause calls to Factory::instance() to return + a PluginManager instance in disguise. Doing so enables DLL + lookups in the core without it knowing so. :) + */ + template < typename InterfaceT > + struct FactoryInstanceHook< ::P::Factory< InterfaceT, ::P::Sharing::FactoryContext, std::string > > + { + typedef ::P::Factory< InterfaceT, ::P::Sharing::FactoryContext, std::string > FactoryType; + typedef ::P::Plugin::PluginManager< InterfaceT > RealFactoryType; + typedef FactoryInstanceHook<FactoryType> ThisType; + + /** + */ + void operator()( FactoryType & ) throw() + { + CERR << "Initializing a PluginManager instance() we hacked in via FactoryInstanceHook!\n"; + } + + /** + The default implementation returns a shared Factory object. + THIS type's operator() will be called on the factory immediately + after creating the factory. + */ + static FactoryType & instance() + { + typedef ::P::Phoenix<RealFactoryType, ::P::Sharing::FactoryContext, ThisType > PHX; + return PHX::instance(); + } + }; + +} // ns Hook +} // namespace P #endif // p_PLUGIN_HPP_INCLUDED |
From: stephan b. <sg...@us...> - 2004-12-25 01:45:27
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3260/include/pclasses Modified Files: Factory.h FactoryReg.h Log Message: Swapped the 2nd and 3rd template args, because usage suggests that the ContextType is used more often than the KeyType. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Factory.h 24 Dec 2004 19:16:54 -0000 1.7 +++ Factory.h 25 Dec 2004 01:45:14 -0000 1.8 @@ -9,14 +9,12 @@ #include <functional> #include <pclasses/Phoenix.h> // i don't like this dep, but i also don't like + // what happens in some cases when i don't use + // phoenix. :/ #include <pclasses/SharingContext.h> -// what happens in some cases when i don't use -// phoenix. :/ namespace P { - - /** The Hook namespace holds classes intended to be used to allow client-side code to hook in to the framework's @@ -40,8 +38,10 @@ </pre> Clients may freely specialize this type to hook their - factories in to P, and the above requirement may not be - imposed by client-side specializations. + factories in to P, and the above 'new' requirement need + not be imposed by client-side specializations. For example, + specializations are used to provide no-op factories for + abstract types, where 'new T' cannot work. */ template < class T, class SubT > @@ -80,7 +80,7 @@ /** Same as create(). */ - result_type operator()() const + result_type operator()() { return create(); } @@ -155,7 +155,8 @@ Both InterfaceT and KeyType must be Default Constructable, and InterfaceT must be constructable on the heap - (e.g., via new InterfaceT()). + (e.g., via new InterfaceT()). Thus InterfaceT must not be + pointer-qualified. The default ipmlementation holds no per-instance state, thus it can be copied quickly. @@ -177,8 +178,8 @@ and is never instantiated by this class. */ template < class InterfaceT, - class KeyType = std::string, - class ContextType = Sharing::FactoryContext + class ContextType = Sharing::FactoryContext, + class KeyType = std::string > class Factory { @@ -206,7 +207,7 @@ /** Convenience typedef. */ - typedef Factory< InterfaceT, KeyType, ContextType > ThisType; + typedef Factory< InterfaceT, ContextType, KeyType > ThisType; Factory() {} @@ -283,6 +284,7 @@ */ void registerFactory( const key_type & key, factory_type fp ) { + // CERR << "registerFactory("<<key<<",facfunc)\n"; factoryMap().insert( FactoryMap::value_type( key, fp ) ); } @@ -314,14 +316,11 @@ /** Returns a shared reference to a Factory. - - Client code may plug in a new default instance() by - specializing Hook::FactoryInstanceHook< FactoryT >. See - that type for details. + */ static Factory & instance() { - return Hook::FactoryInstanceHook<ThisType>::instance(); + return Hook::FactoryInstanceHook<ThisType>::instance(); } @@ -335,7 +334,7 @@ practice (but sometimes very useful). */ template <typename InterfaceT> - struct NamedTypeFactory : public Factory< InterfaceT, std::string, Sharing::FactoryContext > + struct NamedTypeFactory : public Factory< InterfaceT, Sharing::FactoryContext, std::string > { virtual ~NamedTypeFactory(){} }; Index: FactoryReg.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/FactoryReg.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- FactoryReg.h 24 Dec 2004 21:17:35 -0000 1.2 +++ FactoryReg.h 25 Dec 2004 01:45:14 -0000 1.3 @@ -79,7 +79,7 @@ # endif // !p_FACTORY_REG_CONTEXT_DEFINED # define FACTORY_FUNCTION_ ::P::Hook::FactoryCreateHook< PFACREG_TYPE_INTERFACE , PFACREG_TYPE >::create -# define FACTORY_INSTANCE_ ::P::Factory< PFACREG_TYPE_INTERFACE, std::string, PFACREG_CONTEXT >::instance() +# define FACTORY_INSTANCE_ ::P::Factory< PFACREG_TYPE_INTERFACE, PFACREG_CONTEXT, std::string >::instance() //////////////////////////////////////////////////////////////////////// // Register a factory with the classloader: bool pfactory_reg_context< PFACREG_TYPE >::placeholder= ( |
From: stephan b. <sg...@us...> - 2004-12-25 01:09:08
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29665/include/pclasses/Plugin Modified Files: Plugin.h Log Message: Added findPlugin(), a no-throw way to check if a plugin dll exists before trying to addPlugin() it. Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Plugin.h 25 Dec 2004 00:07:30 -0000 1.3 +++ Plugin.h 25 Dec 2004 01:08:58 -0000 1.4 @@ -211,6 +211,12 @@ return this->m_holder.container(); } + std::string findPlugin( const std::string & name ) const + { + return this->searchPath().find( name ); + } + + private: // PluginManager( const ThisType & ); // not impl. // ThisType & operator=( const ThisType & ); // not impl. @@ -220,11 +226,7 @@ this->m_path.addPath( "." ); this->m_path.addPath( PCLASSES_PLUGINS_DIR ); this->m_path.addPath( PCLASSES_LIB_DIR ); -#ifdef __WIN32__ - this->m_path.addExtension( ".dll" ); -#else - this->m_path.addExtension( ".so" ); -#endif + this->m_path.addExtension(std::string(".")+std::string(PCLASSES_PLATFORM_SHARED_LIB_EXTENSION)); } PluginCleaner<PluginList> m_holder; ::P::System::PathFinder m_path; @@ -259,6 +261,12 @@ return pluginManager<T>().addPlugin( pluginname ); } + template <typename T> + std::string findPlugin( const std::string & name ) + { + return pluginManager<T>().findPlugin( name ); + } + } } // namespace P:: Plugin |
From: stephan b. <sg...@us...> - 2004-12-25 01:04:01
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28919/include/pclasses/Util Modified Files: Makefile.toc Log Message: Corrected install path. Added LexT. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/Makefile.toc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.toc 24 Dec 2004 04:52:04 -0000 1.2 +++ Makefile.toc 25 Dec 2004 01:03:52 -0000 1.3 @@ -1,21 +1,15 @@ #!/usr/bin/make -f -################################################### -# AUTO-GENERATED guess at a toc-aware Makefile, -# based off of the contents of directory: -# ./include/pclasses/Util -# Created by ./toc/bin/create_makefile_stubs.sh -# Thu Dec 23 01:31:56 CET 2004 -# It must be tweaked to suit your needs. -################################################### + include toc.make -############## FLEXES: -HEADERS = ManagedThread.h \ +HEADERS = \ + LexT.h \ + ManagedThread.h \ ThreadPool.h \ WorkQueue.h + DIST_FILES += $(HEADERS) + INSTALL_PACKAGE_HEADERS += $(HEADERS) +INSTALL_PACKAGE_HEADERS_DEST = $(INSTALL_PACKAGE_HEADERS_BASE)/Util all: -################################################### -# end auto-generated rules -################################################### |