documented ozulis::core::id
[ozulis.git] / src / ozulis / core / id.hh
blob182d767399d6fdf13f2401752c7142b3e9a47bee
1 #ifndef CORE_ID_HH
2 # define CORE_ID_HH
4 # include <stdint.h>
6 # include <map>
7 # include <set>
9 # include <ozulis/core/singleton.hh>
11 namespace ozulis
13 namespace core
15 typedef int32_t id_t;
17 /**
18 * @brief this template delivers ids for a Base and remember child/parent
19 * associations
21 template <typename Base>
22 class IdBase : public Singleton<IdBase<Base> >
24 public:
25 IdBase();
27 /** @brief get the next available id */
28 static id_t nextId();
29 /** @brief make the assocation between two types */
30 static void setParent(id_t parent, id_t child);
31 /** @brief get the parent of a type */
32 static id_t parent(id_t child);
33 /** @brief check that child is the child of parent */
34 static bool check(id_t parent, id_t child);
36 private:
37 typedef std::map<id_t, std::set<id_t> > childs_t;
38 typedef std::map<id_t, id_t> parents_t;
40 childs_t childs_;
41 parents_t parents_;
42 id_t nextId_;
45 /**
46 * @brief associate an id to a Base and a Type
48 template <typename Base, typename Type>
49 class Id
51 public:
52 static id_t id();
55 /**
56 * @brief make the association between a Parent and a Type
58 template <typename Base, typename Parent, typename Type>
59 class IdP
61 public:
62 static id_t id();
67 extern template class std::map<ozulis::core::id_t,
68 std::set<ozulis::core::id_t> >;
69 extern template class std::map<ozulis::core::id_t, ozulis::core::id_t >;
71 #endif /* !ID_HH */