Update of /cvsroot/pclasses/pclasses2/include/pclasses/System
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10123/include/pclasses/System
Added Files:
Plugin.h
Log Message:
- Added new PluginManager based on the new Factory code
--- NEW FILE: Plugin.h ---
/***************************************************************************
* Copyright (C) 2005 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. *
***************************************************************************/
// Based on the excellect Factory/Classloader code
// from stephan beal <st...@s1...>
#ifndef P_System_Plugin_h
#define P_System_Plugin_h
#include <pclasses/Export.h>
#include <pclasses/NonCopyable.h>
#include <pclasses/Unicode/String.h>
#include <pclasses/System/PathFinder.h>
#include <pclasses/System/SharedLib.h>
#include <map>
#include <string>
#include <typeinfo>
namespace P {
namespace System {
class PSYSTEM_EXPORT PluginManager: public NonCopyable {
public:
typedef std::map<Unicode::String, SharedLib*> PluginMap;
typedef std::map<std::string, PathFinder> PathFinderMap;
void addPluginDir(const std::string& ifaceType,
const Unicode::String& dir) throw(SystemError);
template <class TypeName>
void addPluginDir(const Unicode::String& dir)
throw(SystemError)
{
addPluginDir(typeid(TypeName).name(), dir);
}
SharedLib* addPlugin(const std::string& ifaceType,
const Unicode::String& soName) throw(SystemError);
template <class TypeName>
void addPlugin(const Unicode::String& soName)
throw(SystemError)
{
addPlugin(typeid(TypeName).name(), soName);
}
static PluginManager& instance();
private:
PathFinder& pathFinder(const std::string& ifaceType);
PluginManager();
~PluginManager();
PathFinderMap _pathFinders;
PluginMap _pluginMap;
};
} // !namespace System
} // !namespace P
//! Registers a type in the Factory on static initialization
/*!
\param Iface Interface of the type to be registered
\param type Type to register
*/
#define P_PLUGIN_REGISTER_TYPE(Iface, type) \
void type##_Factory_init() { P_FACTORY_REGISTER_TYPE(Iface, type); } \
int type##_Factory_init_placeholder = ( type##_Factory_init(), 0 );
#define P_PLUGIN_REGISTER_ALIAS(Iface, alias, type) \
void type##_Factory_alias_init() { P_FACTORY_REGISTER_ALIAS(Iface, alias, type); } \
int type##_Factory_alias_init_placeholder = ( type##_Factory_alias_init(), 0 );
#endif
|