updated readme
[ozulis.git] / src / ozulis / core / id.hxx
blob00fd79aecf96b57d2036f86851feeb8f658c1f72
1 #include <ozulis/core/assert.hh>
3 namespace ozulis
5 namespace core
7 template <typename H>
8 IdBase<H>::IdBase()
9 : Singleton<IdBase<H> > (),
10 childs_(),
11 parents_(),
12 nextId_(1)
16 template <typename H>
17 id_t
18 IdBase<H>::nextId()
20 return IdBase<H>::instance().nextId_++;
23 template <typename H>
24 void
25 IdBase<H>::setParent(id_t parent, id_t child)
27 if (parent == child)
28 return;
30 IdBase<H> & thiz = IdBase<H>::instance();
32 assert(parent < child);
33 thiz.parents_[child] = parent;
34 thiz.childs_[parent].insert(child);
37 template <typename H, typename T>
38 id_t
39 Id<H, T>::id()
41 static id_t id_ = IdBase<H>::nextId();
42 return id_;
45 template <typename H, typename P, typename T>
46 id_t
47 IdP<H, P, T>::id()
49 static id_t id_ = -1;
51 if (id_ != -1)
52 return id_;
54 id_t parent = Id<H, P>::id();
55 id_ = Id<H, T>::id();
57 IdBase<H>::setParent(parent, id_);
58 return id_;