1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: node.h,v 1.3 2005/01/10 07:40:26 darco Exp $
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_PARENTNODE_H
26 #define __SYNFIG_PARENTNODE_H
28 /* === H E A D E R S ======================================================= */
30 #include <sigc++/signal.h>
35 #include "interpolation.h"
38 /* === M A C R O S ========================================================= */
40 /* === T Y P E D E F S ===================================================== */
42 /* === C L A S S E S & S T R U C T S ======================================= */
50 Interpolation before,after;
53 TimePoint(const Time& x=Time::begin()):
56 before(INTERPOLATION_NIL),
57 after(INTERPOLATION_NIL)
61 const GUID& get_guid()const { return guid; }
62 const Time& get_time()const { return time; }
63 Interpolation get_before()const { return before; }
64 Interpolation get_after()const { return after; }
66 void set_guid(const GUID& x) { guid=x; }
67 void set_time(const Time& x) { time=x; }
68 void set_before(Interpolation x) { before=x; }
69 void set_after(Interpolation x) { after=x; }
71 void absorb(const TimePoint& x);
72 }; // END of class TimePoint
74 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
75 { lhs.set_time(lhs.get_time()+rhs); return lhs; }
77 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
78 { return lhs.get_time()<rhs.get_time(); }
80 inline bool operator<(const TimePoint& lhs,const Time& rhs)
81 { return lhs.get_time()<rhs; }
83 inline bool operator<(const Time& lhs,const TimePoint& rhs)
84 { return lhs<rhs.get_time(); }
86 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
87 { return lhs.get_time()==rhs.get_time(); }
89 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
90 { return lhs.get_time()!=rhs.get_time(); }
92 class TimePointSet : public std::set<TimePoint>
95 iterator insert(const TimePoint& x);
97 template <typename ITER> void insert(ITER begin, ITER end)
98 { for(;begin!=end;++begin) insert(*begin); }
100 }; // END of class TimePointSet
102 class Node : public etl::rshared_object
105 -- ** -- T Y P E S -----------------------------------------------------------
111 typedef TimePointSet time_set;
114 -- ** -- D A T A -------------------------------------------------------------
122 //! cached time values for all the childrens
123 mutable time_set times;
126 mutable bool bchanged;
129 mutable int time_last_changed_;
132 mutable RWLock rw_lock_;
139 //! \todo This should really be private
140 std::set<Node*> parent_set;
143 -- ** -- S I G N A L S -------------------------------------------------------
148 sigc::signal<void> signal_changed_;
151 /*! \note The second parameter is the *OLD* guid! */
152 sigc::signal<void,GUID> signal_guid_changed_;
155 sigc::signal<void> signal_deleted_;
158 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
163 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
165 sigc::signal<void>& signal_changed() { return signal_changed_; }
168 /*! \note The second parameter is the *OLD* guid! */
169 sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
172 -- ** -- C O N S T R U C T O R S ---------------------------------------------
179 // This class cannot be copied -- use clone() if necessary
187 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
194 //! Gets the GUID for this value node
195 const GUID& get_guid()const;
197 //! Sets the GUID for this value node
198 void set_guid(const GUID& x);
200 int get_time_last_changed()const;
202 void add_child(Node*x);
204 void remove_child(Node*x);
206 int parent_count()const;
208 const time_set &get_times() const;
210 RWLock& get_rw_lock()const { return rw_lock_; }
217 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
221 virtual void on_changed();
223 virtual void on_guid_changed(GUID guid);
225 /*! Function to be overloaded that fills
227 virtual void get_times_vfunc(time_set &set) const = 0;
230 synfig::Node* find_node(const synfig::GUID& guid);
232 template<typename T> etl::handle<T>
233 guid_cast(const synfig::GUID& guid)
235 return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
238 typedef etl::handle<Node> NodeHandle;
240 }; // END of namespace synfig
242 /* === E N D =============================================================== */