more updates
[synfig.git] / synfig-core / trunk / src / synfig / module.h
1 /* === S I N F G =========================================================== */
2 /*!     \file module.h
3 **      \brief writeme
4 **
5 **      $Id: module.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SINFG_MODULE_H
25 #define __SINFG_MODULE_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "general.h"
30 #include <ETL/handle>
31 #include <map>
32 #include "string.h"
33 #include <utility>
34 #include "vector.h"
35 #include "color.h"
36 #include "layer.h"
37 #include "canvas.h"
38
39 //#include "value.h"
40
41 /* === M A C R O S ========================================================= */
42
43 //! Marks the start of a module description
44 #define MODULE_DESC_BEGIN(x) struct x##_modclass : public sinfg::Module { x##_modclass(sinfg::ProgressCallback *callback=NULL); 
45
46 //! Sets the localized name of the module
47 #define MODULE_NAME(x)                  virtual const char * Name() { return x; }
48
49 //! Sets a localized description of the module
50 #define MODULE_DESCRIPTION(x)   virtual const char * Desc() { return x; }
51
52 //! Sets the name of the module's author
53 #define MODULE_AUTHOR(x)                virtual const char * Author() { return x; }
54
55 //! Sets the version string for the module
56 #define MODULE_VERSION(x)               virtual const char * Version() { return x; }
57
58 //! Sets the copyright string for the module
59 #define MODULE_COPYRIGHT(x)             virtual const char * Copyright() { return x; }
60
61 //! Describes the module's construction function
62 #define MODULE_CONSTRUCTOR(x)   bool constructor_(sinfg::ProgressCallback *cb) { return x(cb); }
63
64 //! Describes the module's destruction function
65 #define MODULE_DESTRUCTOR(x)    virtual void destructor_() { return x(); }
66
67 //! Marks the end of a module description
68 #define MODULE_DESC_END };
69
70 //#if 0
71 #ifdef __APPLE__
72 //! Marks the start of a module's inventory
73 #define MODULE_INVENTORY_BEGIN(x)  extern "C" {         \
74         sinfg::Module* _##x##_LTX_new_instance(sinfg::ProgressCallback *cb) \
75         { if(SINFG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
76         if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
77         }; x##_modclass::x##_modclass(sinfg::ProgressCallback *cb) { 
78 #else
79 //! Marks the start of a module's inventory
80 #define MODULE_INVENTORY_BEGIN(x)  extern "C" {         \
81         sinfg::Module* x##_LTX_new_instance(sinfg::ProgressCallback *cb) \
82         { if(SINFG_CHECK_VERSION()){x##_modclass *mod=new x##_modclass(cb); mod->constructor_(cb); return mod; }\
83         if(cb)cb->error(#x": Unable to load module due to version mismatch."); return NULL; } \
84         }; x##_modclass::x##_modclass(sinfg::ProgressCallback *cb) { 
85 #endif
86
87 //! Marks the start of the layers in the module's inventory
88 #define BEGIN_LAYERS {
89
90 //! DEPRECATED - use @INCLUDE_LAYER()
91 //#define LAYER(x) sinfg::Layer::book()[sinfg::String(x::name__)]=x::create;
92 #define LAYER(class)    sinfg::Layer::register_in_book(sinfg::Layer::BookEntry(class::create,class::name__,class::local_name__,class::category__,class::cvs_id__,class::version__));
93 #define LAYER_ALIAS(class,alias)        sinfg::Layer::register_in_book(sinfg::Layer::BookEntry(class::create,alias,alias,_("Do Not Use"),class::cvs_id__,class::version__));
94
95 //! Marks the end of the layers in the module's inventory
96 #define END_LAYERS }
97
98 //! Marks the start of the targets in the module's inventory
99 #define BEGIN_TARGETS {
100
101 #define TARGET(x) sinfg::Target::book()[sinfg::String(x::name__)]=std::pair<sinfg::Target::Factory,sinfg::String>(x::create,sinfg::String(x::ext__));sinfg::Target::ext_book()[sinfg::String(x::ext__)]=x::name__;
102
103 #define TARGET_EXT(x,y) sinfg::Target::ext_book()[sinfg::String(y)]=x::name__;
104
105 //! Marks the end of the targets in the module's inventory
106 #define END_TARGETS }
107
108 //! Marks the start of the importers in the module's inventory
109 #define BEGIN_IMPORTERS {
110
111 #define IMPORTER(x) sinfg::Importer::book()[sinfg::String(x::ext__)]=x::create;
112
113 #define IMPORTER_EXT(x,y) sinfg::Importer::book()[sinfg::String(y)]=x::create;
114
115 //! Marks the end of the importers in the module's inventory
116 #define END_IMPORTERS }
117
118 //! Marks the end of a module's inventory
119 #define MODULE_INVENTORY_END    }
120
121 /* === T Y P E D E F S ===================================================== */
122
123 /* === C L A S S E S & S T R U C T S ======================================= */
124
125 namespace sinfg {
126
127 class ProgressCallback;
128
129 /*!     \class Module
130 **      \todo writeme
131 */
132 class Module : public etl::shared_object
133 {
134 public:
135         bool constructor_(sinfg::ProgressCallback *cb) { return true; }
136         virtual void destructor_() { }
137         
138         typedef etl::handle<Module> Handle;
139         typedef etl::loose_handle<Module> LooseHandle;
140         typedef etl::handle<const Module> ConstHandle;
141         
142 public:
143         typedef Module*(*constructor_type)(ProgressCallback *);
144         typedef std::map<String, Handle > Book;
145 private:
146         static Book* book_;
147 public:
148         static Book& book();
149
150         static bool subsys_init(const String &prefix);
151         static bool subsys_stop();
152         static bool register_default_modules();
153
154         static void Register(Handle mod);
155         static bool Register(const String &module_name, ProgressCallback *cb=NULL);
156         static inline void Register(Module *mod) { Register(Handle(mod)); }
157         
158         virtual const char * Name() { return " "; }
159         virtual const char * Desc() { return " "; }
160         virtual const char * Author() { return " "; }
161         virtual const char * Version() { return " "; }
162         virtual const char * Copyright() { return SINFG_COPYRIGHT; }
163
164         virtual ~Module() { destructor_(); }
165 };
166
167 }; // END of namespace sinfg
168
169 /* === E N D =============================================================== */
170
171 #endif