Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07 / src / synfigapp / action_param.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file action_param.h
3 **      \brief Template File
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_APP_ACTION_PARAM_H
26 #define __SYNFIG_APP_ACTION_PARAM_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <synfig/string.h>
31 #include <synfig/canvas.h>
32 #include <ETL/handle>
33 #include <ETL/stringf>
34 #include <ETL/trivial>
35
36 #include <map>
37 #include <list>
38
39 #include <synfig/layer.h>
40 #include <synfig/canvas.h>
41 #include <synfig/valuenode.h>
42 #include <synfigapp/value_desc.h>
43 #include <synfig/value.h>
44 #include <synfig/activepoint.h>
45 #include <synfig/valuenode_animated.h>
46 #include <synfig/string.h>
47 #include <synfig/keyframe.h>
48 #include <synfig/waypoint.h>
49
50 #include "editmode.h"
51
52 /* === M A C R O S ========================================================= */
53
54 /* === T Y P E D E F S ===================================================== */
55
56 /* === C L A S S E S & S T R U C T S ======================================= */
57
58 namespace synfig {
59 class ProgressCallback;
60 class Canvas;
61 class RendDesc;
62 }; // END of namespace synfig
63
64 namespace synfigapp {
65
66 class CanvasInterface;
67
68 namespace Action {
69
70 //! Action Parameter
71 class Param
72 {
73 public:
74         enum Type
75         {
76                 TYPE_NIL,
77                 TYPE_INTEGER,
78                 TYPE_REAL,
79                 TYPE_BOOL,
80                 TYPE_ACTIVEPOINT,
81                 TYPE_WAYPOINT,
82                 TYPE_WAYPOINTMODEL,
83                 TYPE_KEYFRAME,
84                 TYPE_CANVAS,
85                 TYPE_LAYER,
86                 TYPE_VALUENODE,
87                 TYPE_VALUEDESC,
88                 TYPE_VALUE,
89                 TYPE_STRING,
90                 TYPE_TIME,
91                 TYPE_CANVASINTERFACE,
92                 TYPE_EDITMODE,
93                 TYPE_RENDDESC,
94
95                 TYPE_END
96         };
97 private:
98         Type type_;
99
100         union
101         {
102                 etl::trivial<synfig::Canvas::LooseHandle> canvas;
103                 etl::trivial<synfig::Layer::LooseHandle> layer;
104                 etl::trivial<synfig::ValueNode::LooseHandle> value_node;
105                 etl::trivial<synfig::ValueBase> value;
106                 etl::trivial<synfig::Activepoint> activepoint;
107                 etl::trivial<synfig::ValueNode_Animated::Waypoint> waypoint;
108                 etl::trivial<synfig::ValueNode_Animated::Waypoint::Model> waypoint_model;
109                 etl::trivial<synfig::String> string;
110                 etl::trivial<synfig::Keyframe> keyframe;
111                 etl::trivial<synfig::Time> time;
112                 etl::trivial<synfigapp::ValueDesc> value_desc;
113                 etl::trivial<etl::loose_handle<synfigapp::CanvasInterface> > canvas_interface;
114                 etl::trivial<synfig::RendDesc> rend_desc;
115                 int integer;
116                 synfig::Real real;
117                 bool b;
118                 EditMode edit_mode;
119
120         } data;
121 public:
122
123         Param():type_(TYPE_NIL) { }
124         Param(const Param &x);
125         Param(const etl::handle<synfigapp::CanvasInterface>& x);
126         Param(const etl::loose_handle<synfigapp::CanvasInterface>& x);
127 //      Param(synfigapp::CanvasInterface* x);
128         Param(const synfig::Canvas::Handle& x);
129         Param(const synfig::Canvas::LooseHandle& x);
130         Param(const synfig::Layer::Handle& x);
131         Param(const synfig::Layer::LooseHandle& x);
132         Param(const synfig::ValueNode::Handle& x);
133         Param(const synfig::ValueNode::LooseHandle& x);
134         Param(const synfig::Activepoint& x);
135         Param(const synfig::Waypoint& x);
136         Param(const synfig::Waypoint::Model& x);
137         Param(const synfig::String& x);
138         Param(const synfig::RendDesc& x);
139         Param(const char * x);
140         Param(const synfig::Keyframe& x);
141         Param(const synfigapp::ValueDesc& x);
142         Param(const int& x);
143         Param(const EditMode& x);
144         Param(const synfig::Real& x);
145         Param(const synfig::Time& x);
146         Param(const bool& x);
147         Param(const synfig::ValueBase& x);
148
149         ~Param();
150
151         Param& operator=(const Param& rhs);
152
153         void clear();
154
155         const synfig::Canvas::LooseHandle& get_canvas()const { assert(type_==TYPE_CANVAS); return data.canvas.get(); }
156         const etl::loose_handle<synfigapp::CanvasInterface>& get_canvas_interface()const { assert(type_==TYPE_CANVASINTERFACE); return data.canvas_interface.get(); }
157         const synfig::Layer::LooseHandle& get_layer()const { assert(type_==TYPE_LAYER); return data.layer.get(); }
158         const synfig::ValueNode::LooseHandle& get_value_node()const { assert(type_==TYPE_VALUENODE); return data.value_node.get(); }
159         const synfig::ValueBase& get_value()const { assert(type_==TYPE_VALUE); return data.value.get(); }
160         const synfig::Activepoint& get_activepoint()const { assert(type_==TYPE_ACTIVEPOINT); return data.activepoint.get(); }
161         const synfig::Waypoint& get_waypoint()const { assert(type_==TYPE_WAYPOINT); return data.waypoint.get(); }
162         const synfig::Waypoint::Model& get_waypoint_model()const { assert(type_==TYPE_WAYPOINTMODEL); return data.waypoint_model.get(); }
163         const synfig::String& get_string()const { assert(type_==TYPE_STRING); return data.string.get(); }
164         const synfig::Keyframe& get_keyframe()const { assert(type_==TYPE_KEYFRAME); return data.keyframe.get(); }
165         const synfigapp::ValueDesc& get_value_desc()const { assert(type_==TYPE_VALUEDESC); return data.value_desc.get(); }
166         const synfig::Real& get_real()const { assert(type_==TYPE_REAL); return data.real; }
167         const synfig::Time& get_time()const { assert(type_==TYPE_TIME); return data.time.get(); }
168         const synfig::RendDesc& get_rend_desc()const { assert(type_==TYPE_RENDDESC); return data.rend_desc.get(); }
169         int get_integer()const { assert(type_==TYPE_INTEGER); return data.integer; }
170         EditMode get_edit_mode()const { assert(type_==TYPE_EDITMODE); return data.edit_mode; }
171         bool get_bool()const { assert(type_==TYPE_BOOL); return data.b; }
172
173
174         const Type& get_type()const { return type_; }
175 }; // END of class Param
176
177 class ParamList : public std::multimap<synfig::String,Param>
178 {
179 public:
180         ParamList& add(const synfig::String& name, const Param &x) { insert(std::pair<synfig::String,Param>(name,x)); return *this; }
181         ParamList& add(const ParamList& x) { insert(x.begin(),x.end()); return *this; }
182 }; // END of class ParamList
183
184 class ParamDesc
185 {
186 private:
187         synfig::String  name_;
188         synfig::String  local_name_;
189         synfig::String  desc_;
190         synfig::String  mutual_exclusion_;
191         Param::Type     type_;
192         bool    user_supplied_;
193         bool    supports_multiple_;
194         bool    requires_multiple_;
195         bool    optional_;
196
197 public:
198         ParamDesc(const synfig::String &name, Param::Type type):
199                 name_(name),
200                 local_name_(name),
201                 type_(type),
202                 user_supplied_(false),
203                 supports_multiple_(false),
204                 requires_multiple_(false),
205                 optional_(false)
206         { }
207
208         const synfig::String& get_name()const { return name_; }
209         const synfig::String& get_desc()const { return desc_; }
210         const synfig::String& get_mutual_exclusion()const { return mutual_exclusion_; }
211         const synfig::String& get_local_name()const { return local_name_; }
212         const Param::Type& get_type()const { return type_; }
213         bool get_user_supplied()const { return user_supplied_; }
214         bool get_supports_multiple()const { return supports_multiple_||requires_multiple_; }
215         bool get_requires_multiple()const { return requires_multiple_; }
216         bool get_optional()const { return optional_; }
217
218         ParamDesc& set_local_name(const synfig::String& x) { local_name_=x; return *this; }
219         ParamDesc& set_desc(const synfig::String& x) { desc_=x; return *this; }
220         ParamDesc& set_mutual_exclusion(const synfig::String& x) { mutual_exclusion_=x; return *this; }
221         ParamDesc& set_user_supplied(bool x=true) { user_supplied_=x; return *this; }
222         ParamDesc& set_supports_multiple(bool x=true) { supports_multiple_=x; return *this; }
223         ParamDesc& set_requires_multiple(bool x=true) { requires_multiple_=x; if(x)supports_multiple_=true; return *this; }
224         ParamDesc& set_optional(bool x=true) { optional_=x; return *this; }
225 }; // END of class ParamDesc
226
227 class ParamVocab : public std::list< ParamDesc > { };
228
229 bool candidate_check(const ParamVocab& param_vocab, const ParamList& param_list);
230
231 }; // END of namespace Action
232
233 }; // END of namespace synfigapp
234
235 /* === E N D =============================================================== */
236
237 #endif