Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_04 / synfig-studio / src / synfigapp / timegather.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file timegather.h
3 **      \brief Time Gather Header
4 **
5 **      $Id: timegather.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_TIMEGATHER_H
26 #define __SYNFIG_TIMEGATHER_H
27
28 /* === H E A D E R S ======================================================= */
29 #include <synfig/valuenode_animated.h>
30 #include <synfig/valuenode_dynamiclist.h>
31 #include <synfig/time.h>
32 #include "value_desc.h"
33
34 /* === M A C R O S ========================================================= */
35
36 /* === T Y P E D E F S ===================================================== */
37
38 /* === C L A S S E S & S T R U C T S ======================================= */
39
40 namespace synfigapp {
41
42 class ValueDesc;
43 class synfig::Time;
44
45 struct ValueBaseTimeInfo
46 {
47         synfig::ValueNode_Animated::Handle      val;
48         mutable std::set<synfig::Waypoint>      waypoints;
49         
50         bool operator<(const ValueBaseTimeInfo &rhs) const
51         {
52                 return val < rhs.val;
53         }
54 };
55
56 struct ActiveTimeInfo
57 {
58         struct actcmp
59         {
60                 bool operator()(const synfig::Activepoint &lhs, const synfig::Activepoint &rhs) const
61                 {
62                         return lhs.time < rhs.time;
63                 }               
64         };
65         
66         synfigapp::ValueDesc                                            val;
67         
68         typedef std::set<synfig::Activepoint,actcmp>    set;
69         
70         mutable set activepoints;
71         
72         bool operator<(const ActiveTimeInfo &rhs) const
73         {
74                 return val.get_parent_value_node() == rhs.val.get_parent_value_node() ? 
75                                                 val.get_index() < rhs.val.get_index() : 
76                                                 val.get_parent_value_node() < rhs.val.get_parent_value_node();
77         }
78 };
79
80 struct timepoints_ref
81 {
82         typedef std::set<ValueBaseTimeInfo>             waytracker;     
83         typedef std::set<ActiveTimeInfo>        acttracker;
84         
85         waytracker              waypointbiglist;
86         acttracker              actpointbiglist;        
87         
88         void insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w);  
89         void insert(synfigapp::ValueDesc v, synfig::Activepoint a);
90 };
91
92 //assumes they're sorted... (incremental advance)
93 //checks the intersection of the two sets... might be something better in the stl
94 template < typename I1, typename I2 >
95 bool check_intersect(I1 b1, I1 end1, I2 b2, I2 end2)
96 {
97         if(b1 == end1 || b2 == end2) 
98                 return false;
99         
100         for(; b1 != end1 && b2 != end2;)
101         {
102                 if(*b1 < *b2) ++b1;
103                 else if(*b2 < *b1) ++b2;
104                 else
105                 {
106                         assert(*b1 == *b2);
107                         return true;
108                 }
109         }
110         return false;
111 }
112
113 //pointer kind of a hack, gets the accurate times from a value desc 
114 //      (deals with dynamic list member correctly... i.e. gathers activepoints)
115 const synfig::Node::time_set *get_times_from_vdesc(const synfigapp::ValueDesc &v);
116
117 //get's the closest time inside the set
118 bool get_closest_time(const synfig::Node::time_set &tset, const synfig::Time &t, 
119                                                 const synfig::Time &range, synfig::Time &out);
120
121 //recursion functions based on time restrictions (can be expanded later)...
122 //builds a list of relevant waypoints and activepoints inside the timepoints_ref structure
123 void recurse_valuedesc(synfigapp::ValueDesc valdesc, const std::set<synfig::Time> &tlist,
124                                                                 timepoints_ref &vals);
125 void recurse_layer(synfig::Layer::Handle layer, const std::set<synfig::Time> &tlist, 
126                                                                 timepoints_ref &vals);
127 void recurse_canvas(synfig::Canvas::Handle canvas, const std::set<synfig::Time> &tlist, 
128                                                                 timepoints_ref &vals);
129
130
131
132 }; // END of namespace studio
133
134 /* === E N D =============================================================== */
135
136 #endif