1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/module.h
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_MODULE_H
27 #define __SYNFIG_MODULE_H
29 /* === H E A D E R S ======================================================= */
44 /* === M A C R O S ========================================================= */
46 //! Marks the start of a module description
47 #define MODULE_DESC_BEGIN(x) struct x##_modclass : public synfig::Module { x##_modclass(synfig::ProgressCallback *callback=NULL);
49 //! Sets the localized name of the module
50 #define MODULE_NAME(x) virtual const char * Name() { return x; }
52 //! Sets a localized description of the module
53 #define MODULE_DESCRIPTION(x) virtual const char * Desc() { return x; }
55 //! Sets the name of the module's author
56 #define MODULE_AUTHOR(x) virtual const char * Author() { return x; }
58 //! Sets the version string for the module
59 #define MODULE_VERSION(x) virtual const char * Version() { return x; }
61 //! Sets the copyright string for the module
62 #define MODULE_COPYRIGHT(x) virtual const char * Copyright() { return x; }
64 //! Describes the module's construction function
65 #define MODULE_CONSTRUCTOR(x) bool constructor_(synfig::ProgressCallback *cb) { return x(cb); }
67 //! Describes the module's destruction function
68 #define MODULE_DESTRUCTOR(x) virtual void destructor_() { return x(); }
70 //! Marks the end of a module description
71 #define MODULE_DESC_END };
75 //! Marks the start of a module's inventory
76 #define MODULE_INVENTORY_BEGIN(x) extern "C" { \
77 synfig::Module* _##x##_LTX_new_instance(synfig::ProgressCallback *cb) \
78 { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
79 if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
80 }; x##_modclass::x##_modclass(synfig::ProgressCallback */*cb*/) {
82 //! Marks the start of a module's inventory
83 #define MODULE_INVENTORY_BEGIN(x) extern "C" { \
84 synfig::Module* x##_LTX_new_instance(synfig::ProgressCallback *cb) \
85 { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
86 if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
87 }; x##_modclass::x##_modclass(synfig::ProgressCallback */*cb*/) {
90 //! Marks the start of the layers in the module's inventory
91 #define BEGIN_LAYERS {
93 //! DEPRECATED - use #INCLUDE_LAYER(class)
94 #define LAYER(class) \
95 synfig::Layer::register_in_book( \
96 synfig::Layer::BookEntry(class::create, \
98 dgettext("synfig", class::local_name__), \
103 #define LAYER_ALIAS(class,alias) \
104 synfig::Layer::register_in_book( \
105 synfig::Layer::BookEntry(class::create, \
108 CATEGORY_DO_NOT_USE, \
112 //! Marks the end of the layers in the module's inventory
115 //! Marks the start of the targets in the module's inventory
116 #define BEGIN_TARGETS {
119 synfig::Target::book()[synfig::String(x::name__)].factory = \
120 reinterpret_cast<synfig::Target::Factory> (x::create); \
121 synfig::Target::book()[synfig::String(x::name__)].filename = \
122 synfig::String(x::ext__); \
123 synfig::Target::book()[synfig::String(x::name__)].target_param = \
124 synfig::TargetParam(); \
125 synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__;
127 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
129 //! Marks the end of the targets in the module's inventory
130 #define END_TARGETS }
132 //! Marks the start of the importers in the module's inventory
133 #define BEGIN_IMPORTERS {
135 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
137 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
139 //! Marks the end of the importers in the module's inventory
140 #define END_IMPORTERS }
142 //! Marks the start of the valuenodes in the module's inventory
143 #define BEGIN_VALUENODES { synfig::LinkableValueNode::Book &book(synfig::LinkableValueNode::book());
145 #define VALUENODE(class,name,local,version) \
146 book[name].factory=reinterpret_cast<synfig::LinkableValueNode::Factory>(&class::create); \
147 book[name].check_type=&class::check_type; \
148 book[name].local_name=local; \
149 book[name].release_version=version;
151 //! Marks the end of the valuenodes in the module's inventory
152 #define END_VALUENODES }
154 //! Marks the end of a module's inventory
155 #define MODULE_INVENTORY_END }
157 /* === T Y P E D E F S ===================================================== */
159 /* === C L A S S E S & S T R U C T S ======================================= */
163 class ProgressCallback;
168 class Module : public etl::shared_object
171 bool constructor_(synfig::ProgressCallback */*cb*/) { return true; }
172 virtual void destructor_() { }
174 typedef etl::handle<Module> Handle;
175 typedef etl::loose_handle<Module> LooseHandle;
176 typedef etl::handle<const Module> ConstHandle;
179 typedef Module*(*constructor_type)(ProgressCallback *);
180 typedef std::map<String, Handle > Book;
186 static bool subsys_init(const String &prefix);
187 static bool subsys_stop();
188 static void register_default_modules(ProgressCallback *cb=NULL);
190 static void Register(Handle mod);
191 static bool Register(const String &module_name, ProgressCallback *cb=NULL);
192 static inline void Register(Module *mod) { Register(Handle(mod)); }
194 virtual const char * Name() { return " "; }
195 virtual const char * Desc() { return " "; }
196 virtual const char * Author() { return " "; }
197 virtual const char * Version() { return " "; }
198 virtual const char * Copyright() { return SYNFIG_COPYRIGHT; }
200 virtual ~Module() { destructor_(); }
203 }; // END of namespace synfig
205 /* === E N D =============================================================== */