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 ======================================================= */
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
49 /* === M A C R O S ========================================================= */
51 // About BE_FRUGAL_WITH_GUIDS
52 // If this macro is set, then a GUID will NOT
53 // be calculated until the first call to get_guid()
54 // This also means that the node doesn't get
55 // added to the database until get_guid() is called
56 // for the first time, or set_guid() is called.
57 // If it is expensive to calculate GUIDs, then
58 // this can improve performance a tad in
59 // some cases. Otherwise, it doesn't change
61 #define BE_FRUGAL_WITH_GUIDS 1
66 # define __sys_clock ::clock
70 # define __sys_clock ::clock
73 extern clock_t _clock();
74 # define CLOCKS_PER_SEC 1000
75 # define __sys_clock _clock
80 /* === G L O B A L S ======================================================= */
83 typedef HASH_MAP_CLASS<GUID,Node*,GUIDHash> GlobalNodeMap;
85 typedef map<GUID,Node*> GlobalNodeMap;
88 static GlobalNodeMap* global_node_map_;
90 static GlobalNodeMap& global_node_map()
93 global_node_map_=new GlobalNodeMap;
94 return *global_node_map_;
97 /* === P R O C E D U R E S ================================================= */
100 synfig::find_node(const GUID& guid)
102 if(global_node_map().count(guid)==0)
104 return global_node_map()[guid];
108 refresh_node(synfig::Node* node, GUID old_guid)
110 assert(global_node_map().count(old_guid));
111 global_node_map().erase(old_guid);
112 assert(!global_node_map().count(old_guid));
113 global_node_map()[node->get_guid()]=node;
116 /* === M E T H O D S ======================================================= */
120 TimePoint::c_str()const
122 return get_time().get_string().c_str();
127 TimePoint::absorb(const TimePoint& x)
129 if(get_guid()==x.get_guid())
131 set_guid(get_guid()^x.get_guid());
133 if(get_after()==INTERPOLATION_NIL)
134 set_after(x.get_after());
135 if(get_before()==INTERPOLATION_NIL)
136 set_before(x.get_before());
138 if(get_after()!=x.get_after() && x.get_after()!=INTERPOLATION_NIL)
139 set_after(INTERPOLATION_UNDEFINED);
140 if(get_before()!=x.get_before() && x.get_before()!=INTERPOLATION_NIL)
141 set_before(INTERPOLATION_UNDEFINED);
144 TimePointSet::iterator
145 TimePointSet::insert(const TimePoint& x)
147 iterator iter(find(x));
150 const_cast<TimePoint&>(*iter).absorb(x);
153 return std::set<TimePoint>::insert(x).first;
173 time_last_changed_(__sys_clock()),
176 #ifndef BE_FRUGAL_WITH_GUIDS
179 assert(!global_node_map().count(guid_));
180 global_node_map()[guid_]=this;
190 assert(global_node_map().count(guid_));
191 global_node_map().erase(guid_);
192 assert(!global_node_map().count(guid_));
199 time_last_changed_=__sys_clock();
204 //! Gets the GUID for this value node
206 Node::get_guid()const
208 #ifdef BE_FRUGAL_WITH_GUIDS
211 const_cast<GUID&>(guid_).make_unique();
213 assert(!global_node_map().count(guid_));
214 global_node_map()[guid_]=const_cast<Node*>(this);
221 //! Sets the GUID for this value node
223 Node::set_guid(const GUID& x)
227 #ifdef BE_FRUGAL_WITH_GUIDS
231 assert(!global_node_map().count(guid_));
232 global_node_map()[guid_]=this;
240 refresh_node(this, oldguid);
241 on_guid_changed(oldguid);
246 Node::get_time_last_changed()const
248 return time_last_changed_;
252 Node::add_child(Node*x)
254 x->parent_set.insert(this);
258 Node::remove_child(Node*x)
260 if(x->parent_set.count(this)) x->parent_set.erase(this);
264 Node::parent_count()const
266 return parent_set.size();
269 const Node::time_set &
270 Node::get_times() const
275 get_times_vfunc(times);
279 //set the output set...
288 deleting_=true; signal_deleted()();
298 std::set<Node*>::iterator iter;
299 for(iter=parent_set.begin();iter!=parent_set.end();++iter)
306 Node::on_guid_changed(GUID guid)
308 signal_guid_changed()(guid);