1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
50 /* === M A C R O S ========================================================= */
52 // About BE_FRUGAL_WITH_GUIDS
53 // If this macro is set, then a GUID will NOT
54 // be calculated until the first call to get_guid()
55 // This also means that the node doesn't get
56 // added to the database until get_guid() is called
57 // for the first time, or set_guid() is called.
58 // If it is expensive to calculate GUIDs, then
59 // this can improve performance a tad in
60 // some cases. Otherwise, it doesn't change
62 #define BE_FRUGAL_WITH_GUIDS 1
67 # define __sys_clock ::clock
71 # define __sys_clock ::clock
74 extern clock_t _clock();
75 # define CLOCKS_PER_SEC 1000
76 # define __sys_clock _clock
81 /* === G L O B A L S ======================================================= */
84 typedef HASH_MAP_CLASS<synfig::GUID,Node*,GUIDHash> GlobalNodeMap;
86 typedef map<synfig::GUID,Node*> GlobalNodeMap;
89 static GlobalNodeMap* global_node_map_;
91 static GlobalNodeMap& global_node_map()
94 global_node_map_=new GlobalNodeMap;
95 return *global_node_map_;
98 /* === P R O C E D U R E S ================================================= */
101 synfig::find_node(const synfig::GUID& guid)
103 if(global_node_map().count(guid)==0)
105 return global_node_map()[guid];
109 refresh_node(synfig::Node* node, synfig::GUID old_guid)
111 assert(global_node_map().count(old_guid));
112 global_node_map().erase(old_guid);
113 assert(!global_node_map().count(old_guid));
114 global_node_map()[node->get_guid()]=node;
117 /* === M E T H O D S ======================================================= */
121 TimePoint::c_str()const
123 return get_time().get_string().c_str();
128 TimePoint::absorb(const TimePoint& x)
130 if(get_guid()==x.get_guid())
132 set_guid(get_guid()^x.get_guid());
134 if(get_after()==INTERPOLATION_NIL)
135 set_after(x.get_after());
136 if(get_before()==INTERPOLATION_NIL)
137 set_before(x.get_before());
139 if(get_after()!=x.get_after() && x.get_after()!=INTERPOLATION_NIL)
140 set_after(INTERPOLATION_UNDEFINED);
141 if(get_before()!=x.get_before() && x.get_before()!=INTERPOLATION_NIL)
142 set_before(INTERPOLATION_UNDEFINED);
145 TimePointSet::iterator
146 TimePointSet::insert(const TimePoint& x)
148 iterator iter(find(x));
151 const_cast<TimePoint&>(*iter).absorb(x);
154 return std::set<TimePoint>::insert(x).first;
174 time_last_changed_(__sys_clock()),
177 #ifndef BE_FRUGAL_WITH_GUIDS
180 assert(!global_node_map().count(guid_));
181 global_node_map()[guid_]=this;
191 assert(global_node_map().count(guid_));
192 global_node_map().erase(guid_);
193 assert(!global_node_map().count(guid_));
200 time_last_changed_=__sys_clock();
205 //! Gets the GUID for this value node
207 Node::get_guid()const
209 #ifdef BE_FRUGAL_WITH_GUIDS
212 const_cast<synfig::GUID&>(guid_).make_unique();
214 assert(!global_node_map().count(guid_));
215 global_node_map()[guid_]=const_cast<Node*>(this);
222 //! Sets the GUID for this value node
224 Node::set_guid(const synfig::GUID& x)
228 #ifdef BE_FRUGAL_WITH_GUIDS
232 assert(!global_node_map().count(guid_));
233 global_node_map()[guid_]=this;
239 synfig::GUID oldguid(guid_);
241 refresh_node(this, oldguid);
242 on_guid_changed(oldguid);
247 Node::get_time_last_changed()const
249 return time_last_changed_;
253 Node::add_child(Node*x)
255 x->parent_set.insert(this);
259 Node::remove_child(Node*x)
261 if(x->parent_set.count(this)) x->parent_set.erase(this);
265 Node::parent_count()const
267 return parent_set.size();
270 const Node::time_set &
271 Node::get_times() const
276 get_times_vfunc(times);
280 //set the output set...
289 deleting_=true; signal_deleted()();
299 std::set<Node*>::iterator iter;
300 for(iter=parent_set.begin();iter!=parent_set.end();++iter)
307 Node::on_guid_changed(synfig::GUID guid)
309 signal_guid_changed()(guid);