Choreonoid  1.8
HierarchicalClassRegistry.h
Go to the documentation of this file.
1 #ifndef CNOID_UTIL_HIERARCHICAL_CLASS_REGISTRY_H
2 #define CNOID_UTIL_HIERARCHICAL_CLASS_REGISTRY_H
3 
4 #include <typeinfo>
5 #include "exportdecl.h"
6 
7 namespace cnoid {
8 
9 class CNOID_EXPORT HierarchicalClassRegistryBase
10 {
11 public:
14 
16  int registerClassAsTypeInfo(const std::type_info& type, const std::type_info& superType);
17 
18  int superClassId(int classId) const;
19  int numRegisteredClasses() const;
20 
21 protected:
22  int getClassId(const std::type_info& type, int unknownClassId = -1) const;
23 
24 private:
25  class Impl;
26  Impl* impl;
27 };
28 
29 template<class BaseClass>
31 {
32 public:
34  registerClassAsTypeInfo(typeid(BaseClass), typeid(BaseClass));
35  }
36 
38 
39  template<class TargetClass, class SuperClass = BaseClass>
41  registerClassAsTypeInfo(typeid(TargetClass), typeid(SuperClass));
42  return *this;
43  }
44 
45  template<class Object>
46  bool hasRegistration() const {
47  return getClassId(typeid(Object)) >= 0;
48  }
49 
50  template<class Object>
51  int classId(int unknownClassId = -1) const {
52  return getClassId(typeid(Object), unknownClassId);
53  }
54 
55  int classId(const std::type_info& type, int unknownClassId = -1) const {
56  return getClassId(type, unknownClassId);
57  }
58 
59  int classId(const BaseClass* object, int unknownClassId = -1) const {
60  return getClassId(typeid(*object), unknownClassId);
61  }
62 };
63 
64 }
65 
66 #endif
67 
cnoid::HierarchicalClassRegistry
Definition: HierarchicalClassRegistry.h:30
cnoid::HierarchicalClassRegistry::classId
int classId(const std::type_info &type, int unknownClassId=-1) const
Definition: HierarchicalClassRegistry.h:55
cnoid::HierarchicalClassRegistry::classId
int classId(int unknownClassId=-1) const
Definition: HierarchicalClassRegistry.h:51
cnoid::HierarchicalClassRegistry::registerClass
HierarchicalClassRegistry< BaseClass > & registerClass()
Definition: HierarchicalClassRegistry.h:40
cnoid::HierarchicalClassRegistry::classId
int classId(const BaseClass *object, int unknownClassId=-1) const
Definition: HierarchicalClassRegistry.h:59
cnoid::HierarchicalClassRegistryBase::getClassId
int getClassId(const std::type_info &type, int unknownClassId=-1) const
Definition: HierarchicalClassRegistry.cpp:76
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::HierarchicalClassRegistry::HierarchicalClassRegistry
HierarchicalClassRegistry()
Definition: HierarchicalClassRegistry.h:33
cnoid::HierarchicalClassRegistry::hasRegistration
bool hasRegistration() const
Definition: HierarchicalClassRegistry.h:46
cnoid::HierarchicalClassRegistryBase
Definition: HierarchicalClassRegistry.h:9
cnoid::HierarchicalClassRegistryBase::registerClassAsTypeInfo
int registerClassAsTypeInfo(const std::type_info &type, const std::type_info &superType)
Definition: HierarchicalClassRegistry.cpp:38