From: Christian P. <cp...@us...> - 2005-04-28 10:35:48
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3559/include/pclasses/Plugin Modified Files: Plugin.h Log Message: - Use new tracing macro Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Plugin.h 31 Jan 2005 11:21:11 -0000 1.15 +++ Plugin.h 28 Apr 2005 10:35:40 -0000 1.16 @@ -4,16 +4,14 @@ #include <list> #include <string> #include <map> -#include "pclasses/pclasses-config.h" -#include "pclasses/Factory.h" -#include "pclasses/NonCopyable.h" -#include "pclasses/System/SharedLib.h" -#include "pclasses/System/PathFinder.h" -#include "pclasses/System/Directory.h" - -#ifndef CERR -#define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " -#endif +#include <pclasses/pclasses-config.h> +#include <pclasses/Factory.h> +#include <pclasses/NonCopyable.h> +#include <pclasses/Trace.h> +#include <pclasses/Unicode/String.h> +#include <pclasses/System/SharedLib.h> +#include <pclasses/System/PathFinder.h> +#include <pclasses/System/Directory.h> namespace P { namespace Plugin { @@ -32,11 +30,11 @@ */ template <class InterfaceT> class PluginManager : - public ::P::NamedTypeFactory< InterfaceT > + public NamedTypeFactory< InterfaceT > { public: typedef InterfaceT InterfaceType; - typedef ::P::NamedTypeFactory< InterfaceT > ParentType; + typedef NamedTypeFactory< InterfaceT > ParentType; typedef PluginManager<InterfaceType> ThisType; typedef typename ParentType::FactoryFuncType FactoryFuncType; typedef typename ParentType::ResultType ResultType; @@ -44,7 +42,7 @@ /** A type used to hold SharedLib handles. */ - typedef std::map<std::string,::P::System::SharedLib *> PluginsMap; + typedef std::map<Unicode::String, System::SharedLib *> PluginsMap; /** Creates a PluginManager with a default search path @@ -82,18 +80,18 @@ ResultType create( const std::string & _feature ) { std::string feature = this->expandAliases( _feature ); - //CERR << "create("<<_feature<<" ["<<feature<<"])\n"; + P_TRACE(PluginManager) << "create("<<_feature<<" ["<<feature<<"])"; InterfaceType * ret = ParentType::create( feature ); if( ret ) return ret; - std::string dll = this->findPlugin( feature ); + Unicode::String dll = this->findPlugin( feature ); if( dll.empty() ) { - //CERR << "No dll found for feature '"<<feature<<"'!\n"; + P_TRACE(PluginManager) << "No dll found for feature '"<<feature<<"'!"; return 0; } try { - //CERR << "Adding plugin '"<<dll<<"'!\n"; + P_TRACE(PluginManager) << "Adding plugin '"<<dll<<"'!"; this->addPlugin( dll ); ret = ParentType::create( feature ); } @@ -111,11 +109,10 @@ thrown. */ - void addPluginDir( const std::string & dir ) throw(::P::RuntimeError) + void addPluginDir( const Unicode::String & dir ) throw(RuntimeError) { - //CERR << "addPluginDir("<<dir<<").\n"; - using ::P::System::Directory; - const Directory d(dir); // throws on error + P_TRACE(PluginManager) << "addPluginDir("<<dir<<")"; + const System::Directory d(dir); // throws on error d.begin(); // avoid 'unused var' warning. // ^^^ need to find a more elegant solution for that. this->searchPath().addPath( dir ); @@ -136,8 +133,8 @@ multiple times with the same so_name will return the same SharedLib object. */ - ::P::System::SharedLib * - addPlugin( const std::string & so_name ) throw(::P::RuntimeError) + System::SharedLib * + addPlugin(const Unicode::String& so_name) throw(RuntimeError) { typedef typename PluginsMap::iterator IT; // look for cached entry: @@ -148,10 +145,10 @@ } // find a DLL file: - std::string fn = this->searchPath().find( so_name ); + Unicode::String fn = this->searchPath().find( so_name ); if( fn.empty() ) { - throw ::P::System::SystemError( 0, (std::string("No plugin found for '")+so_name+"'.").c_str(), P_SOURCEINFO ); + throw RuntimeError( std::string("No plugin found for '")+so_name.utf8()+"'.", P_SOURCEINFO ); } // check for entry cached under DLL's file name: @@ -162,7 +159,7 @@ } // open DLL and, if workie, cache it: - ::P::System::SharedLib * shl = ::P::System::openSharedLib( fn ); + System::SharedLib * shl = System::openSharedLib( fn ); m_smap.insert( std::make_pair( fn, shl ) ); return shl; } @@ -175,13 +172,13 @@ */ static ThisType & instance() { - return ::P::Hook::FactoryInstanceHook<ThisType>::instance(); + return Hook::FactoryInstanceHook<ThisType>::instance(); } /** This object's search path. Clients are free to modify it. */ - ::P::System::PathFinder & searchPath() + System::PathFinder & searchPath() { return this->m_path; } @@ -189,7 +186,7 @@ /** This object's search path. */ - const ::P::System::PathFinder & searchPath() const + const System::PathFinder & searchPath() const { return this->m_path; } @@ -235,7 +232,7 @@ Returns a path to a plugin file on success or an empty string on error. */ - std::string findPlugin( const std::string & name ) const + Unicode::String findPlugin( const Unicode::String & name ) const { return this->searchPath().find( name ); } @@ -256,7 +253,7 @@ this->m_path.addExtension(std::string(".")+System::SharedLib::extension()); } PluginsMap m_smap; - ::P::System::PathFinder m_path; + System::PathFinder m_path; // ^^^^ todo: consider making this static. }; @@ -274,7 +271,7 @@ pluginManager<T>().addPluginDir(pluginname). */ template <typename T> - void addPluginDir( const std::string & path ) throw(RuntimeError) + void addPluginDir( const Unicode::String & path ) throw(RuntimeError) { return pluginManager<T>().addPluginDir( path ); } @@ -284,8 +281,8 @@ pluginManager<T>().addPlugin(pluginname). */ template <typename T> - ::P::System::SharedLib * - addPlugin( const std::string & pluginname ) throw(RuntimeError) + System::SharedLib * + addPlugin( const Unicode::String & pluginname ) throw(RuntimeError) { return pluginManager<T>().addPlugin( pluginname ); } @@ -295,7 +292,7 @@ pluginManager<T>().findPlugin(name). */ template <typename T> - std::string findPlugin( const std::string & name ) + Unicode::String findPlugin( const Unicode::String & name ) { return pluginManager<T>().findPlugin( name ); } @@ -305,7 +302,7 @@ pluginManager<T>().searchPath(). */ template <typename T> - ::P::System::PathFinder & searchPath() + System::PathFinder & searchPath() { return pluginManager<T>().searchPath(); } @@ -350,10 +347,10 @@ lookups in the core without it knowing so. :) */ template < typename InterfaceT > - struct FactoryInstanceHook< ::P::Factory< InterfaceT, ::P::Sharing::FactoryContext, std::string > > + struct FactoryInstanceHook< Factory< InterfaceT, Sharing::FactoryContext, std::string > > { - typedef ::P::Factory< InterfaceT, ::P::Sharing::FactoryContext, std::string > FactoryType; - typedef ::P::Plugin::PluginManager< InterfaceT > RealFactoryType; + typedef Factory< InterfaceT, Sharing::FactoryContext, std::string > FactoryType; + typedef Plugin::PluginManager< InterfaceT > RealFactoryType; typedef FactoryInstanceHook<FactoryType> ThisType; /** @@ -372,7 +369,7 @@ */ static FactoryType & instance() { - typedef ::P::Phoenix<RealFactoryType, ::P::Sharing::FactoryContext, ThisType > PHX; + typedef Phoenix<RealFactoryType, Sharing::FactoryContext, ThisType > PHX; return PHX::instance(); } }; |