valuenode.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_VALUENODE_H
00026 #define __SYNFIG_VALUENODE_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include "vector.h"
00031 #include "value.h"
00032 #include "string.h"
00033 #include <ETL/handle>
00034 #include <ETL/stringf>
00035 #include "exception.h"
00036 #include <map>
00037 #include <sigc++/signal.h>
00038 #include "guid.h"
00039 
00040 #ifndef SYNFIG_NO_ANGLE
00041 #include <ETL/angle>
00042 #endif
00043 
00044 #include "node.h"
00045 
00046 #include <set>
00047 
00048 /* === M A C R O S ========================================================= */
00049 
00050 // This is a hack for GCC 3.0.4... which has a broken dynamic_cast<>
00051 // It is deprecated, and will be removed soon.
00052 #if ( __GNUC__ == 3 ) && ( __GNUC__MINOR__ == 0 )
00053 # define DCAST_HACK_BASECLASS() int cast__
00054 # define DCAST_HACK_ID(x)       static const int my_cast__(void) { return x; }
00055 # define DCAST_HACK_ENABLE()    cast__=my_cast__()
00056 #else
00057 # define DCAST_HACK_BASECLASS()
00058 # define DCAST_HACK_ID(x)
00059 # define DCAST_HACK_ENABLE()
00060 #endif
00061 
00062 /* === T Y P E D E F S ===================================================== */
00063 
00064 /* === C L A S S E S & S T R U C T S ======================================= */
00065 
00066 namespace synfig {
00067 
00068 class Canvas;
00069 class LinkableValueNode;
00070 class Layer;
00071 
00075 class ValueNode : public synfig::Node
00076 {
00077     friend class Layer;
00078     friend class LinkableValueNode;
00079 
00080     /*
00081  -- ** -- T Y P E S -----------------------------------------------------------
00082     */
00083 
00084 public:
00085 
00086     typedef etl::handle<ValueNode> Handle;
00087 
00088     typedef etl::loose_handle<ValueNode> LooseHandle;
00089 
00090     typedef etl::handle<const ValueNode> ConstHandle;
00091 
00092     typedef etl::rhandle<ValueNode> RHandle;
00093 
00094 
00095     static bool subsys_init();
00096 
00097     static bool subsys_stop();
00098 
00099     /*
00100  -- ** -- D A T A -------------------------------------------------------------
00101     */
00102 
00103 private:
00104     ValueBase::Type type;
00105     String name;
00106     etl::loose_handle<Canvas> canvas_;
00107     etl::loose_handle<Canvas> root_canvas_;
00108 
00109     /*
00110  -- ** -- S I G N A L S -------------------------------------------------------
00111     */
00112 
00113 private:
00114 
00116     sigc::signal<void> signal_value_changed_;
00117 
00119     sigc::signal<void,int*> signal_children_reordered_;
00120 
00122     sigc::signal<void,int> signal_child_changed_;
00123 
00125     sigc::signal<void,int> signal_child_removed_;
00126 
00128     sigc::signal<void,int> signal_child_inserted_;
00129 
00131     sigc::signal<void> signal_id_changed_;
00132 
00133     /*
00134  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
00135     */
00136 
00137 public:
00138 
00140     sigc::signal<void>& signal_value_changed() { return signal_value_changed_; }
00141 
00143     sigc::signal<void,int*>& signal_children_reordered() { return signal_children_reordered_; }
00144 
00146     sigc::signal<void,int>& signal_child_changed() { return signal_child_changed_; }
00147 
00149     sigc::signal<void,int>& signal_child_removed() { return signal_child_removed_; }
00150 
00152     sigc::signal<void,int>& signal_child_inserted() { return signal_child_inserted_; }
00153 
00155     sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
00156 
00157     /*
00158  -- ** -- C O N S T R U C T O R S ---------------------------------------------
00159     */
00160 
00161 protected:
00162 
00163     ValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
00164 
00165 public:
00166 
00167     virtual ~ValueNode();
00168 
00169     /*
00170  -- ** -- M E M B E R   F U N C T I O N S -------------------------------------
00171     */
00172 
00173 public:
00174 
00176     virtual ValueBase operator()(Time /*t*/)const
00177         { return ValueBase(); }
00178 
00180     void set_id(const String &x);
00181 
00183 
00185     const String &get_id()const { return name; }
00186 
00188     virtual String get_name()const=0;
00189 
00191     virtual String get_local_name()const=0;
00192 
00193 
00195     virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
00196 
00198     bool is_exported()const { return !get_id().empty(); }
00199 
00201     ValueBase::Type get_type()const { return type; }
00202 
00204     etl::loose_handle<Canvas> get_parent_canvas()const { return canvas_; }
00205 
00207     etl::loose_handle<Canvas> get_root_canvas()const { return root_canvas_; }
00208 
00210     void set_parent_canvas(etl::loose_handle<Canvas> x);
00211 
00213     void set_root_canvas(etl::loose_handle<Canvas> x);
00214 
00216     String get_relative_id(etl::loose_handle<const Canvas> x)const;
00217 
00218     int replace(etl::handle<ValueNode> x);
00219 
00220 protected:
00222     void set_type(ValueBase::Type t) { type=t; }
00223 
00224     virtual void on_changed();
00225 
00226 public:
00227     DCAST_HACK_BASECLASS();
00228     DCAST_HACK_ID(0);
00229 }; // END of class ValueNode
00230 
00234 class PlaceholderValueNode : public ValueNode
00235 {
00236 public:
00237     typedef etl::handle<PlaceholderValueNode> Handle;
00238     typedef etl::loose_handle<PlaceholderValueNode> LooseHandle;
00239     typedef etl::handle<const PlaceholderValueNode> ConstHandle;
00240     typedef etl::rhandle<PlaceholderValueNode> RHandle;
00241 
00242 private:
00243 
00244     PlaceholderValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
00245 
00246 public:
00247 
00248     virtual ValueBase operator()(Time t)const;
00249 
00250     virtual String get_name()const;
00251 
00252     virtual String get_local_name()const;
00253 
00254     virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
00255 
00256     static Handle create(ValueBase::Type type=ValueBase::TYPE_NIL);
00257 
00258 protected:
00259     virtual void get_times_vfunc(Node::time_set &/*set*/) const {}
00260 }; // END of class PlaceholderValueNode
00261 
00262 
00266 class LinkableValueNode : public ValueNode
00267 {
00268     friend class ValueNode;
00269 public:
00270 
00271     typedef etl::handle<LinkableValueNode> Handle;
00272 
00273     typedef etl::loose_handle<LinkableValueNode> LooseHandle;
00274 
00275     typedef etl::handle<const LinkableValueNode> ConstHandle;
00276 
00277     typedef etl::rhandle<LinkableValueNode> RHandle;
00278 
00279 
00281     typedef LinkableValueNode* (*Factory)(const ValueBase&);
00282 
00283     typedef bool (*CheckType)(ValueBase::Type);
00284 
00285     struct BookEntry
00286     {
00287         String local_name;
00288         Factory factory;
00289         CheckType check_type;
00290     };
00291 
00292     typedef std::map<String,BookEntry> Book;
00293 
00294     static Book& book();
00295 
00296     static Handle create(const String &name, const ValueBase& x);
00297 
00298     static bool check_type(const String &name, ValueBase::Type x);
00299 
00300 public:
00301     LinkableValueNode(ValueBase::Type type=ValueBase::TYPE_NIL):
00302         ValueNode(type) { }
00303 
00304 protected:
00305     virtual bool set_link_vfunc(int i,ValueNode::Handle x)=0;
00306 
00307     void unlink_all();
00308 
00309 public:
00310 
00311     virtual int link_count()const=0;
00312 
00313     virtual String link_local_name(int i)const=0;
00314 
00315     virtual String link_name(int i)const=0;
00316 
00317     virtual int get_link_index_from_name(const String &name)const=0;
00318 
00319     virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
00320 
00321     bool set_link(int i,ValueNode::Handle x);
00322     bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x);  }
00323 
00324     ValueNode::LooseHandle get_link(int i)const;
00325     ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
00326 
00327 protected:
00329     void set_type(ValueBase::Type t) { ValueNode::set_type(t); }
00330 
00331     virtual ValueNode::LooseHandle get_link_vfunc(int i)const=0;
00332 
00333     // Wrapper for new operator, used by clone()
00334     virtual LinkableValueNode* create_new()const=0;
00335 
00336     virtual void get_times_vfunc(Node::time_set &set) const;
00337 }; // END of class LinkableValueNode
00338 
00344 class ValueNodeList : public std::list<ValueNode::RHandle>
00345 {
00346     int placeholder_count_;
00347 public:
00348     ValueNodeList();
00349 
00351 
00354     ValueNode::Handle find(const String &name);
00355 
00357 
00360     ValueNode::ConstHandle find(const String &name)const;
00361 
00363     bool erase(ValueNode::Handle value_node);
00364 
00366     bool add(ValueNode::Handle value_node);
00367 
00369     bool count(const String &id)const;
00370 
00372     ValueNode::Handle surefind(const String &name);
00373 
00375     void audit();
00376 
00378     int placeholder_count()const { return placeholder_count_; }
00379 };
00380 
00381 ValueNode::LooseHandle find_value_node(const GUID& guid);
00382 
00383 }; // END of namespace synfig
00384 
00385 /* === E N D =============================================================== */
00386 
00387 #endif

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