more updates
[synfig.git] / synfig-core / trunk / src / synfig / node.h
diff --git a/synfig-core/trunk/src/synfig/node.h b/synfig-core/trunk/src/synfig/node.h
new file mode 100644 (file)
index 0000000..ac87725
--- /dev/null
@@ -0,0 +1,243 @@
+/* === S I N F G =========================================================== */
+/*!    \file node.h
+**     \brief Template Header
+**
+**     $Id: node.h,v 1.3 2005/01/10 07:40:26 darco Exp $
+**
+**     \legal
+**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**
+**     This software and associated documentation
+**     are CONFIDENTIAL and PROPRIETARY property of
+**     the above-mentioned copyright holder.
+**
+**     You may not copy, print, publish, or in any
+**     other way distribute this software without
+**     a prior written agreement with
+**     the copyright holder.
+**     \endlegal
+*/
+/* ========================================================================= */
+
+/* === S T A R T =========================================================== */
+
+#ifndef __SINFG_PARENTNODE_H
+#define __SINFG_PARENTNODE_H
+
+/* === H E A D E R S ======================================================= */
+
+#include <sigc++/signal.h>
+#include <set>
+#include "time.h"
+#include "guid.h"
+#include <ETL/handle>
+#include "interpolation.h"
+#include "mutex.h"
+
+/* === M A C R O S ========================================================= */
+
+/* === T Y P E D E F S ===================================================== */
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+namespace sinfg {
+
+class TimePoint
+{
+       GUID guid;
+       Time time;
+       Interpolation before,after;
+public:
+
+       TimePoint(const Time& x=Time::begin()):
+               guid(0),
+               time(x),
+               before(INTERPOLATION_NIL),
+               after(INTERPOLATION_NIL)
+       {
+       }
+
+       const GUID& get_guid()const { return guid; }
+       const Time& get_time()const { return time; }
+       Interpolation get_before()const { return before; }
+       Interpolation get_after()const { return after; }
+
+       void set_guid(const GUID& x) { guid=x; }
+       void set_time(const Time& x) { time=x; }
+       void set_before(Interpolation x) { before=x; }
+       void set_after(Interpolation x) { after=x; }
+       
+       void absorb(const TimePoint& x);
+}; // END of class TimePoint
+
+inline TimePoint operator+(TimePoint lhs,const Time& rhs)
+       { lhs.set_time(lhs.get_time()+rhs); return lhs; }
+
+inline bool operator<(const TimePoint& lhs,const TimePoint& rhs)
+       { return lhs.get_time()<rhs.get_time(); }
+
+inline bool operator<(const TimePoint& lhs,const Time& rhs)
+       { return lhs.get_time()<rhs; }
+
+inline bool operator<(const Time& lhs,const TimePoint& rhs)
+       { return lhs<rhs.get_time(); }
+
+inline bool operator==(const TimePoint& lhs,const TimePoint& rhs)
+       { return lhs.get_time()==rhs.get_time(); }
+
+inline bool operator!=(const TimePoint& lhs,const TimePoint& rhs)
+       { return lhs.get_time()!=rhs.get_time(); }
+
+class TimePointSet : public std::set<TimePoint>
+{
+public:
+       iterator insert(const TimePoint& x);
+
+       template <typename ITER> void insert(ITER begin, ITER end)
+               { for(;begin!=end;++begin) insert(*begin); }
+
+}; // END of class TimePointSet
+       
+class Node : public etl::rshared_object
+{
+       /*
+ --    ** -- T Y P E S -----------------------------------------------------------
+       */
+
+public: 
+       
+       //! \writeme
+       typedef TimePointSet    time_set;
+
+       /*
+ --    ** -- D A T A -------------------------------------------------------------
+       */
+
+private:
+
+       //! \writeme
+       GUID guid_;
+
+       //! cached time values for all the childrens
+       mutable time_set        times;
+
+       //! \writeme
+       mutable bool            bchanged;
+
+       //! \writeme
+       mutable int time_last_changed_;
+
+       //! \writeme
+       mutable RWLock rw_lock_;
+       
+       //! \writeme
+       bool deleting_;
+
+public:
+
+       //! \todo This should really be private
+       std::set<Node*>         parent_set;
+
+       /*
+ -- ** -- S I G N A L S -------------------------------------------------------
+       */
+
+private:
+       
+       sigc::signal<void> signal_changed_;
+
+       //!     GUID Changed
+       /*! \note The second parameter is the *OLD* guid! */
+       sigc::signal<void,GUID> signal_guid_changed_;   
+
+       //!     Deleted
+       sigc::signal<void> signal_deleted_;     
+
+       /*
+ -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
+       */
+
+public:
+
+       sigc::signal<void>& signal_deleted() { return signal_deleted_; }
+
+       sigc::signal<void>& signal_changed() { return signal_changed_; }
+
+       //!     GUID Changed
+       /*! \note The second parameter is the *OLD* guid! */
+       sigc::signal<void,GUID>& signal_guid_changed() { return signal_guid_changed_; }
+
+       /*
+ --    ** -- C O N S T R U C T O R S ---------------------------------------------
+       */
+
+protected:
+
+       Node();
+
+       // This class cannot be copied -- use clone() if necessary
+private:
+       Node(const Node &x);
+
+public:
+       virtual ~Node();
+
+       /*
+ --    ** -- M E M B E R   F U N C T I O N S -------------------------------------
+       */
+       
+public:
+
+       void changed();
+
+       //! Gets the GUID for this value node
+       const GUID& get_guid()const;
+
+       //! Sets the GUID for this value node
+       void set_guid(const GUID& x);
+
+       int get_time_last_changed()const;
+       
+       void add_child(Node*x);
+
+       void remove_child(Node*x);
+
+       int parent_count()const;
+       
+       const time_set &get_times() const;
+
+       RWLock& get_rw_lock()const { return rw_lock_; }
+       
+protected:
+       
+       void begin_delete();
+       
+       /*
+ --    ** -- V I R T U A L   F U N C T I O N S -----------------------------------
+       */
+
+protected:
+       virtual void on_changed();
+
+       virtual void on_guid_changed(GUID guid);
+
+       /*!     Function to be overloaded that fills 
+       */
+       virtual void get_times_vfunc(time_set &set) const = 0;
+};     
+
+sinfg::Node* sinfg::find_node(const sinfg::GUID& guid);
+
+template<typename T> etl::handle<T>
+guid_cast(const sinfg::GUID& guid)
+{
+       return etl::handle<T>::cast_dynamic(sinfg::find_node(guid));
+}
+
+typedef etl::handle<Node> NodeHandle;
+
+}; // END of namespace sinfg
+
+/* === E N D =============================================================== */
+
+#endif