1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #define HASH_MAP_H <ext/hash_map>
39 using namespace __gnu_cxx;
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
52 /* === M A C R O S ========================================================= */
54 // About BE_FRUGAL_WITH_GUIDS
55 // If this macro is set, then a GUID will NOT
56 // be calculated until the first call to get_guid()
57 // This also means that the node doesn't get
58 // added to the database until get_guid() is called
59 // for the first time, or set_guid() is called.
60 // If it is expensive to calculate GUIDs, then
61 // this can improve performance a tad in
62 // some cases. Otherwise, it doesn't change
64 #define BE_FRUGAL_WITH_GUIDS 1
69 # define __sys_clock ::clock
73 # define __sys_clock ::clock
76 extern clock_t _clock();
77 # define CLOCKS_PER_SEC 1000
78 # define __sys_clock _clock
83 /* === G L O B A L S ======================================================= */
86 typedef hash_map<GUID,Node*,GUIDHash> GlobalNodeMap;
88 typedef map<GUID,Node*> GlobalNodeMap;
91 static GlobalNodeMap* global_node_map_;
93 static GlobalNodeMap& global_node_map()
96 global_node_map_=new GlobalNodeMap;
97 return *global_node_map_;
100 /* === P R O C E D U R E S ================================================= */
103 synfig::find_node(const GUID& guid)
105 if(global_node_map().count(guid)==0)
107 return global_node_map()[guid];
111 refresh_node(synfig::Node* node, GUID old_guid)
113 assert(global_node_map().count(old_guid));
114 global_node_map().erase(old_guid);
115 assert(!global_node_map().count(old_guid));
116 global_node_map()[node->get_guid()]=node;
119 /* === M E T H O D S ======================================================= */
123 TimePoint::c_str()const
125 return get_time().get_string().c_str();
130 TimePoint::absorb(const TimePoint& x)
132 if(get_guid()==x.get_guid())
134 set_guid(get_guid()^x.get_guid());
136 if(get_after()==INTERPOLATION_NIL)
137 set_after(x.get_after());
138 if(get_before()==INTERPOLATION_NIL)
139 set_before(x.get_before());
141 if(get_after()!=x.get_after() && x.get_after()!=INTERPOLATION_NIL)
142 set_after(INTERPOLATION_UNDEFINED);
143 if(get_before()!=x.get_before() && x.get_before()!=INTERPOLATION_NIL)
144 set_before(INTERPOLATION_UNDEFINED);
147 TimePointSet::iterator
148 TimePointSet::insert(const TimePoint& x)
150 iterator iter(find(x));
153 const_cast<TimePoint&>(*iter).absorb(x);
156 return std::set<TimePoint>::insert(x).first;
178 #ifndef BE_FRUGAL_WITH_GUIDS
181 assert(!global_node_map().count(guid_));
182 global_node_map()[guid_]=this;
192 assert(global_node_map().count(guid_));
193 global_node_map().erase(guid_);
194 assert(!global_node_map().count(guid_));
201 time_last_changed_=__sys_clock();
206 //! Gets the GUID for this value node
208 Node::get_guid()const
210 #ifdef BE_FRUGAL_WITH_GUIDS
213 const_cast<GUID&>(guid_).make_unique();
215 assert(!global_node_map().count(guid_));
216 global_node_map()[guid_]=const_cast<Node*>(this);
223 //! Sets the GUID for this value node
225 Node::set_guid(const GUID& x)
229 #ifdef BE_FRUGAL_WITH_GUIDS
233 assert(!global_node_map().count(guid_));
234 global_node_map()[guid_]=this;
242 refresh_node(this, oldguid);
243 on_guid_changed(oldguid);
248 Node::get_time_last_changed()const
250 return time_last_changed_;
254 Node::add_child(Node*x)
256 x->parent_set.insert(this);
260 Node::remove_child(Node*x)
262 if(x->parent_set.count(this)) x->parent_set.erase(this);
266 Node::parent_count()const
268 return parent_set.size();
271 const Node::time_set &
272 Node::get_times() const
277 get_times_vfunc(times);
281 //set the output set...
290 deleting_=true; signal_deleted()();
300 std::set<Node*>::iterator iter;
301 for(iter=parent_set.begin();iter!=parent_set.end();++iter)
308 Node::on_guid_changed(GUID guid)
310 signal_guid_changed()(guid);