Add information about which valuenode types were added in which release. Don't save...
[synfig.git] / synfig-core / trunk / 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 "releases.h"
35 #include <utility>
36 #include "vector.h"
37 #include "color.h"
38 #include "layer.h"
39 #include "canvas.h"
40
41 //#include "value.h"
42
43 /* === M A C R O S ========================================================= */
44
45 //! Marks the start of a module description
46 #define MODULE_DESC_BEGIN(x) struct x##_modclass : public synfig::Module { x##_modclass(synfig::ProgressCallback *callback=NULL);
47
48 //! Sets the localized name of the module
49 #define MODULE_NAME(x)                  virtual const char * Name() { return x; }
50
51 //! Sets a localized description of the module
52 #define MODULE_DESCRIPTION(x)   virtual const char * Desc() { return x; }
53
54 //! Sets the name of the module's author
55 #define MODULE_AUTHOR(x)                virtual const char * Author() { return x; }
56
57 //! Sets the version string for the module
58 #define MODULE_VERSION(x)               virtual const char * Version() { return x; }
59
60 //! Sets the copyright string for the module
61 #define MODULE_COPYRIGHT(x)             virtual const char * Copyright() { return x; }
62
63 //! Describes the module's construction function
64 #define MODULE_CONSTRUCTOR(x)   bool constructor_(synfig::ProgressCallback *cb) { return x(cb); }
65
66 //! Describes the module's destruction function
67 #define MODULE_DESTRUCTOR(x)    virtual void destructor_() { return x(); }
68
69 //! Marks the end of a module description
70 #define MODULE_DESC_END };
71
72 //#if 0
73 #ifdef __APPLE__
74 //! Marks the start of a module's inventory
75 #define MODULE_INVENTORY_BEGIN(x)  extern "C" {         \
76         synfig::Module* _##x##_LTX_new_instance(synfig::ProgressCallback *cb) \
77         { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
78         if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
79         }; x##_modclass::x##_modclass(synfig::ProgressCallback */*cb*/) {
80 #else
81 //! Marks the start of a module's inventory
82 #define MODULE_INVENTORY_BEGIN(x)  extern "C" {         \
83         synfig::Module* x##_LTX_new_instance(synfig::ProgressCallback *cb) \
84         { if(SYNFIG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
85         if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
86         }; x##_modclass::x##_modclass(synfig::ProgressCallback */*cb*/) {
87 #endif
88
89 //! Marks the start of the layers in the module's inventory
90 #define BEGIN_LAYERS {
91
92 //! DEPRECATED - use #INCLUDE_LAYER(class)
93 #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__));
94 //#define LAYER(x) synfig::Layer::book()[synfig::String(x::name__)]=x::create;
95 #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
97 //! Marks the end of the layers in the module's inventory
98 #define END_LAYERS }
99
100 //! Marks the start of the targets in the module's inventory
101 #define BEGIN_TARGETS {
102
103 #define TARGET(x)                                                                                                                                                               \
104         synfig::Target::book()[synfig::String(x::name__)]=                                                                                      \
105                 std::pair<synfig::Target::Factory,synfig::String>                                                                               \
106                         (x::create,synfig::String(x::ext__));                                                                                           \
107         synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__;
108
109 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
110
111 //! Marks the end of the targets in the module's inventory
112 #define END_TARGETS }
113
114 //! Marks the start of the importers in the module's inventory
115 #define BEGIN_IMPORTERS {
116
117 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
118
119 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
120
121 //! Marks the end of the importers in the module's inventory
122 #define END_IMPORTERS }
123
124 //! Marks the start of the valuenodes in the module's inventory
125 #define BEGIN_VALUENODES { synfig::LinkableValueNode::Book &book(synfig::LinkableValueNode::book());
126
127 #define VALUENODE(class,name,local,version)                                                                                                             \
128         book[name].factory=reinterpret_cast<synfig::LinkableValueNode::Factory>(&class::create);        \
129         book[name].check_type=&class::check_type;                                                                                                       \
130         book[name].local_name=local;                                                                                                                            \
131         book[name].release_version=version;
132
133 //! Marks the end of the valuenodes in the module's inventory
134 #define END_VALUENODES }
135
136 //! Marks the end of a module's inventory
137 #define MODULE_INVENTORY_END    }
138
139 /* === T Y P E D E F S ===================================================== */
140
141 /* === C L A S S E S & S T R U C T S ======================================= */
142
143 namespace synfig {
144
145 class ProgressCallback;
146
147 /*!     \class Module
148 **      \todo writeme
149 */
150 class Module : public etl::shared_object
151 {
152 public:
153         bool constructor_(synfig::ProgressCallback */*cb*/) { return true; }
154         virtual void destructor_() { }
155
156         typedef etl::handle<Module> Handle;
157         typedef etl::loose_handle<Module> LooseHandle;
158         typedef etl::handle<const Module> ConstHandle;
159
160 public:
161         typedef Module*(*constructor_type)(ProgressCallback *);
162         typedef std::map<String, Handle > Book;
163 private:
164         static Book* book_;
165 public:
166         static Book& book();
167
168         static bool subsys_init(const String &prefix);
169         static bool subsys_stop();
170         static bool register_default_modules();
171
172         static void Register(Handle mod);
173         static bool Register(const String &module_name, ProgressCallback *cb=NULL);
174         static inline void Register(Module *mod) { Register(Handle(mod)); }
175
176         virtual const char * Name() { return " "; }
177         virtual const char * Desc() { return " "; }
178         virtual const char * Author() { return " "; }
179         virtual const char * Version() { return " "; }
180         virtual const char * Copyright() { return SYNFIG_COPYRIGHT; }
181
182         virtual ~Module() { destructor_(); }
183 };
184
185 }; // END of namespace synfig
186
187 /* === E N D =============================================================== */
188
189 #endif