module.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_MODULE_H
00026 #define __SYNFIG_MODULE_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include "general.h"
00031 #include <ETL/handle>
00032 #include <map>
00033 #include "string.h"
00034 #include <utility>
00035 #include "vector.h"
00036 #include "color.h"
00037 #include "layer.h"
00038 #include "canvas.h"
00039 
00040 //#include "value.h"
00041 
00042 /* === M A C R O S ========================================================= */
00043 
00045 #define MODULE_DESC_BEGIN(x) struct x##_modclass : public synfig::Module { x##_modclass(synfig::ProgressCallback *callback=NULL); 
00046 
00048 #define MODULE_NAME(x)          virtual const char * Name() { return x; }
00049 
00051 #define MODULE_DESCRIPTION(x)   virtual const char * Desc() { return x; }
00052 
00054 #define MODULE_AUTHOR(x)        virtual const char * Author() { return x; }
00055 
00057 #define MODULE_VERSION(x)       virtual const char * Version() { return x; }
00058 
00060 #define MODULE_COPYRIGHT(x)     virtual const char * Copyright() { return x; }
00061 
00063 #define MODULE_CONSTRUCTOR(x)   bool constructor_(synfig::ProgressCallback *cb) { return x(cb); }
00064 
00066 #define MODULE_DESTRUCTOR(x)    virtual void destructor_() { return x(); }
00067 
00069 #define MODULE_DESC_END };
00070 
00071 //#if 0
00072 #ifdef __APPLE__
00073 
00074 #define MODULE_INVENTORY_BEGIN(x)  extern "C" {     \
00075     synfig::Module* _##x##_LTX_new_instance(synfig::ProgressCallback *cb) \
00076     { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
00077     if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
00078     }; x##_modclass::x##_modclass(synfig::ProgressCallback *cb) { 
00079 #else
00080 
00081 #define MODULE_INVENTORY_BEGIN(x)  extern "C" {     \
00082     synfig::Module* x##_LTX_new_instance(synfig::ProgressCallback *cb) \
00083     { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
00084     if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
00085     }; x##_modclass::x##_modclass(synfig::ProgressCallback *cb) { 
00086 #endif
00087 
00089 #define BEGIN_LAYERS {
00090 
00092 //#define LAYER(x) synfig::Layer::book()[synfig::String(x::name__)]=x::create;
00093 #define LAYER(class)    synfig::Layer::register_in_book(synfig::Layer::BookEntry(class::create,class::name__,class::local_name__,class::category__,class::cvs_id__,class::version__));
00094 #define LAYER_ALIAS(class,alias)    synfig::Layer::register_in_book(synfig::Layer::BookEntry(class::create,alias,alias,_("Do Not Use"),class::cvs_id__,class::version__));
00095 
00097 #define END_LAYERS }
00098 
00100 #define BEGIN_TARGETS {
00101 
00102 #define TARGET(x) synfig::Target::book()[synfig::String(x::name__)]=std::pair<synfig::Target::Factory,synfig::String>(x::create,synfig::String(x::ext__));synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__;
00103 
00104 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
00105 
00107 #define END_TARGETS }
00108 
00110 #define BEGIN_IMPORTERS {
00111 
00112 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
00113 
00114 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
00115 
00117 #define END_IMPORTERS }
00118 
00120 #define MODULE_INVENTORY_END    }
00121 
00122 /* === T Y P E D E F S ===================================================== */
00123 
00124 /* === C L A S S E S & S T R U C T S ======================================= */
00125 
00126 namespace synfig {
00127 
00128 class ProgressCallback;
00129 
00133 class Module : public etl::shared_object
00134 {
00135 public:
00136     bool constructor_(synfig::ProgressCallback *cb) { return true; }
00137     virtual void destructor_() { }
00138     
00139     typedef etl::handle<Module> Handle;
00140     typedef etl::loose_handle<Module> LooseHandle;
00141     typedef etl::handle<const Module> ConstHandle;
00142     
00143 public:
00144     typedef Module*(*constructor_type)(ProgressCallback *);
00145     typedef std::map<String, Handle > Book;
00146 private:
00147     static Book* book_;
00148 public:
00149     static Book& book();
00150 
00151     static bool subsys_init(const String &prefix);
00152     static bool subsys_stop();
00153     static bool register_default_modules();
00154 
00155     static void Register(Handle mod);
00156     static bool Register(const String &module_name, ProgressCallback *cb=NULL);
00157     static inline void Register(Module *mod) { Register(Handle(mod)); }
00158     
00159     virtual const char * Name() { return " "; }
00160     virtual const char * Desc() { return " "; }
00161     virtual const char * Author() { return " "; }
00162     virtual const char * Version() { return " "; }
00163     virtual const char * Copyright() { return SYNFIG_COPYRIGHT; }
00164 
00165     virtual ~Module() { destructor_(); }
00166 };
00167 
00168 }; // END of namespace synfig
00169 
00170 /* === E N D =============================================================== */
00171 
00172 #endif

Generated on Fri Jun 23 15:20:50 2006 for synfig by  doxygen 1.4.6