1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
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 TimePoint operator-(TimePoint lhs,const Time& rhs)
78 { lhs.set_time(lhs.get_time()-rhs); return lhs; }
80 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
81 { return lhs.get_time()<rhs.get_time(); }
83 inline bool operator<(const TimePoint& lhs,const Time& rhs)
84 { return lhs.get_time()<rhs; }
86 inline bool operator<(const Time& lhs,const TimePoint& rhs)
87 { return lhs<rhs.get_time(); }
89 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
90 { return lhs.get_time()==rhs.get_time(); }
92 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
93 { return lhs.get_time()!=rhs.get_time(); }
95 class TimePointSet : public std::set<TimePoint>
98 iterator insert(const TimePoint& x);
100 template <typename ITER> void insert(ITER begin, ITER end)
101 { for(;begin!=end;++begin) insert(*begin); }
103 }; // END of class TimePointSet
105 class Node : public etl::rshared_object
108 -- ** -- T Y P E S -----------------------------------------------------------
114 typedef TimePointSet time_set;
117 -- ** -- D A T A -------------------------------------------------------------
125 //! cached time values for all the childrens
126 mutable time_set times;
129 mutable bool bchanged;
132 mutable int time_last_changed_;
135 mutable RWLock rw_lock_;
142 //! \todo This should really be private
143 std::set<Node*> parent_set;
146 -- ** -- S I G N A L S -------------------------------------------------------
151 sigc::signal<void> signal_changed_;
154 /*! \note The second parameter is the *OLD* guid! */
155 sigc::signal<void,GUID> signal_guid_changed_;
158 sigc::signal<void> signal_deleted_;
161 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
166 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
168 sigc::signal<void>& signal_changed() { return signal_changed_; }
171 /*! \note The second parameter is the *OLD* guid! */
172 sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
175 -- ** -- C O N S T R U C T O R S ---------------------------------------------
182 // This class cannot be copied -- use clone() if necessary
190 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
197 //! Gets the GUID for this value node
198 const GUID& get_guid()const;
200 //! Sets the GUID for this value node
201 void set_guid(const GUID& x);
203 int get_time_last_changed()const;
205 void add_child(Node*x);
207 void remove_child(Node*x);
209 int parent_count()const;
211 const time_set &get_times() const;
213 RWLock& get_rw_lock()const { return rw_lock_; }
220 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
224 virtual void on_changed();
226 virtual void on_guid_changed(GUID guid);
228 /*! Function to be overloaded that fills
230 virtual void get_times_vfunc(time_set &set) const = 0;
233 synfig::Node* find_node(const synfig::GUID& guid);
235 template<typename T> etl::handle<T>
236 guid_cast(const synfig::GUID& guid)
238 return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
241 typedef etl::handle<Node> NodeHandle;
243 }; // END of namespace synfig
245 /* === E N D =============================================================== */