1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: node.cpp,v 1.5 2005/01/07 03:29:12 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
24 #define HASH_MAP_H <ext/hash_map>
34 #include "proto/nodebase.h"
38 using namespace __gnu_cxx;
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
51 /* === M A C R O S ========================================================= */
53 // About BE_FRUGAL_WITH_GUIDS
54 // If this macro is set, then a GUID will NOT
55 // be calculated until the first call to get_guid()
56 // This also means that the node doesn't get
57 // added to the database until get_guid() is called
58 // for the first time, or set_guid() is called.
59 // If it is expensive to calculate GUIDs, then
60 // this can improve performance a tad in
61 // some cases. Otherwise, it doesn't change
63 #define BE_FRUGAL_WITH_GUIDS 1
68 # define __sys_clock ::clock
72 # define __sys_clock ::clock
75 extern clock_t _clock();
76 # define CLOCKS_PER_SEC 1000
77 # define __sys_clock _clock
82 /* === G L O B A L S ======================================================= */
85 typedef hash_map<GUID,Node*,GUIDHash> GlobalNodeMap;
87 typedef map<GUID,Node*> GlobalNodeMap;
90 static GlobalNodeMap* global_node_map_;
92 static GlobalNodeMap& global_node_map()
95 global_node_map_=new GlobalNodeMap;
96 return *global_node_map_;
99 /* === P R O C E D U R E S ================================================= */
102 synfig::find_node(const GUID& guid)
104 if(global_node_map().count(guid)==0)
106 return global_node_map()[guid];
110 refresh_node(synfig::Node* node, GUID old_guid)
112 assert(global_node_map().count(old_guid));
113 global_node_map().erase(old_guid);
114 assert(!global_node_map().count(old_guid));
115 global_node_map()[node->get_guid()]=node;
118 /* === M E T H O D S ======================================================= */
121 TimePoint::absorb(const TimePoint& x)
123 if(get_guid()==x.get_guid())
125 set_guid(get_guid()^x.get_guid());
127 if(get_after()==INTERPOLATION_NIL)
128 set_after(x.get_after());
129 if(get_before()==INTERPOLATION_NIL)
130 set_before(x.get_before());
132 if(get_after()!=x.get_after() && x.get_after()!=INTERPOLATION_NIL)
133 set_after(INTERPOLATION_UNDEFINED);
134 if(get_before()!=x.get_before() && x.get_before()!=INTERPOLATION_NIL)
135 set_before(INTERPOLATION_UNDEFINED);
138 TimePointSet::iterator
139 TimePointSet::insert(const TimePoint& x)
141 iterator iter(find(x));
144 const_cast<TimePoint&>(*iter).absorb(x);
147 return std::set<TimePoint>::insert(x).first;
169 #ifndef BE_FRUGAL_WITH_GUIDS
172 assert(!global_node_map().count(guid_));
173 global_node_map()[guid_]=this;
183 assert(global_node_map().count(guid_));
184 global_node_map().erase(guid_);
185 assert(!global_node_map().count(guid_));
192 time_last_changed_=__sys_clock();
197 //! Gets the GUID for this value node
199 Node::get_guid()const
201 #ifdef BE_FRUGAL_WITH_GUIDS
206 assert(!global_node_map().count(guid_));
207 global_node_map()[guid_]=this;
214 //! Sets the GUID for this value node
216 Node::set_guid(const GUID& x)
220 #ifdef BE_FRUGAL_WITH_GUIDS
224 assert(!global_node_map().count(guid_));
225 global_node_map()[guid_]=this;
233 refresh_node(this, oldguid);
234 on_guid_changed(oldguid);
239 Node::get_time_last_changed()const
241 return time_last_changed_;
245 Node::add_child(Node*x)
247 x->parent_set.insert(this);
251 Node::remove_child(Node*x)
253 if(x->parent_set.count(this)) x->parent_set.erase(this);
257 Node::parent_count()const
259 return parent_set.size();
262 const Node::time_set &
263 Node::get_times() const
268 get_times_vfunc(times);
272 //set the output set...
281 deleting_=true; signal_deleted()();
291 std::set<Node*>::iterator iter;
292 for(iter=parent_set.begin();iter!=parent_set.end();++iter)
299 Node::on_guid_changed(GUID guid)
301 signal_guid_changed()(guid);