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 /* === T Y P E D E F S ===================================================== */
64 /* === C L A S S E S & S T R U C T S ======================================= */
69 class LinkableValueNode;
75 class ValueNode : public synfig::Node
78 friend class LinkableValueNode;
81 -- ** -- T Y P E S -----------------------------------------------------------
86 typedef etl::handle<ValueNode> Handle;
88 typedef etl::loose_handle<ValueNode> LooseHandle;
90 typedef etl::handle<const ValueNode> ConstHandle;
92 typedef etl::rhandle<ValueNode> RHandle;
95 static bool subsys_init();
97 static bool subsys_stop();
100 -- ** -- D A T A -------------------------------------------------------------
104 ValueBase::Type type;
106 etl::loose_handle<Canvas> canvas_;
107 etl::loose_handle<Canvas> root_canvas_;
110 -- ** -- S I G N A L S -------------------------------------------------------
115 //! ValueBase Changed
116 sigc::signal<void> signal_value_changed_;
118 //! Children Reordered
119 sigc::signal<void,int*> signal_children_reordered_;
122 sigc::signal<void,int> signal_child_changed_;
125 sigc::signal<void,int> signal_child_removed_;
128 sigc::signal<void,int> signal_child_inserted_;
131 sigc::signal<void> signal_id_changed_;
134 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
139 //! ValueBase Changed
140 sigc::signal<void>& signal_value_changed() { return signal_value_changed_; }
142 //! Children Reordered
143 sigc::signal<void,int*>& signal_children_reordered() { return signal_children_reordered_; }
146 sigc::signal<void,int>& signal_child_changed() { return signal_child_changed_; }
149 sigc::signal<void,int>& signal_child_removed() { return signal_child_removed_; }
152 sigc::signal<void,int>& signal_child_inserted() { return signal_child_inserted_; }
155 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
158 -- ** -- C O N S T R U C T O R S ---------------------------------------------
163 ValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
167 virtual ~ValueNode();
170 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
175 //! Returns the value of the ValueNode at time \a t
176 virtual ValueBase operator()(Time /*t*/)const
177 { return ValueBase(); }
179 //! \internal Sets the id of the ValueNode
180 void set_id(const String &x);
182 //! Returns the id of the ValueNode
183 /*! The ID is used for keeping track of a
184 ** specific instance of a ValueNode. */
185 const String &get_id()const { return name; }
187 //! Returns the name of the ValueNode type
188 virtual String get_name()const=0;
190 //! Returns the localized name of the ValueNode type
191 virtual String get_local_name()const=0;
195 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
198 bool is_exported()const { return !get_id().empty(); }
200 //! Returns the type of the ValueNode
201 ValueBase::Type get_type()const { return type; }
203 //! Returns a handle to the parent canvas, if it has one.
204 etl::loose_handle<Canvas> get_parent_canvas()const { return canvas_; }
206 //! Returns a handle to the parent canvas, if it has one.
207 etl::loose_handle<Canvas> get_root_canvas()const { return root_canvas_; }
210 void set_parent_canvas(etl::loose_handle<Canvas> x);
213 void set_root_canvas(etl::loose_handle<Canvas> x);
216 String get_relative_id(etl::loose_handle<const Canvas> x)const;
218 int replace(etl::handle<ValueNode> x);
221 //! Sets the type of the ValueNode
222 void set_type(ValueBase::Type t) { type=t; }
224 virtual void on_changed();
227 DCAST_HACK_BASECLASS();
229 }; // END of class ValueNode
231 /*! \class PlaceholderValueNode
234 class PlaceholderValueNode : public ValueNode
237 typedef etl::handle<PlaceholderValueNode> Handle;
238 typedef etl::loose_handle<PlaceholderValueNode> LooseHandle;
239 typedef etl::handle<const PlaceholderValueNode> ConstHandle;
240 typedef etl::rhandle<PlaceholderValueNode> RHandle;
244 PlaceholderValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
248 virtual ValueBase operator()(Time t)const;
250 virtual String get_name()const;
252 virtual String get_local_name()const;
254 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
256 static Handle create(ValueBase::Type type=ValueBase::TYPE_NIL);
259 virtual void get_times_vfunc(Node::time_set &/*set*/) const {}
260 }; // END of class PlaceholderValueNode
263 /*! \class LinkableValueNode
266 class LinkableValueNode : public ValueNode
268 friend class ValueNode;
271 typedef etl::handle<LinkableValueNode> Handle;
273 typedef etl::loose_handle<LinkableValueNode> LooseHandle;
275 typedef etl::handle<const LinkableValueNode> ConstHandle;
277 typedef etl::rhandle<LinkableValueNode> RHandle;
280 //! Type that represents a pointer to a ValueNode's constructor
281 typedef LinkableValueNode* (*Factory)(const ValueBase&);
283 typedef bool (*CheckType)(ValueBase::Type);
289 CheckType check_type;
292 typedef std::map<String,BookEntry> Book;
296 static Handle create(const String &name, const ValueBase& x);
298 static bool check_type(const String &name, ValueBase::Type x);
301 LinkableValueNode(ValueBase::Type type=ValueBase::TYPE_NIL):
305 virtual bool set_link_vfunc(int i,ValueNode::Handle x)=0;
311 virtual int link_count()const=0;
313 virtual String link_local_name(int i)const=0;
315 virtual String link_name(int i)const=0;
317 virtual int get_link_index_from_name(const String &name)const=0;
319 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
321 bool set_link(int i,ValueNode::Handle x);
322 bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x); }
324 ValueNode::LooseHandle get_link(int i)const;
325 ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
328 //! Sets the type of the ValueNode
329 void set_type(ValueBase::Type t) { ValueNode::set_type(t); }
331 virtual ValueNode::LooseHandle get_link_vfunc(int i)const=0;
333 // Wrapper for new operator, used by clone()
334 virtual LinkableValueNode* create_new()const=0;
336 virtual void get_times_vfunc(Node::time_set &set) const;
337 }; // END of class LinkableValueNode
339 /*! \class ValueNodeList
340 ** \brief A searchable value_node list container
341 ** \warning Do not confuse with ValueNode_DynamicList!
344 class ValueNodeList : public std::list<ValueNode::RHandle>
346 int placeholder_count_;
350 //! Finds the ValueNode in the list with the given \a name
351 /*! \return If found, returns a handle to the ValueNode.
352 ** Otherwise, returns an empty handle.
354 ValueNode::Handle find(const String &name);
356 //! Finds the ValueNode in the list with the given \a name
357 /*! \return If found, returns a handle to the ValueNode.
358 ** Otherwise, returns an empty handle.
360 ValueNode::ConstHandle find(const String &name)const;
362 //! Removes the \a value_node from the list
363 bool erase(ValueNode::Handle value_node);
366 bool add(ValueNode::Handle value_node);
369 bool count(const String &id)const;
371 //! Similar to find, but will create a placeholder value_node if it cannot be found.
372 ValueNode::Handle surefind(const String &name);
374 //! Removes any value_nodes with reference counts of 1.
377 //! Placeholder Count
378 int placeholder_count()const { return placeholder_count_; }
381 ValueNode::LooseHandle find_value_node(const GUID& guid);
383 }; // END of namespace synfig
385 /* === E N D =============================================================== */