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
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_VALUENODE_H
27 #define __SYNFIG_VALUENODE_H
29 /* === H E A D E R S ======================================================= */
36 #include <ETL/stringf>
37 #include "exception.h"
39 #include <sigc++/signal.h>
47 /* === M A C R O S ========================================================= */
49 #define CHECK_TYPE_AND_SET_VALUE(variable, type) \
50 /* I don't think this ever happens - maybe remove this code? */ \
51 if (get_type() == ValueBase::TYPE_NIL) { \
52 warning("%s:%d get_type() IS nil sometimes!", \
53 __FILE__, __LINE__); \
56 if (get_type() != ValueBase::TYPE_NIL && \
57 !(ValueBase::same_type_as(value->get_type(), type)) && \
58 !PlaceholderValueNode::Handle::cast_dynamic(value)) { \
59 error(_("%s:%d wrong type for %s: need %s but got %s"), \
61 link_local_name(i).c_str(), \
62 ValueBase::type_local_name(type).c_str(), \
63 ValueBase::type_local_name(value->get_type()).c_str()); \
67 signal_child_changed()(i); \
68 signal_value_changed()(); \
71 /* === T Y P E D E F S ===================================================== */
73 /* === C L A S S E S & S T R U C T S ======================================= */
78 class LinkableValueNode;
84 class ValueNode : public synfig::Node
87 friend class LinkableValueNode;
90 -- ** -- T Y P E S -----------------------------------------------------------
95 typedef etl::handle<ValueNode> Handle;
97 typedef etl::loose_handle<ValueNode> LooseHandle;
99 typedef etl::handle<const ValueNode> ConstHandle;
101 typedef etl::rhandle<ValueNode> RHandle;
104 static bool subsys_init();
106 static bool subsys_stop();
109 -- ** -- D A T A -------------------------------------------------------------
113 ValueBase::Type type;
115 etl::loose_handle<Canvas> canvas_;
116 etl::loose_handle<Canvas> root_canvas_;
119 -- ** -- S I G N A L S -------------------------------------------------------
124 //! ValueBase Changed
125 sigc::signal<void> signal_value_changed_;
127 //! Children Reordered
128 sigc::signal<void,int*> signal_children_reordered_;
131 sigc::signal<void,int> signal_child_changed_;
134 sigc::signal<void,int> signal_child_removed_;
137 sigc::signal<void,int> signal_child_inserted_;
140 sigc::signal<void> signal_id_changed_;
143 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
148 //! ValueBase Changed
149 sigc::signal<void>& signal_value_changed() { return signal_value_changed_; }
151 //! Children Reordered
152 sigc::signal<void,int*>& signal_children_reordered() { return signal_children_reordered_; }
155 sigc::signal<void,int>& signal_child_changed() { return signal_child_changed_; }
158 sigc::signal<void,int>& signal_child_removed() { return signal_child_removed_; }
161 sigc::signal<void,int>& signal_child_inserted() { return signal_child_inserted_; }
164 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
167 -- ** -- C O N S T R U C T O R S ---------------------------------------------
172 ValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
176 virtual ~ValueNode();
179 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
184 //! Returns the value of the ValueNode at time \a t
185 virtual ValueBase operator()(Time /*t*/)const
186 { return ValueBase(); }
188 //! \internal Sets the id of the ValueNode
189 void set_id(const String &x);
191 //! Returns the id of the ValueNode
192 /*! The ID is used for keeping track of a
193 ** specific instance of a ValueNode. */
194 const String &get_id()const { return name; }
196 //! Returns the name of the ValueNode type
197 virtual String get_name()const=0;
199 //! Returns the localized name of the ValueNode type
200 virtual String get_local_name()const=0;
202 //! Return a full description of the ValueNode and its parentage
203 virtual String get_description(bool show_exported_name = true)const;
207 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
210 bool is_exported()const { return !get_id().empty(); }
212 //! Returns the type of the ValueNode
213 ValueBase::Type get_type()const { return type; }
215 //! Returns a handle to the parent canvas, if it has one.
216 etl::loose_handle<Canvas> get_parent_canvas()const { return canvas_; }
218 //! Returns a handle to the parent canvas, if it has one.
219 etl::loose_handle<Canvas> get_root_canvas()const { return root_canvas_; }
222 void set_parent_canvas(etl::loose_handle<Canvas> x);
225 void set_root_canvas(etl::loose_handle<Canvas> x);
228 String get_relative_id(etl::loose_handle<const Canvas> x)const;
230 int replace(etl::handle<ValueNode> x);
233 //! Sets the type of the ValueNode
234 void set_type(ValueBase::Type t) { type=t; }
236 virtual void on_changed();
237 }; // END of class ValueNode
239 /*! \class PlaceholderValueNode
242 class PlaceholderValueNode : public ValueNode
245 typedef etl::handle<PlaceholderValueNode> Handle;
246 typedef etl::loose_handle<PlaceholderValueNode> LooseHandle;
247 typedef etl::handle<const PlaceholderValueNode> ConstHandle;
248 typedef etl::rhandle<PlaceholderValueNode> RHandle;
252 PlaceholderValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
256 virtual ValueBase operator()(Time t)const;
258 virtual String get_name()const;
260 virtual String get_local_name()const;
262 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
264 static Handle create(ValueBase::Type type=ValueBase::TYPE_NIL);
267 virtual void get_times_vfunc(Node::time_set &/*set*/) const {}
268 }; // END of class PlaceholderValueNode
271 /*! \class LinkableValueNode
274 class LinkableValueNode : public ValueNode
276 friend class ValueNode;
279 typedef etl::handle<LinkableValueNode> Handle;
281 typedef etl::loose_handle<LinkableValueNode> LooseHandle;
283 typedef etl::handle<const LinkableValueNode> ConstHandle;
285 typedef etl::rhandle<LinkableValueNode> RHandle;
288 //! Type that represents a pointer to a ValueNode's constructor
289 /*! As a pointer to the constructor, it represents a "factory" of
290 ** objects of this class.
292 typedef LinkableValueNode* (*Factory)(const ValueBase&);
294 //! This represents a pointer to a Type check member fucntion
295 /*! As a pointer to the member, it represents a fucntion that checks
296 ** the type of the provided ValueBase
298 typedef bool (*CheckType)(ValueBase::Type);
304 CheckType check_type;
305 ReleaseVersion release_version; // which version of synfig introduced this valuenode type
308 //! Book of types of linkable value nodes indexed by type name.
309 /*! While the sifz file is read, each time a new LinkableValueNode entry
310 ** is found, the factory constructor that the "factory" pointer member
311 ** of the "BookEntry" struct points to, is called, and a new object of
312 ** that type is created.
313 ** \sa LinkableValueNode::Factory
315 typedef std::map<String,BookEntry> Book;
319 static Handle create(const String &name, const ValueBase& x);
321 static bool check_type(const String &name, ValueBase::Type x);
324 LinkableValueNode(ValueBase::Type type=ValueBase::TYPE_NIL):
328 virtual bool set_link_vfunc(int i,ValueNode::Handle x)=0;
334 virtual int link_count()const=0;
336 virtual String link_local_name(int i)const=0;
338 virtual String link_name(int i)const=0;
340 virtual int get_link_index_from_name(const String &name)const=0;
342 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
344 bool set_link(int i,ValueNode::Handle x);
345 bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x); }
347 ValueNode::LooseHandle get_link(int i)const;
348 ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
351 get_description(int index = -1, bool show_exported_name = true)const;
354 //! Sets the type of the ValueNode
355 void set_type(ValueBase::Type t) { ValueNode::set_type(t); }
357 virtual ValueNode::LooseHandle get_link_vfunc(int i)const=0;
359 // Wrapper for new operator, used by clone()
360 virtual LinkableValueNode* create_new()const=0;
362 virtual void get_times_vfunc(Node::time_set &set) const;
363 }; // END of class LinkableValueNode
365 /*! \class ValueNodeList
366 ** \brief A searchable value_node list container
367 ** \warning Do not confuse with ValueNode_DynamicList!
370 class ValueNodeList : public std::list<ValueNode::RHandle>
372 int placeholder_count_;
376 //! Finds the ValueNode in the list with the given \a name
377 /*! \return If found, returns a handle to the ValueNode.
378 ** Otherwise, returns an empty handle.
380 ValueNode::Handle find(const String &name);
382 //! Finds the ValueNode in the list with the given \a name
383 /*! \return If found, returns a handle to the ValueNode.
384 ** Otherwise, returns an empty handle.
386 ValueNode::ConstHandle find(const String &name)const;
388 //! Removes the \a value_node from the list
389 bool erase(ValueNode::Handle value_node);
392 bool add(ValueNode::Handle value_node);
395 bool count(const String &id)const;
397 //! Similar to find, but will create a placeholder value_node if it cannot be found.
398 ValueNode::Handle surefind(const String &name);
400 //! Removes any value_nodes with reference counts of 1.
403 //! Placeholder Count
404 int placeholder_count()const { return placeholder_count_; }
407 ValueNode::LooseHandle find_value_node(const GUID& guid);
409 }; // END of namespace synfig
411 /* === E N D =============================================================== */