Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07 / src / synfig / module.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file synfig/module.h
3 **      \brief writeme
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_MODULE_H
26 #define __SYNFIG_MODULE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "general.h"
31 #include <ETL/handle>
32 #include <map>
33 #include "string.h"
34 #include <utility>
35 #include "vector.h"
36 #include "color.h"
37 #include "layer.h"
38 #include "canvas.h"
39
40 //#include "value.h"
41
42 /* === M A C R O S ========================================================= */
43
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);
46
47 //! Sets the localized name of the module
48 #define MODULE_NAME(x)                  virtual const char * Name() { return x; }
49
50 //! Sets a localized description of the module
51 #define MODULE_DESCRIPTION(x)   virtual const char * Desc() { return x; }
52
53 //! Sets the name of the module's author
54 #define MODULE_AUTHOR(x)                virtual const char * Author() { return x; }
55
56 //! Sets the version string for the module
57 #define MODULE_VERSION(x)               virtual const char * Version() { return x; }
58
59 //! Sets the copyright string for the module
60 #define MODULE_COPYRIGHT(x)             virtual const char * Copyright() { return x; }
61
62 //! Describes the module's construction function
63 #define MODULE_CONSTRUCTOR(x)   bool constructor_(synfig::ProgressCallback *cb) { return x(cb); }
64
65 //! Describes the module's destruction function
66 #define MODULE_DESTRUCTOR(x)    virtual void destructor_() { return x(); }
67
68 //! Marks the end of a module description
69 #define MODULE_DESC_END };
70
71 //#if 0
72 #ifdef __APPLE__
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*/) {
79 #else
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*/) {
86 #endif
87
88 //! Marks the start of the layers in the module's inventory
89 #define BEGIN_LAYERS {
90
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__));
95
96 //! Marks the end of the layers in the module's inventory
97 #define END_LAYERS }
98
99 //! Marks the start of the targets in the module's inventory
100 #define BEGIN_TARGETS {
101
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__;
103
104 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
105
106 //! Marks the end of the targets in the module's inventory
107 #define END_TARGETS }
108
109 //! Marks the start of the importers in the module's inventory
110 #define BEGIN_IMPORTERS {
111
112 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
113
114 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
115
116 //! Marks the end of the importers in the module's inventory
117 #define END_IMPORTERS }
118
119 //! Marks the end of a module's inventory
120 #define MODULE_INVENTORY_END    }
121
122 /* === T Y P E D E F S ===================================================== */
123
124 /* === C L A S S E S & S T R U C T S ======================================= */
125
126 namespace synfig {
127
128 class ProgressCallback;
129
130 /*!     \class Module
131 **      \todo writeme
132 */
133 class Module : public etl::shared_object
134 {
135 public:
136         bool constructor_(synfig::ProgressCallback */*cb*/) { return true; }
137         virtual void destructor_() { }
138
139         typedef etl::handle<Module> Handle;
140         typedef etl::loose_handle<Module> LooseHandle;
141         typedef etl::handle<const Module> ConstHandle;
142
143 public:
144         typedef Module*(*constructor_type)(ProgressCallback *);
145         typedef std::map<String, Handle > Book;
146 private:
147         static Book* book_;
148 public:
149         static Book& book();
150
151         static bool subsys_init(const String &prefix);
152         static bool subsys_stop();
153         static bool register_default_modules();
154
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)); }
158
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; }
164
165         virtual ~Module() { destructor_(); }
166 };
167
168 }; // END of namespace synfig
169
170 /* === E N D =============================================================== */
171
172 #endif