node.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_PARENTNODE_H
00026 #define __SYNFIG_PARENTNODE_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include <sigc++/signal.h>
00031 #include <set>
00032 #include "time.h"
00033 #include "guid.h"
00034 #include <ETL/handle>
00035 #include "interpolation.h"
00036 #include "mutex.h"
00037 
00038 /* === M A C R O S ========================================================= */
00039 
00040 /* === T Y P E D E F S ===================================================== */
00041 
00042 /* === C L A S S E S & S T R U C T S ======================================= */
00043 
00044 namespace synfig {
00045 
00046 class TimePoint
00047 {
00048     GUID guid;
00049     Time time;
00050     Interpolation before,after;
00051 public:
00052 
00053     TimePoint(const Time& x=Time::begin()):
00054         guid(0),
00055         time(x),
00056         before(INTERPOLATION_NIL),
00057         after(INTERPOLATION_NIL)
00058     {
00059     }
00060 
00061     const GUID& get_guid()const { return guid; }
00062     const Time& get_time()const { return time; }
00063     Interpolation get_before()const { return before; }
00064     Interpolation get_after()const { return after; }
00065 
00066     void set_guid(const GUID& x) { guid=x; }
00067     void set_time(const Time& x) { time=x; }
00068     void set_before(Interpolation x) { before=x; }
00069     void set_after(Interpolation x) { after=x; }
00070 
00071     void absorb(const TimePoint& x);
00072 }; // END of class TimePoint
00073 
00074 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
00075     { lhs.set_time(lhs.get_time()+rhs); return lhs; }
00076 
00077 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
00078     { return lhs.get_time()<rhs.get_time(); }
00079 
00080 inline bool operator<(const TimePoint& lhs,const Time& rhs)
00081     { return lhs.get_time()<rhs; }
00082 
00083 inline bool operator<(const Time& lhs,const TimePoint& rhs)
00084     { return lhs<rhs.get_time(); }
00085 
00086 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
00087     { return lhs.get_time()==rhs.get_time(); }
00088 
00089 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
00090     { return lhs.get_time()!=rhs.get_time(); }
00091 
00092 class TimePointSet : public std::set<TimePoint>
00093 {
00094 public:
00095     iterator insert(const TimePoint& x);
00096 
00097     template <typename ITER> void insert(ITER begin, ITER end)
00098         { for(;begin!=end;++begin) insert(*begin); }
00099 
00100 }; // END of class TimePointSet
00101 
00102 class Node : public etl::rshared_object
00103 {
00104     /*
00105  -- ** -- T Y P E S -----------------------------------------------------------
00106     */
00107 
00108 public:
00109 
00111     typedef TimePointSet    time_set;
00112 
00113     /*
00114  -- ** -- D A T A -------------------------------------------------------------
00115     */
00116 
00117 private:
00118 
00120     GUID guid_;
00121 
00123     mutable time_set    times;
00124 
00126     mutable bool        bchanged;
00127 
00129     mutable int time_last_changed_;
00130 
00132     mutable RWLock rw_lock_;
00133 
00135     bool deleting_;
00136 
00137 public:
00138 
00140     std::set<Node*>     parent_set;
00141 
00142     /*
00143  -- ** -- S I G N A L S -------------------------------------------------------
00144     */
00145 
00146 private:
00147 
00148     sigc::signal<void> signal_changed_;
00149 
00151 
00152     sigc::signal<void,GUID> signal_guid_changed_;
00153 
00155     sigc::signal<void> signal_deleted_;
00156 
00157     /*
00158  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
00159     */
00160 
00161 public:
00162 
00163     sigc::signal<void>& signal_deleted() { return signal_deleted_; }
00164 
00165     sigc::signal<void>& signal_changed() { return signal_changed_; }
00166 
00168 
00169     sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
00170 
00171     /*
00172  -- ** -- C O N S T R U C T O R S ---------------------------------------------
00173     */
00174 
00175 protected:
00176 
00177     Node();
00178 
00179     // This class cannot be copied -- use clone() if necessary
00180 private:
00181     Node(const Node &x);
00182 
00183 public:
00184     virtual ~Node();
00185 
00186     /*
00187  -- ** -- M E M B E R   F U N C T I O N S -------------------------------------
00188     */
00189 
00190 public:
00191 
00192     void changed();
00193 
00195     const GUID& get_guid()const;
00196 
00198     void set_guid(const GUID& x);
00199 
00200     int get_time_last_changed()const;
00201 
00202     void add_child(Node*x);
00203 
00204     void remove_child(Node*x);
00205 
00206     int parent_count()const;
00207 
00208     const time_set &get_times() const;
00209 
00210     RWLock& get_rw_lock()const { return rw_lock_; }
00211 
00212 protected:
00213 
00214     void begin_delete();
00215 
00216     /*
00217  -- ** -- V I R T U A L   F U N C T I O N S -----------------------------------
00218     */
00219 
00220 protected:
00221     virtual void on_changed();
00222 
00223     virtual void on_guid_changed(GUID guid);
00224 
00227     virtual void get_times_vfunc(time_set &set) const = 0;
00228 };
00229 
00230 synfig::Node* find_node(const synfig::GUID& guid);
00231 
00232 template<typename T> etl::handle<T>
00233 guid_cast(const synfig::GUID& guid)
00234 {
00235     return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
00236 }
00237 
00238 typedef etl::handle<Node> NodeHandle;
00239 
00240 }; // END of namespace synfig
00241 
00242 /* === E N D =============================================================== */
00243 
00244 #endif

Generated on Wed Dec 12 03:11:41 2007 for synfig by  doxygen 1.5.4