- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# node.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00022 /* ========================================================================= */
    00023
    00024 /* === S T A R T =========================================================== */
    00025
    00026 #ifndef __SYNFIG_PARENTNODE_H
    00027 #define __SYNFIG_PARENTNODE_H
    00028
    00029 /* === H E A D E R S ======================================================= */
    00030
    00031 #include <sigc++/signal.h>
    00032 #include <set>
    00033 #include "time.h"
    00034 #include "guid.h"
    00035 #include <ETL/handle>
    00036 #include "interpolation.h"
    00037 #include "mutex.h"
    00038
    00039 /* === M A C R O S ========================================================= */
    00040
    00041 // When a PasteCanvas layer has a non-zero 'time offset' parameter, should
    00042 // the waypoints shown for the canvas be adjusted?  This currently only
    00043 // partially works - see the TODO at the end of layer_pastecanvas.cpp
    00044 #define ADJUST_WAYPOINTS_FOR_TIME_OFFSET
    00045
    00046 /* === T Y P E D E F S ===================================================== */
    00047
    00048 /* === C L A S S E S & S T R U C T S ======================================= */
    00049
    00050 namespace synfig {
    00051
    00052 class TimePoint
    00053 {
    00054     GUID guid;
    00055     Time time;
    00056     Interpolation before,after;
    00057 public:
    00058
    00059     TimePoint(const Time& x=Time::begin()):
    00060         guid(0),
    00061         time(x),
    00062         before(INTERPOLATION_NIL),
    00063         after(INTERPOLATION_NIL)
    00064     {
    00065     }
    00066
    00067 #ifdef _DEBUG
    00068     const char *c_str()const;
    00069 #endif
    00070
    00071     const GUID& get_guid()const { return guid; }
    00072     const Time& get_time()const { return time; }
    00073     Interpolation get_before()const { return before; }
    00074     Interpolation get_after()const { return after; }
    00075
    00076     void set_guid(const GUID& x) { guid=x; }
    00077     void set_time(const Time& x) { time=x; }
    00078     void set_before(Interpolation x) { before=x; }
    00079     void set_after(Interpolation x) { after=x; }
    00080
    00081     void absorb(const TimePoint& x);
    00082 }; // END of class TimePoint
    00083
    00084 inline TimePoint operator+(TimePoint lhs,const Time& rhs)
    00085     { lhs.set_time(lhs.get_time()+rhs); return lhs; }
    00086
    00087 inline TimePoint operator-(TimePoint lhs,const Time& rhs)
    00088     { lhs.set_time(lhs.get_time()-rhs); return lhs; }
    00089
    00090 inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
    00091     { return lhs.get_time()<rhs.get_time(); }
    00092
    00093 inline bool operator<(const TimePoint& lhs,const Time& rhs)
    00094     { return lhs.get_time()<rhs; }
    00095
    00096 inline bool operator<(const Time& lhs,const TimePoint& rhs)
    00097     { return lhs<rhs.get_time(); }
    00098
    00099 inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
    00100     { return lhs.get_time()==rhs.get_time(); }
    00101
    00102 inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
    00103     { return lhs.get_time()!=rhs.get_time(); }
    00104
    00105 class TimePointSet : public std::set<TimePoint>
    00106 {
    00107 public:
    00108     iterator insert(const TimePoint& x);
    00109
    00110     template <typename ITER> void insert(ITER begin, ITER end)
    00111         { for(;begin!=end;++begin) insert(*begin); }
    00112
    00113 }; // END of class TimePointSet
    00114
    00115 class Node : public etl::rshared_object
    00116 {
    00117     /*
    00118  -- ** -- T Y P E S -----------------------------------------------------------
    00119     */
    00120
    00121 public:
    00122
    00124     typedef TimePointSet    time_set;
    00125
    00126     /*
    00127  -- ** -- D A T A -------------------------------------------------------------
    00128     */
    00129
    00130 private:
    00131
    00133     GUID guid_;
    00134
    00136     mutable time_set    times;
    00137
    00139     mutable bool        bchanged;
    00140
    00142     mutable int time_last_changed_;
    00143
    00145     mutable RWLock rw_lock_;
    00146
    00148     bool deleting_;
    00149
    00150 public:
    00151
    00153     std::set<Node*>     parent_set;
    00154
    00155     /*
    00156  -- ** -- S I G N A L S -------------------------------------------------------
    00157     */
    00158
    00159 private:
    00160
    00161     sigc::signal<void> signal_changed_;
    00162
    00164
    00165     sigc::signal<void,GUID> signal_guid_changed_;
    00166
    00168     sigc::signal<void> signal_deleted_;
    00169
    00170     /*
    00171  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
    00172     */
    00173
    00174 public:
    00175
    00176     sigc::signal<void>& signal_deleted() { return signal_deleted_; }
    00177
    00178     sigc::signal<void>& signal_changed() { return signal_changed_; }
    00179
    00181
    00182     sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
    00183
    00184     /*
    00185  -- ** -- C O N S T R U C T O R S ---------------------------------------------
    00186     */
    00187
    00188 protected:
    00189
    00190     Node();
    00191
    00192     // This class cannot be copied -- use clone() if necessary
    00193 private:
    00194     Node(const Node &x);
    00195
    00196 public:
    00197     virtual ~Node();
    00198
    00199     /*
    00200  -- ** -- M E M B E R   F U N C T I O N S -------------------------------------
    00201     */
    00202
    00203 public:
    00204
    00205     void changed();
    00206
    00208     const GUID& get_guid()const;
    00209
    00211     void set_guid(const GUID& x);
    00212
    00213     int get_time_last_changed()const;
    00214
    00215     void add_child(Node*x);
    00216
    00217     void remove_child(Node*x);
    00218
    00219     int parent_count()const;
    00220
    00221     const time_set &get_times() const;
    00222
    00223     RWLock& get_rw_lock()const { return rw_lock_; }
    00224
    00225 protected:
    00226
    00227     void begin_delete();
    00228
    00229     /*
    00230  -- ** -- V I R T U A L   F U N C T I O N S -----------------------------------
    00231     */
    00232
    00233 protected:
    00234     virtual void on_changed();
    00235
    00236     virtual void on_guid_changed(GUID guid);
    00237
    00240     virtual void get_times_vfunc(time_set &set) const = 0;
    00241 };
    00242
    00243 synfig::Node* find_node(const synfig::GUID& guid);
    00244
    00245 template<typename T> etl::handle<T>
    00246 guid_cast(const synfig::GUID& guid)
    00247 {
    00248     return etl::handle<T>::cast_dynamic(synfig::find_node(guid));
    00249 }
    00250
    00251 #ifdef _DEBUG
    00252 template <typename T>
    00253 synfig::String set_string(T start, T end)
    00254 {
    00255     synfig::String ret("[");
    00256     bool started = false;
    00257
    00258     while (start != end)
    00259     {
    00260         if (started)    ret += ", ";
    00261         else            started = true;
    00262
    00263         ret += synfig::String((*start).c_str());
    00264         start++;
    00265     }
    00266
    00267     return ret + "]";
    00268 }
    00269
    00270 template <typename T>
    00271 synfig::String set_string(T set)
    00272 {
    00273     return set_string(set.begin(), set.end());
    00274 }
    00275 #endif // _DEBUG
    00276
    00277 typedef etl::handle<Node> NodeHandle;
    00278
    00279 }; // END of namespace synfig
    00280
    00281 /* === E N D =============================================================== */
    00282
    00283 #endif