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 void registerTypes(Typelib::Registry& registry) = 0;
00043     };
00044 }
00045 
00046 #define TYPELIB_REGISTER_IO2(name, klass1, klass2) extern "C" void registerPlugins(Typelib::PluginManager& manager) {\
00047     manager.add(new Typelib::GenericIOPlugin<klass1>(#name)); \
00048     manager.add(new Typelib::GenericIOPlugin<klass2>(#name)); \
00049 }
00050 
00051 #define TYPELIB_REGISTER_IO1(name, klass1) extern "C" void registerPlugins(Typelib::PluginManager& manager) {\
00052     manager.add(new Typelib::GenericIOPlugin<klass1>(#name)); \
00053 }
00054 
00055 #endif
00056 


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Mon Oct 6 2014 03:17:12