plugins.hh
Go to the documentation of this file.
00001 #ifndef TYPELIB_IOPLUGINS_HH
00002 #define TYPELIB_IOPLUGINS_HH
00003 
00004 #include <boost/type_traits/is_base_and_derived.hpp>
00005 #include <boost/mpl/if.hpp>
00006 
00007 namespace Typelib
00008 {
00009     class ExportPlugin;
00010     class ImportPlugin;
00011     class Exporter;
00012     class Importer;
00013 
00014     template<typename Type>
00015     struct plugin_traits
00016     {
00017         typedef typename boost::mpl::if_
00018             < boost::is_base_and_derived<Exporter, Type>
00019             , ExportPlugin
00020             , ImportPlugin >::type   plugin_base;
00021 
00022         typedef typename boost::mpl::if_
00023             < boost::is_base_and_derived<Exporter, Type>
00024             , Exporter
00025             , Importer >::type   object_base;
00026     };
00027 
00028     template<typename Type>
00029     class GenericIOPlugin 
00030         : public plugin_traits<Type>::plugin_base
00031     {
00032     public:
00033         GenericIOPlugin(char const* name)
00034             : plugin_traits<Type>::plugin_base(name) {}
00035         typename plugin_traits<Type>::object_base* create()
00036         { return new Type; }
00037     };
00038 
00039     class TypeDefinitionPlugin
00040     {
00041     public:
00042         virtual ~TypeDefinitionPlugin() {}
00043         virtual void registerTypes(Typelib::Registry& registry) = 0;
00044     };
00045 }
00046 
00047 #define TYPELIB_REGISTER_IO2(name, klass1, klass2) extern "C" void registerPlugins(Typelib::PluginManager& manager) {\
00048     manager.add(new Typelib::GenericIOPlugin<klass1>(#name)); \
00049     manager.add(new Typelib::GenericIOPlugin<klass2>(#name)); \
00050 }
00051 
00052 #define TYPELIB_REGISTER_IO1(name, klass1) extern "C" void registerPlugins(Typelib::PluginManager& manager) {\
00053     manager.add(new Typelib::GenericIOPlugin<klass1>(#name)); \
00054 }
00055 
00056 #endif
00057 


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Sat Jun 8 2019 18:49:22