00001
00021
00022
00023
00024
00025 #ifndef __SYNFIG_VALUENODE_DYNAMICLIST_H
00026 #define __SYNFIG_VALUENODE_DYNAMICLIST_H
00027
00028
00029
00030 #include <vector>
00031 #include <list>
00032
00033 #include "valuenode.h"
00034 #include "time.h"
00035 #include "uniqueid.h"
00036 #include "activepoint.h"
00037
00038
00039
00040
00041
00042 namespace synfig {
00043 class ValueNode_BLine;
00044
00074 class ValueNode_DynamicList : public LinkableValueNode
00075 {
00076 public:
00077
00087 struct ListEntry : public UniqueID
00088 {
00089 friend class ValueNode_DynamicList;
00090 friend class ValueNode_BLine;
00091 public:
00092 typedef synfig::Activepoint Activepoint;
00093
00094 typedef std::list<Activepoint> ActivepointList;
00095
00096 typedef std::pair<ActivepointList::iterator,bool> findresult;
00097 typedef std::pair<ActivepointList::const_iterator,bool> const_findresult;
00098
00099
00100 private:
00101 mutable Node::time_set times;
00102 public:
00103 ValueNode::RHandle value_node;
00104
00105 ActivepointList timing_info;
00106
00107 private:
00108 int index;
00109 etl::loose_handle<ValueNode> parent_;
00110 void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
00111
00112 public:
00113
00114 int get_index()const { return index; }
00115
00116
00117 bool status_at_time(const Time &x)const;
00118
00119 float amount_at_time(const Time &x, bool *rising=0)const;
00120
00121 ActivepointList::iterator add(Time time, bool status, int priority=0);
00122 ActivepointList::iterator add(const Activepoint &x);
00123
00124 findresult find_uid(const UniqueID& x);
00125 const_findresult find_uid(const UniqueID& x)const;
00126
00127 findresult find_time(const Time& x);
00128 const_findresult find_time(const Time& x)const;
00129
00130 ActivepointList::iterator find(const UniqueID& x);
00131 ActivepointList::const_iterator find(const UniqueID& x)const;
00132 ActivepointList::iterator find(const Time& x);
00133 ActivepointList::const_iterator find(const Time& x)const;
00134 ActivepointList::iterator find_prev(const Time& x);
00135 ActivepointList::const_iterator find_prev(const Time& x)const;
00136 ActivepointList::iterator find_next(const Time& x);
00137 ActivepointList::const_iterator find_next(const Time& x)const;
00138
00139 Activepoint new_activepoint_at_time(const Time& x)const;
00140
00141 ActivepointList::iterator add(Time time)
00142 { return add(time, status_at_time(time)); }
00143
00144 void erase(const UniqueID& x);
00145
00146 int find(const Time& begin,const Time& end,std::vector<Activepoint*>& list);
00147
00148 const synfig::Node::time_set &get_times() const;
00149
00150 const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
00151
00152 ListEntry();
00153 ListEntry(const ValueNode::Handle &value_node);
00154 ListEntry(const ValueNode::Handle &value_node,Time begin, Time end);
00155 };
00156
00157 typedef etl::handle<ValueNode_DynamicList> Handle;
00158 typedef etl::handle<const ValueNode_DynamicList> ConstHandle;
00159
00160 protected:
00161 ValueNode_DynamicList(ValueBase::Type container_type=ValueBase::TYPE_NIL);
00162
00163 ValueBase::Type container_type;
00164
00165 bool loop_;
00166
00167
00168 public:
00169 std::vector<ListEntry> list;
00170
00171 public:
00172
00173 void add(const ValueNode::Handle &value_node, int index=-1);
00174 void add(const ListEntry &value_node, int index=-1);
00175 void erase(const ValueNode::Handle &value_node);
00176 void reindex();
00177
00178 int find_next_valid_entry(int x, Time t)const;
00179 int find_prev_valid_entry(int x, Time t)const;
00180
00181 virtual ValueNode::LooseHandle get_link_vfunc(int i)const;
00182
00183 virtual int link_count()const;
00184
00185 virtual String link_name(int i)const;
00186
00187 virtual ValueBase operator()(Time t)const;
00188
00189 virtual ~ValueNode_DynamicList();
00190
00191 virtual String link_local_name(int i)const;
00192 virtual int get_link_index_from_name(const String &name)const;
00193
00194 virtual String get_name()const;
00195 virtual String get_local_name()const;
00196
00197 bool get_loop()const { return loop_; }
00198 void set_loop(bool x) { loop_=x; }
00199
00200 ValueBase::Type get_contained_type()const;
00201
00202
00203 template <typename iterator> static Handle
00204 create(iterator begin, iterator end)
00205 {
00206 Handle ret=create((*begin)->get_type());
00207 for(;begin!=end;++begin)
00208 ret->add(ListEntry(*begin));
00209 return ret;
00210 }
00211
00212 void insert_time(const Time& location, const Time& delta);
00213
00214
00215 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
00216
00217 virtual ListEntry create_list_entry(int index, Time time=0, Real origin=0.5);
00218
00219 protected:
00220
00221 virtual bool set_link_vfunc(int i,ValueNode::Handle x);
00222 LinkableValueNode* create_new()const;
00223
00224 virtual void get_times_vfunc(Node::time_set &set) const;
00225
00226 public:
00231 static Handle create(ValueBase::Type id=ValueBase::TYPE_NIL);
00232 using synfig::LinkableValueNode::get_link_vfunc;
00233 using synfig::LinkableValueNode::set_link_vfunc;
00234 static bool check_type(ValueBase::Type type);
00235 static ValueNode_DynamicList* create_from(const ValueBase &x=ValueBase::TYPE_GRADIENT);
00236 };
00237
00238 typedef ValueNode_DynamicList::ListEntry::Activepoint Activepoint;
00239 typedef ValueNode_DynamicList::ListEntry::ActivepointList ActivepointList;
00240
00241 };
00242
00243
00244
00245 #endif