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