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()
92 //#define LAYER(x) synfig::Layer::book()[synfig::String(x::name__)]=x::create;
93 #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__));
94 #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__));
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 {
102 #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__;
104 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
106 //! Marks the end of the targets in the module's inventory
107 #define END_TARGETS }
109 //! Marks the start of the importers in the module's inventory
110 #define BEGIN_IMPORTERS {
112 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
114 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
116 //! Marks the end of the importers in the module's inventory
117 #define END_IMPORTERS }
119 //! Marks the end of a module's inventory
120 #define MODULE_INVENTORY_END }
122 /* === T Y P E D E F S ===================================================== */
124 /* === C L A S S E S & S T R U C T S ======================================= */
128 class ProgressCallback;
133 class Module : public etl::shared_object
136 bool constructor_(synfig::ProgressCallback */*cb*/) { return true; }
137 virtual void destructor_() { }
139 typedef etl::handle<Module> Handle;
140 typedef etl::loose_handle<Module> LooseHandle;
141 typedef etl::handle<const Module> ConstHandle;
144 typedef Module*(*constructor_type)(ProgressCallback *);
145 typedef std::map<String, Handle > Book;
151 static bool subsys_init(const String &prefix);
152 static bool subsys_stop();
153 static bool register_default_modules();
155 static void Register(Handle mod);
156 static bool Register(const String &module_name, ProgressCallback *cb=NULL);
157 static inline void Register(Module *mod) { Register(Handle(mod)); }
159 virtual const char * Name() { return " "; }
160 virtual const char * Desc() { return " "; }
161 virtual const char * Author() { return " "; }
162 virtual const char * Version() { return " "; }
163 virtual const char * Copyright() { return SYNFIG_COPYRIGHT; }
165 virtual ~Module() { destructor_(); }
168 }; // END of namespace synfig
170 /* === E N D =============================================================== */