00001
00022
00023
00024
00025
00026 #ifndef __SYNFIG_MODULE_H
00027 #define __SYNFIG_MODULE_H
00028
00029
00030
00031 #include "general.h"
00032 #include <ETL/handle>
00033 #include <map>
00034 #include "string.h"
00035 #include "releases.h"
00036 #include <utility>
00037 #include "vector.h"
00038 #include "color.h"
00039 #include "layer.h"
00040 #include "canvas.h"
00041
00042
00043
00044
00045
00047 #define MODULE_DESC_BEGIN(x) struct x##_modclass : public synfig::Module { x##_modclass(synfig::ProgressCallback *callback=NULL);
00048
00050 #define MODULE_NAME(x) virtual const char * Name() { return x; }
00051
00053 #define MODULE_DESCRIPTION(x) virtual const char * Desc() { return x; }
00054
00056 #define MODULE_AUTHOR(x) virtual const char * Author() { return x; }
00057
00059 #define MODULE_VERSION(x) virtual const char * Version() { return x; }
00060
00062 #define MODULE_COPYRIGHT(x) virtual const char * Copyright() { return x; }
00063
00065 #define MODULE_CONSTRUCTOR(x) bool constructor_(synfig::ProgressCallback *cb) { return x(cb); }
00066
00068 #define MODULE_DESTRUCTOR(x) virtual void destructor_() { return x(); }
00069
00071 #define MODULE_DESC_END };
00072
00073
00074 #ifdef __APPLE__
00076 #define MODULE_INVENTORY_BEGIN(x) extern "C" { \
00077 synfig::Module* _##x##_LTX_new_instance(synfig::ProgressCallback *cb) \
00078 { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
00079 if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
00080 }; x##_modclass::x##_modclass(synfig::ProgressCallback *) {
00081 #else
00083 #define MODULE_INVENTORY_BEGIN(x) extern "C" { \
00084 synfig::Module* x##_LTX_new_instance(synfig::ProgressCallback *cb) \
00085 { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
00086 if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
00087 }; x##_modclass::x##_modclass(synfig::ProgressCallback *) {
00088 #endif
00089
00091 #define BEGIN_LAYERS {
00092
00094 #define LAYER(class) \
00095 synfig::Layer::register_in_book( \
00096 synfig::Layer::BookEntry(class::create, \
00097 class::name__, \
00098 dgettext("synfig", class::local_name__), \
00099 class::category__, \
00100 class::cvs_id__, \
00101 class::version__));
00102
00103 #define LAYER_ALIAS(class,alias) \
00104 synfig::Layer::register_in_book( \
00105 synfig::Layer::BookEntry(class::create, \
00106 alias, \
00107 alias, \
00108 CATEGORY_DO_NOT_USE, \
00109 class::cvs_id__, \
00110 class::version__));
00111
00113 #define END_LAYERS }
00114
00116 #define BEGIN_TARGETS {
00117
00118 #define TARGET(x) \
00119 synfig::Target::book()[synfig::String(x::name__)]= \
00120 std::pair<synfig::Target::Factory,synfig::String> \
00121 (x::create,synfig::String(x::ext__)); \
00122 synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__;
00123
00124 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
00125
00127 #define END_TARGETS }
00128
00130 #define BEGIN_IMPORTERS {
00131
00132 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
00133
00134 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
00135
00137 #define END_IMPORTERS }
00138
00140 #define BEGIN_VALUENODES { synfig::LinkableValueNode::Book &book(synfig::LinkableValueNode::book());
00141
00142 #define VALUENODE(class,name,local,version) \
00143 book[name].factory=reinterpret_cast<synfig::LinkableValueNode::Factory>(&class::create); \
00144 book[name].check_type=&class::check_type; \
00145 book[name].local_name=local; \
00146 book[name].release_version=version;
00147
00149 #define END_VALUENODES }
00150
00152 #define MODULE_INVENTORY_END }
00153
00154
00155
00156
00157
00158 namespace synfig {
00159
00160 class ProgressCallback;
00161
00165 class Module : public etl::shared_object
00166 {
00167 public:
00168 bool constructor_(synfig::ProgressCallback *) { return true; }
00169 virtual void destructor_() { }
00170
00171 typedef etl::handle<Module> Handle;
00172 typedef etl::loose_handle<Module> LooseHandle;
00173 typedef etl::handle<const Module> ConstHandle;
00174
00175 public:
00176 typedef Module*(*constructor_type)(ProgressCallback *);
00177 typedef std::map<String, Handle > Book;
00178 private:
00179 static Book* book_;
00180 public:
00181 static Book& book();
00182
00183 static bool subsys_init(const String &prefix);
00184 static bool subsys_stop();
00185 static void register_default_modules(ProgressCallback *cb=NULL);
00186
00187 static void Register(Handle mod);
00188 static bool Register(const String &module_name, ProgressCallback *cb=NULL);
00189 static inline void Register(Module *mod) { Register(Handle(mod)); }
00190
00191 virtual const char * Name() { return " "; }
00192 virtual const char * Desc() { return " "; }
00193 virtual const char * Author() { return " "; }
00194 virtual const char * Version() { return " "; }
00195 virtual const char * Copyright() { return SYNFIG_COPYRIGHT; }
00196
00197 virtual ~Module() { destructor_(); }
00198 };
00199
00200 };
00201
00202
00203
00204 #endif