synfig-core  1.0.3
valuenode_dynamiclist.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
22 /* ========================================================================= */
23 
24 /* === S T A R T =========================================================== */
25 
26 #ifndef __SYNFIG_VALUENODE_DYNAMICLIST_H
27 #define __SYNFIG_VALUENODE_DYNAMICLIST_H
28 
29 /* === H E A D E R S ======================================================= */
30 
31 #include <vector>
32 #include <list>
33 
34 #include <synfig/valuenode.h>
35 #include <synfig/time.h>
36 #include <synfig/uniqueid.h>
37 #include <synfig/activepoint.h>
38 
39 /* === M A C R O S ========================================================= */
40 
41 /* === C L A S S E S & S T R U C T S ======================================= */
42 
43 namespace synfig {
44 class ValueNode_BLine;
45 class Canvas;
46 
77 {
78 public:
79 
89  struct ListEntry : public UniqueID
90  {
91  friend class ValueNode_DynamicList;
92  friend class ValueNode_BLine;
93  friend class ValueNode_WPList;
94  friend class ValueNode_DIList;
95  public:
97 
98  typedef std::list<Activepoint> ActivepointList;
99 
100  typedef std::pair<ActivepointList::iterator,bool> findresult;
101  typedef std::pair<ActivepointList::const_iterator,bool> const_findresult;
102 
103 
104  private:
105  mutable Node::time_set times;
106  public:
108 
110 
111  private:
112  int index;
113  etl::loose_handle<ValueNode> parent_;
114  void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
115 
116  public:
117 
118  int get_index()const { return index; }
119 
120 
121  bool status_at_time(const Time &x)const;
122 
123  float amount_at_time(const Time &x, bool *rising=0)const;
124 
125  ActivepointList::iterator add(Time time, bool status, int priority=0);
126  ActivepointList::iterator add(const Activepoint &x);
127 
128  findresult find_uid(const UniqueID& x);
129  const_findresult find_uid(const UniqueID& x)const;
130 
131  findresult find_time(const Time& x);
132  const_findresult find_time(const Time& x)const;
133 
134  ActivepointList::iterator find(const UniqueID& x);
135  ActivepointList::const_iterator find(const UniqueID& x)const;
136  ActivepointList::iterator find(const Time& x);
137  ActivepointList::const_iterator find(const Time& x)const;
138  ActivepointList::iterator find_prev(const Time& x);
139  ActivepointList::const_iterator find_prev(const Time& x)const;
140  ActivepointList::iterator find_next(const Time& x);
141  ActivepointList::const_iterator find_next(const Time& x)const;
142 
144 
145  ActivepointList::iterator add(Time time)
146  { return add(time, status_at_time(time)); }
147 
148  void erase(const UniqueID& x);
149 
150  int find(const Time& begin,const Time& end,std::vector<Activepoint*>& list);
151 
152  const synfig::Node::time_set &get_times() const;
153 
154  const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
155 
156  ListEntry();
158  ListEntry(const ValueNode::Handle &value_node,Time begin, Time end);
159  }; // END of struct ValueNode_DynamicList::ListEntry
160 
161  typedef etl::handle<ValueNode_DynamicList> Handle;
162  typedef etl::handle<const ValueNode_DynamicList> ConstHandle;
163 
164 protected:
165  ValueNode_DynamicList(Type &container_type=type_nil, etl::loose_handle<Canvas> canvas = 0);
166  ValueNode_DynamicList(Type &container_type, Type &type, etl::loose_handle<Canvas> canvas = 0);
167 
169 
170  bool loop_;
171 
172 
173 public:
174  std::vector<ListEntry> list;
175 
176 public:
177 
178  void add(const ValueNode::Handle &value_node, int index=-1);
179  void add(const ListEntry &value_node, int index=-1);
180  void erase(const ValueNode::Handle &value_node);
181  void reindex();
182 
183  int find_next_valid_entry(int x, Time t)const;
184  int find_prev_valid_entry(int x, Time t)const;
185 
186  virtual ValueNode::LooseHandle get_link_vfunc(int i)const;
187 
188  virtual int link_count()const;
189 
190  virtual String link_name(int i)const;
191 
192  virtual ValueBase operator()(Time t)const;
193 
194  virtual ~ValueNode_DynamicList();
195 
196  virtual String link_local_name(int i)const;
197  virtual int get_link_index_from_name(const String &name)const;
198 
199  virtual String get_name()const;
200  virtual String get_local_name()const;
201 
202  bool get_loop()const { return loop_; }
203  void set_loop(bool x) { loop_=x; }
204 
205  void set_member_canvas(etl::loose_handle<Canvas>);
206 
207  Type& get_contained_type()const;
208 
209 
210  template <typename iterator> static Handle
211  create(iterator begin, iterator end)
212  {
213  Handle ret=create((*begin)->get_type());
214  for(;begin!=end;++begin)
215  ret->add(ListEntry(*begin));
216  return ret;
217  }
218 
219  void insert_time(const Time& location, const Time& delta);
220  //void manipulate_time(const Time& old_begin,const Time& old_end,const Time& new_begin,const Time& new_end);
221 
222  virtual ValueNode::Handle clone(etl::loose_handle<Canvas> canvas, const GUID& deriv_guid=GUID())const;
223 
224  virtual ListEntry create_list_entry(int index, Time time=0, Real origin=0.5);
225 
226 protected:
227 
228  virtual bool set_link_vfunc(int i,ValueNode::Handle x);
230 
231  virtual void get_times_vfunc(Node::time_set &set) const;
232 
233 public:
238  static Handle create(Type &type=type_nil, etl::loose_handle<Canvas> canvas = 0);
241  static bool check_type(Type &type);
243  virtual Vocab get_children_vocab_vfunc()const;
244 }; // END of class ValueNode_DynamicList
245 
248 
249 }; // END of namespace synfig
250 
251 /* === E N D =============================================================== */
252 
253 #endif