1 /* === S Y N F I G ========================================================= */
3 ** \brief Header file for implementation of the "Placeholder" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_VALUENODE_H
26 #define __SYNFIG_VALUENODE_H
28 /* === H E A D E R S ======================================================= */
34 #include <ETL/stringf>
35 #include "exception.h"
37 #include <sigc++/signal.h>
40 #ifndef SYNFIG_NO_ANGLE
48 /* === M A C R O S ========================================================= */
50 // This is a hack for GCC 3.0.4... which has a broken dynamic_cast<>
51 // It is deprecated, and will be removed soon.
52 #if ( __GNUC__ == 3 ) && ( __GNUC__MINOR__ == 0 )
53 # define DCAST_HACK_BASECLASS() int cast__
54 # define DCAST_HACK_ID(x) static const int my_cast__(void) { return x; }
55 # define DCAST_HACK_ENABLE() cast__=my_cast__()
57 # define DCAST_HACK_BASECLASS()
58 # define DCAST_HACK_ID(x)
59 # define DCAST_HACK_ENABLE()
62 #define CHECK_TYPE_AND_SET_VALUE(variable, type) \
63 /* I don't think this ever happens - maybe remove this code? */ \
64 if (get_type() == ValueBase::TYPE_NIL) { \
65 warning("%s:%d get_type() IS nil sometimes!", \
66 __FILE__, __LINE__); \
69 if (get_type() != ValueBase::TYPE_NIL && \
70 !(ValueBase::same_type_as(value->get_type(), type)) && \
71 !PlaceholderValueNode::Handle::cast_dynamic(value)) { \
72 error(_("%s:%d wrong type for %s: need %s but got %s"), \
74 link_local_name(i).c_str(), \
75 ValueBase::type_local_name(type).c_str(), \
76 ValueBase::type_local_name(value->get_type()).c_str()); \
80 signal_child_changed()(i); \
81 signal_value_changed()(); \
84 /* === T Y P E D E F S ===================================================== */
86 /* === C L A S S E S & S T R U C T S ======================================= */
91 class LinkableValueNode;
97 class ValueNode : public synfig::Node
100 friend class LinkableValueNode;
103 -- ** -- T Y P E S -----------------------------------------------------------
108 typedef etl::handle<ValueNode> Handle;
110 typedef etl::loose_handle<ValueNode> LooseHandle;
112 typedef etl::handle<const ValueNode> ConstHandle;
114 typedef etl::rhandle<ValueNode> RHandle;
117 static bool subsys_init();
119 static bool subsys_stop();
122 -- ** -- D A T A -------------------------------------------------------------
126 ValueBase::Type type;
128 etl::loose_handle<Canvas> canvas_;
129 etl::loose_handle<Canvas> root_canvas_;
132 -- ** -- S I G N A L S -------------------------------------------------------
137 //! ValueBase Changed
138 sigc::signal<void> signal_value_changed_;
140 //! Children Reordered
141 sigc::signal<void,int*> signal_children_reordered_;
144 sigc::signal<void,int> signal_child_changed_;
147 sigc::signal<void,int> signal_child_removed_;
150 sigc::signal<void,int> signal_child_inserted_;
153 sigc::signal<void> signal_id_changed_;
156 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
161 //! ValueBase Changed
162 sigc::signal<void>& signal_value_changed() { return signal_value_changed_; }
164 //! Children Reordered
165 sigc::signal<void,int*>& signal_children_reordered() { return signal_children_reordered_; }
168 sigc::signal<void,int>& signal_child_changed() { return signal_child_changed_; }
171 sigc::signal<void,int>& signal_child_removed() { return signal_child_removed_; }
174 sigc::signal<void,int>& signal_child_inserted() { return signal_child_inserted_; }
177 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
180 -- ** -- C O N S T R U C T O R S ---------------------------------------------
185 ValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
189 virtual ~ValueNode();
192 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
197 //! Returns the value of the ValueNode at time \a t
198 virtual ValueBase operator()(Time /*t*/)const
199 { return ValueBase(); }
201 //! \internal Sets the id of the ValueNode
202 void set_id(const String &x);
204 //! Returns the id of the ValueNode
205 /*! The ID is used for keeping track of a
206 ** specific instance of a ValueNode. */
207 const String &get_id()const { return name; }
209 //! Returns the name of the ValueNode type
210 virtual String get_name()const=0;
212 //! Returns the localized name of the ValueNode type
213 virtual String get_local_name()const=0;
217 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
220 bool is_exported()const { return !get_id().empty(); }
222 //! Returns the type of the ValueNode
223 ValueBase::Type get_type()const { return type; }
225 //! Returns a handle to the parent canvas, if it has one.
226 etl::loose_handle<Canvas> get_parent_canvas()const { return canvas_; }
228 //! Returns a handle to the parent canvas, if it has one.
229 etl::loose_handle<Canvas> get_root_canvas()const { return root_canvas_; }
232 void set_parent_canvas(etl::loose_handle<Canvas> x);
235 void set_root_canvas(etl::loose_handle<Canvas> x);
238 String get_relative_id(etl::loose_handle<const Canvas> x)const;
240 int replace(etl::handle<ValueNode> x);
243 //! Sets the type of the ValueNode
244 void set_type(ValueBase::Type t) { type=t; }
246 virtual void on_changed();
249 DCAST_HACK_BASECLASS();
251 }; // END of class ValueNode
253 /*! \class PlaceholderValueNode
256 class PlaceholderValueNode : public ValueNode
259 typedef etl::handle<PlaceholderValueNode> Handle;
260 typedef etl::loose_handle<PlaceholderValueNode> LooseHandle;
261 typedef etl::handle<const PlaceholderValueNode> ConstHandle;
262 typedef etl::rhandle<PlaceholderValueNode> RHandle;
266 PlaceholderValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
270 virtual ValueBase operator()(Time t)const;
272 virtual String get_name()const;
274 virtual String get_local_name()const;
276 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
278 static Handle create(ValueBase::Type type=ValueBase::TYPE_NIL);
281 virtual void get_times_vfunc(Node::time_set &/*set*/) const {}
282 }; // END of class PlaceholderValueNode
285 /*! \class LinkableValueNode
288 class LinkableValueNode : public ValueNode
290 friend class ValueNode;
293 typedef etl::handle<LinkableValueNode> Handle;
295 typedef etl::loose_handle<LinkableValueNode> LooseHandle;
297 typedef etl::handle<const LinkableValueNode> ConstHandle;
299 typedef etl::rhandle<LinkableValueNode> RHandle;
302 //! Type that represents a pointer to a ValueNode's constructor
303 typedef LinkableValueNode* (*Factory)(const ValueBase&);
305 typedef bool (*CheckType)(ValueBase::Type);
311 CheckType check_type;
314 typedef std::map<String,BookEntry> Book;
318 static Handle create(const String &name, const ValueBase& x);
320 static bool check_type(const String &name, ValueBase::Type x);
323 LinkableValueNode(ValueBase::Type type=ValueBase::TYPE_NIL):
327 virtual bool set_link_vfunc(int i,ValueNode::Handle x)=0;
333 virtual int link_count()const=0;
335 virtual String link_local_name(int i)const=0;
337 virtual String link_name(int i)const=0;
339 virtual int get_link_index_from_name(const String &name)const=0;
341 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
343 bool set_link(int i,ValueNode::Handle x);
344 bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x); }
346 ValueNode::LooseHandle get_link(int i)const;
347 ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
350 //! Sets the type of the ValueNode
351 void set_type(ValueBase::Type t) { ValueNode::set_type(t); }
353 virtual ValueNode::LooseHandle get_link_vfunc(int i)const=0;
355 // Wrapper for new operator, used by clone()
356 virtual LinkableValueNode* create_new()const=0;
358 virtual void get_times_vfunc(Node::time_set &set) const;
359 }; // END of class LinkableValueNode
361 /*! \class ValueNodeList
362 ** \brief A searchable value_node list container
363 ** \warning Do not confuse with ValueNode_DynamicList!
366 class ValueNodeList : public std::list<ValueNode::RHandle>
368 int placeholder_count_;
372 //! Finds the ValueNode in the list with the given \a name
373 /*! \return If found, returns a handle to the ValueNode.
374 ** Otherwise, returns an empty handle.
376 ValueNode::Handle find(const String &name);
378 //! Finds the ValueNode in the list with the given \a name
379 /*! \return If found, returns a handle to the ValueNode.
380 ** Otherwise, returns an empty handle.
382 ValueNode::ConstHandle find(const String &name)const;
384 //! Removes the \a value_node from the list
385 bool erase(ValueNode::Handle value_node);
388 bool add(ValueNode::Handle value_node);
391 bool count(const String &id)const;
393 //! Similar to find, but will create a placeholder value_node if it cannot be found.
394 ValueNode::Handle surefind(const String &name);
396 //! Removes any value_nodes with reference counts of 1.
399 //! Placeholder Count
400 int placeholder_count()const { return placeholder_count_; }
403 ValueNode::LooseHandle find_value_node(const GUID& guid);
405 }; // END of namespace synfig
407 /* === E N D =============================================================== */