1 /* === S I N F 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>
37 using namespace __gnu_cxx;
44 /* === U S I N G =========================================================== */
48 using namespace sinfg;
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<GUID,Node*,GUIDHash> GlobalNodeMap;
86 typedef map<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 sinfg::find_node(const GUID& guid)
103 if(global_node_map().count(guid)==0)
105 return global_node_map()[guid];
109 refresh_node(sinfg::Node* node, 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 ======================================================= */
120 TimePoint::absorb(const TimePoint& x)
122 if(get_guid()==x.get_guid())
124 set_guid(get_guid()^x.get_guid());
126 if(get_after()==INTERPOLATION_NIL)
127 set_after(x.get_after());
128 if(get_before()==INTERPOLATION_NIL)
129 set_before(x.get_before());
131 if(get_after()!=x.get_after() && x.get_after()!=INTERPOLATION_NIL)
132 set_after(INTERPOLATION_UNDEFINED);
133 if(get_before()!=x.get_before() && x.get_before()!=INTERPOLATION_NIL)
134 set_before(INTERPOLATION_UNDEFINED);
137 TimePointSet::iterator
138 TimePointSet::insert(const TimePoint& x)
140 iterator iter(find(x));
143 const_cast<TimePoint&>(*iter).absorb(x);
146 return std::set<TimePoint>::insert(x).first;
168 #ifndef BE_FRUGAL_WITH_GUIDS
171 assert(!global_node_map().count(guid_));
172 global_node_map()[guid_]=this;
182 assert(global_node_map().count(guid_));
183 global_node_map().erase(guid_);
184 assert(!global_node_map().count(guid_));
191 time_last_changed_=__sys_clock();
196 //! Gets the GUID for this value node
198 Node::get_guid()const
200 #ifdef BE_FRUGAL_WITH_GUIDS
205 assert(!global_node_map().count(guid_));
206 global_node_map()[guid_]=this;
213 //! Sets the GUID for this value node
215 Node::set_guid(const GUID& x)
219 #ifdef BE_FRUGAL_WITH_GUIDS
223 assert(!global_node_map().count(guid_));
224 global_node_map()[guid_]=this;
232 refresh_node(this, oldguid);
233 on_guid_changed(oldguid);
238 Node::get_time_last_changed()const
240 return time_last_changed_;
244 Node::add_child(Node*x)
246 x->parent_set.insert(this);
250 Node::remove_child(Node*x)
252 if(x->parent_set.count(this)) x->parent_set.erase(this);
256 Node::parent_count()const
258 return parent_set.size();
261 const Node::time_set &
262 Node::get_times() const
267 get_times_vfunc(times);
271 //set the output set...
280 deleting_=true; signal_deleted()();
290 std::set<Node*>::iterator iter;
291 for(iter=parent_set.begin();iter!=parent_set.end();++iter)
298 Node::on_guid_changed(GUID guid)
300 signal_guid_changed()(guid);