1 /* === S I N F G =========================================================== */
3 ** \brief Template Header
5 ** $Id: valuenode.h,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_VALUENODE_H
25 #define __SINFG_VALUENODE_H
27 /* === H E A D E R S ======================================================= */
33 #include <ETL/stringf>
34 #include "exception.h"
36 #include <sigc++/signal.h>
39 #ifndef SINFG_NO_ANGLE
47 /* === M A C R O S ========================================================= */
49 // This is a hack for GCC 3.0.4... which has a broken dynamic_cast<>
50 // It is deprecated, and will be removed soon.
51 #if ( __GNUC__ == 3 ) && ( __GNUC__MINOR__ == 0 )
52 # define DCAST_HACK_BASECLASS() int cast__
53 # define DCAST_HACK_ID(x) static const int my_cast__(void) { return x; }
54 # define DCAST_HACK_ENABLE() cast__=my_cast__()
56 # define DCAST_HACK_BASECLASS()
57 # define DCAST_HACK_ID(x)
58 # define DCAST_HACK_ENABLE()
61 /* === T Y P E D E F S ===================================================== */
63 /* === C L A S S E S & S T R U C T S ======================================= */
68 class LinkableValueNode;
74 class ValueNode : public sinfg::Node
77 friend class LinkableValueNode;
80 -- ** -- T Y P E S -----------------------------------------------------------
85 typedef etl::handle<ValueNode> Handle;
87 typedef etl::loose_handle<ValueNode> LooseHandle;
89 typedef etl::handle<const ValueNode> ConstHandle;
91 typedef etl::rhandle<ValueNode> RHandle;
94 static bool subsys_init();
96 static bool subsys_stop();
99 -- ** -- D A T A -------------------------------------------------------------
103 ValueBase::Type type;
105 etl::loose_handle<Canvas> canvas_;
106 etl::loose_handle<Canvas> root_canvas_;
109 -- ** -- S I G N A L S -------------------------------------------------------
114 //! ValueBase Changed
115 sigc::signal<void> signal_value_changed_;
117 //! Children Reordered
118 sigc::signal<void,int*> signal_children_reordered_;
121 sigc::signal<void,int> signal_child_changed_;
124 sigc::signal<void,int> signal_child_removed_;
127 sigc::signal<void,int> signal_child_inserted_;
130 sigc::signal<void> signal_id_changed_;
133 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
138 //! ValueBase Changed
139 sigc::signal<void>& signal_value_changed() { return signal_value_changed_; }
141 //! Children Reordered
142 sigc::signal<void,int*>& signal_children_reordered() { return signal_children_reordered_; }
145 sigc::signal<void,int>& signal_child_changed() { return signal_child_changed_; }
148 sigc::signal<void,int>& signal_child_removed() { return signal_child_removed_; }
151 sigc::signal<void,int>& signal_child_inserted() { return signal_child_inserted_; }
154 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
157 -- ** -- C O N S T R U C T O R S ---------------------------------------------
162 ValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
166 virtual ~ValueNode();
169 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
174 //! Returns the value of the ValueNode at time \a t
175 virtual ValueBase operator()(Time t)const
176 { return ValueBase(); }
178 //! \internal Sets the id of the ValueNode
179 void set_id(const String &x);
181 //! Returns the id of the ValueNode
182 /*! The ID is used for keeping track of a
183 ** specific instance of a ValueNode. */
184 const String &get_id()const { return name; }
186 //! Returns the name of the ValueNode type
187 virtual String get_name()const=0;
189 //! Returns the localized name of the ValueNode type
190 virtual String get_local_name()const=0;
194 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
197 bool is_exported()const { return !get_id().empty(); }
199 //! Returns the type of the ValueNode
200 ValueBase::Type get_type()const { return type; }
202 //! Returns a handle to the parent canvas, if it has one.
203 etl::loose_handle<Canvas> get_parent_canvas()const { return canvas_; }
205 //! Returns a handle to the parent canvas, if it has one.
206 etl::loose_handle<Canvas> get_root_canvas()const { return root_canvas_; }
209 void set_parent_canvas(etl::loose_handle<Canvas> x);
212 void set_root_canvas(etl::loose_handle<Canvas> x);
215 String get_relative_id(etl::loose_handle<const Canvas> x)const;
217 int replace(etl::handle<ValueNode> x);
220 //! Sets the type of the ValueNode
221 void set_type(ValueBase::Type t) { type=t; }
223 virtual void on_changed();
226 DCAST_HACK_BASECLASS();
228 }; // END of class ValueNode
230 /*! \class PlaceholderValueNode
233 class PlaceholderValueNode : public ValueNode
236 typedef etl::handle<PlaceholderValueNode> Handle;
237 typedef etl::loose_handle<PlaceholderValueNode> LooseHandle;
238 typedef etl::handle<const PlaceholderValueNode> ConstHandle;
239 typedef etl::rhandle<PlaceholderValueNode> RHandle;
243 PlaceholderValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
247 virtual ValueBase operator()(Time t)const;
249 virtual String get_name()const;
251 virtual String get_local_name()const;
253 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
255 static Handle create(ValueBase::Type type=ValueBase::TYPE_NIL);
258 virtual void get_times_vfunc(Node::time_set &set) const {}
259 }; // END of class PlaceholderValueNode
262 /*! \class LinkableValueNode
265 class LinkableValueNode : public ValueNode
267 friend class ValueNode;
270 typedef etl::handle<LinkableValueNode> Handle;
272 typedef etl::loose_handle<LinkableValueNode> LooseHandle;
274 typedef etl::handle<const LinkableValueNode> ConstHandle;
276 typedef etl::rhandle<LinkableValueNode> RHandle;
279 //! Type that represents a pointer to a ValueNode's constructor
280 typedef LinkableValueNode* (*Factory)(const ValueBase&);
282 typedef bool (*CheckType)(ValueBase::Type);
288 CheckType check_type;
291 typedef std::map<String,BookEntry> Book;
295 static Handle create(const String &name, const ValueBase& x);
297 static bool check_type(const String &name, ValueBase::Type x);
300 LinkableValueNode(ValueBase::Type type=ValueBase::TYPE_NIL):
304 virtual bool set_link_vfunc(int i,ValueNode::Handle x)=0;
310 virtual int link_count()const=0;
312 virtual String link_local_name(int i)const=0;
314 virtual String link_name(int i)const=0;
316 virtual int get_link_index_from_name(const String &name)const=0;
318 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
320 bool set_link(int i,ValueNode::Handle x);
321 bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x); }
323 ValueNode::LooseHandle get_link(int i)const;
324 ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
327 //! Sets the type of the ValueNode
328 void set_type(ValueBase::Type t) { ValueNode::set_type(t); }
330 virtual ValueNode::LooseHandle get_link_vfunc(int i)const=0;
332 // Wrapper for new operator, used by clone()
333 virtual LinkableValueNode* create_new()const=0;
335 virtual void get_times_vfunc(Node::time_set &set) const;
336 }; // END of class LinkableValueNode
338 /*! \class ValueNodeList
339 ** \brief A searchable value_node list container
340 ** \warning Do not confuse with ValueNode_DynamicList!
343 class ValueNodeList : public std::list<ValueNode::RHandle>
345 int placeholder_count_;
349 //! Finds the ValueNode in the list with the given \a name
350 /*! \return If found, returns a handle to the ValueNode.
351 ** Otherwise, returns an empty handle.
353 ValueNode::Handle find(const String &name);
355 //! Finds the ValueNode in the list with the given \a name
356 /*! \return If found, returns a handle to the ValueNode.
357 ** Otherwise, returns an empty handle.
359 ValueNode::ConstHandle find(const String &name)const;
361 //! Removes the \a value_node from the list
362 bool erase(ValueNode::Handle value_node);
365 bool add(ValueNode::Handle value_node);
368 bool count(const String &id)const;
370 //! Similar to find, but will create a placeholder value_node if it cannot be found.
371 ValueNode::Handle surefind(const String &name);
373 //! Removes any value_nodes with reference counts of 1.
376 //! Placeholder Count
377 int placeholder_count()const { return placeholder_count_; }
380 ValueNode::LooseHandle find_value_node(const GUID& guid);
382 }; // END of namespace sinfg
384 /* === E N D =============================================================== */