Added copyright lines for files I've edited this year.
[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 **      Copyright (c) 2007, 2008 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_MODULE_H
27 #define __SYNFIG_MODULE_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include "general.h"
32 #include <ETL/handle>
33 #include <map>
34 #include "string.h"
35 #include "releases.h"
36 #include <utility>
37 #include "vector.h"
38 #include "color.h"
39 #include "layer.h"
40 #include "canvas.h"
41
42 //#include "value.h"
43
44 /* === M A C R O S ========================================================= */
45
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);
48
49 //! Sets the localized name of the module
50 #define MODULE_NAME(x)                  virtual const char * Name() { return x; }
51
52 //! Sets a localized description of the module
53 #define MODULE_DESCRIPTION(x)   virtual const char * Desc() { return x; }
54
55 //! Sets the name of the module's author
56 #define MODULE_AUTHOR(x)                virtual const char * Author() { return x; }
57
58 //! Sets the version string for the module
59 #define MODULE_VERSION(x)               virtual const char * Version() { return x; }
60
61 //! Sets the copyright string for the module
62 #define MODULE_COPYRIGHT(x)             virtual const char * Copyright() { return x; }
63
64 //! Describes the module's construction function
65 #define MODULE_CONSTRUCTOR(x)   bool constructor_(synfig::ProgressCallback *cb) { return x(cb); }
66
67 //! Describes the module's destruction function
68 #define MODULE_DESTRUCTOR(x)    virtual void destructor_() { return x(); }
69
70 //! Marks the end of a module description
71 #define MODULE_DESC_END };
72
73 //#if 0
74 #ifdef __APPLE__
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*/) {
81 #else
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*/) {
88 #endif
89
90 //! Marks the start of the layers in the module's inventory
91 #define BEGIN_LAYERS {
92
93 //! DEPRECATED - use #INCLUDE_LAYER(class)
94 #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__));
95 //#define LAYER(x) synfig::Layer::book()[synfig::String(x::name__)]=x::create;
96 #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__));
97
98 //! Marks the end of the layers in the module's inventory
99 #define END_LAYERS }
100
101 //! Marks the start of the targets in the module's inventory
102 #define BEGIN_TARGETS {
103
104 #define TARGET(x)                                                                                                                                                               \
105         synfig::Target::book()[synfig::String(x::name__)]=                                                                                      \
106                 std::pair<synfig::Target::Factory,synfig::String>                                                                               \
107                         (x::create,synfig::String(x::ext__));                                                                                           \
108         synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__;
109
110 #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__;
111
112 //! Marks the end of the targets in the module's inventory
113 #define END_TARGETS }
114
115 //! Marks the start of the importers in the module's inventory
116 #define BEGIN_IMPORTERS {
117
118 #define IMPORTER(x) synfig::Importer::book()[synfig::String(x::ext__)]=x::create;
119
120 #define IMPORTER_EXT(x,y) synfig::Importer::book()[synfig::String(y)]=x::create;
121
122 //! Marks the end of the importers in the module's inventory
123 #define END_IMPORTERS }
124
125 //! Marks the start of the valuenodes in the module's inventory
126 #define BEGIN_VALUENODES { synfig::LinkableValueNode::Book &book(synfig::LinkableValueNode::book());
127
128 #define VALUENODE(class,name,local,version)                                                                                                             \
129         book[name].factory=reinterpret_cast<synfig::LinkableValueNode::Factory>(&class::create);        \
130         book[name].check_type=&class::check_type;                                                                                                       \
131         book[name].local_name=local;                                                                                                                            \
132         book[name].release_version=version;
133
134 //! Marks the end of the valuenodes in the module's inventory
135 #define END_VALUENODES }
136
137 //! Marks the end of a module's inventory
138 #define MODULE_INVENTORY_END    }
139
140 /* === T Y P E D E F S ===================================================== */
141
142 /* === C L A S S E S & S T R U C T S ======================================= */
143
144 namespace synfig {
145
146 class ProgressCallback;
147
148 /*!     \class Module
149 **      \todo writeme
150 */
151 class Module : public etl::shared_object
152 {
153 public:
154         bool constructor_(synfig::ProgressCallback */*cb*/) { return true; }
155         virtual void destructor_() { }
156
157         typedef etl::handle<Module> Handle;
158         typedef etl::loose_handle<Module> LooseHandle;
159         typedef etl::handle<const Module> ConstHandle;
160
161 public:
162         typedef Module*(*constructor_type)(ProgressCallback *);
163         typedef std::map<String, Handle > Book;
164 private:
165         static Book* book_;
166 public:
167         static Book& book();
168
169         static bool subsys_init(const String &prefix);
170         static bool subsys_stop();
171         static bool register_default_modules();
172
173         static void Register(Handle mod);
174         static bool Register(const String &module_name, ProgressCallback *cb=NULL);
175         static inline void Register(Module *mod) { Register(Handle(mod)); }
176
177         virtual const char * Name() { return " "; }
178         virtual const char * Desc() { return " "; }
179         virtual const char * Author() { return " "; }
180         virtual const char * Version() { return " "; }
181         virtual const char * Copyright() { return SYNFIG_COPYRIGHT; }
182
183         virtual ~Module() { destructor_(); }
184 };
185
186 }; // END of namespace synfig
187
188 /* === E N D =============================================================== */
189
190 #endif