1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/module.h
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_MODULE_H
26 #define __SYNFIG_MODULE_H
28 /* === H E A D E R S ======================================================= */
42 /* === M A C R O S ========================================================= */
44 //! Marks the start of a module description
45 #define MODULE_DESC_BEGIN(x) struct x##_modclass : public synfig::Module { x##_modclass(synfig::ProgressCallback *callback=NULL);
47 //! Sets the localized name of the module
48 #define MODULE_NAME(x) virtual const char * Name() { return x; }
50 //! Sets a localized description of the module
51 #define MODULE_DESCRIPTION(x) virtual const char * Desc() { return x; }
53 //! Sets the name of the module's author
54 #define MODULE_AUTHOR(x) virtual const char * Author() { return x; }
56 //! Sets the version string for the module
57 #define MODULE_VERSION(x) virtual const char * Version() { return x; }
59 //! Sets the copyright string for the module
60 #define MODULE_COPYRIGHT(x) virtual const char * Copyright() { return x; }
62 //! Describes the module's construction function
63 #define MODULE_CONSTRUCTOR(x) bool constructor_(synfig::ProgressCallback *cb) { return x(cb); }
65 //! Describes the module's destruction function
66 #define MODULE_DESTRUCTOR(x) virtual void destructor_() { return x(); }
68 //! Marks the end of a module description
69 #define MODULE_DESC_END };
73 //! Marks the start of a module's inventory
74 #define MODULE_INVENTORY_BEGIN(x) extern "C" { \
75 synfig::Module* _##x##_LTX_new_instance(synfig::ProgressCallback *cb) \
76 { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
77 if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
78 }; x##_modclass::x##_modclass(synfig::ProgressCallback */*cb*/) {
80 //! Marks the start of a module's inventory
81 #define MODULE_INVENTORY_BEGIN(x) extern "C" { \
82 synfig::Module* x##_LTX_new_instance(synfig::ProgressCallback *cb) \
83 { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
84 if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
85 }; x##_modclass::x##_modclass(synfig::ProgressCallback */*cb*/) {
88 //! Marks the start of the layers in the module's inventory
89 #define BEGIN_LAYERS {
91 //! DEPRECATED - use #INCLUDE_LAYER(class)
92 #define LAYER(class) synfig::Layer::register_in_book(synfig::Layer::BookEntry(class::create,class::name__,dgettext("synfig",class::local_name__),dgettext("synfig",class::category__),class::cvs_id__,class::version__));
93 //#define LAYER(x) synfig::Layer::book()[synfig::String(x::name__)]=x::create;
94 #define LAYER_ALIAS(class,alias) synfig::Layer::register_in_book(synfig::Layer::BookEntry(class::create,alias,alias,CATEGORY_DO_NOT_USE,class::cvs_id__,class::version__));
96 //! Marks the end of the layers in the module's inventory
99 //! Marks the start of the targets in the module's inventory
100 #define BEGIN_TARGETS {
103 synfig::Target::book()[synfig::String(x::name__)]= \
104 std::pair<synfig::Target::Factory,synfig::String> \
105 (x::create,synfig::String(x::ext__)); \
106 synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__;
108 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
110 //! Marks the end of the targets in the module's inventory
111 #define END_TARGETS }
113 //! Marks the start of the importers in the module's inventory
114 #define BEGIN_IMPORTERS {
116 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
118 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
120 //! Marks the end of the importers in the module's inventory
121 #define END_IMPORTERS }
123 //! Marks the start of the valuenodes in the module's inventory
124 #define BEGIN_VALUENODES { synfig::LinkableValueNode::Book &book(synfig::LinkableValueNode::book());
126 #define VALUENODE(class,name,local) \
127 book[name].factory=reinterpret_cast<synfig::LinkableValueNode::Factory>(&class::create); \
128 book[name].check_type=&class::check_type; \
129 book[name].local_name=local;
131 //! Marks the end of the valuenodes in the module's inventory
132 #define END_VALUENODES }
134 //! Marks the end of a module's inventory
135 #define MODULE_INVENTORY_END }
137 /* === T Y P E D E F S ===================================================== */
139 /* === C L A S S E S & S T R U C T S ======================================= */
143 class ProgressCallback;
148 class Module : public etl::shared_object
151 bool constructor_(synfig::ProgressCallback */*cb*/) { return true; }
152 virtual void destructor_() { }
154 typedef etl::handle<Module> Handle;
155 typedef etl::loose_handle<Module> LooseHandle;
156 typedef etl::handle<const Module> ConstHandle;
159 typedef Module*(*constructor_type)(ProgressCallback *);
160 typedef std::map<String, Handle > Book;
166 static bool subsys_init(const String &prefix);
167 static bool subsys_stop();
168 static bool register_default_modules();
170 static void Register(Handle mod);
171 static bool Register(const String &module_name, ProgressCallback *cb=NULL);
172 static inline void Register(Module *mod) { Register(Handle(mod)); }
174 virtual const char * Name() { return " "; }
175 virtual const char * Desc() { return " "; }
176 virtual const char * Author() { return " "; }
177 virtual const char * Version() { return " "; }
178 virtual const char * Copyright() { return SYNFIG_COPYRIGHT; }
180 virtual ~Module() { destructor_(); }
183 }; // END of namespace synfig
185 /* === E N D =============================================================== */