IComponentType.h
1 
27 #ifndef COSMO_COMPONENT_TYPE_INTERFACE_H
28 #define COSMO_COMPONENT_TYPE_INTERFACE_H
29 
30 #include <Pt/Cosmo/IUnknown.h>
31 #include <Pt/Cosmo/IEnumerable.h>
32 
33 #include <typeinfo>
34 
35 namespace Pt {
36 
37 namespace Cosmo {
38 
39 class Component;
40 
50 {
51  public:
54  virtual ~IComponentType()
55  {}
56 
61  bool hasFeatureId(const char* featureId) const;
62 
65  const IEnumerable<const char*>& featureIds() const;
66 
69  const char* classId() const;
70 
73  template <typename I>
74  bool hasInterface() const;
75 
80  template <typename I>
81  I* queryInterface(Component& c) const;
82 
83  protected:
86  virtual bool onHasFeatureId(const char* featureId) const = 0;
87 
90  virtual const IEnumerable<const char*>& onGetFeatureIds() const = 0;
91 
94  virtual const char* onGetClassId() const = 0;
95 
98  virtual bool onHasInterface(const std::type_info& ti) const = 0;
99 
103  const std::type_info& ti) const = 0;
104 };
105 
106 } // namespace Cosmo
107 
108 } // namespace Pt
109 
110 #include <Pt/Cosmo/Component.h>
111 
112 namespace Pt {
113 
114 namespace Cosmo {
115 
116 inline bool IComponentType::hasFeatureId(const char* featureId) const
117 {
118  return onHasFeatureId(featureId);
119 }
120 
121 
123 {
124  return onGetFeatureIds();
125 }
126 
127 
128 inline const char* IComponentType::classId() const
129 {
130  return onGetClassId();
131 }
132 
133 
134 template <typename I>
136 {
137  const std::type_info& ti = typeid(I);
138  return onHasInterface(ti);
139 }
140 
141 
142 template <typename I>
144 {
145  const std::type_info& ti = typeid(I);
146  IUnknown* unknown = onQueryInterface(c, ti);
147  return static_cast<I*>(unknown);
148 }
149 
150 } // namespace Cosmo
151 
152 } // namespace Pt
153 
154 #endif // include guard
Core module.
Definition: Allocator.h:33
I * queryInterface(Component &c) const
Returns the interface or null if not implemented.
Definition: IComponentType.h:143
virtual ~IComponentType()
Destructor.
Definition: IComponentType.h:54
Component base class.
Definition: Component.h:52
virtual const char * onGetClassId() const =0
Returns the class ID of the component.
virtual const IEnumerable< const char * > & onGetFeatureIds() const =0
Returns the implemented feature IDs.
Component interface query.
Definition: IComponentType.h:50
virtual IUnknown * onQueryInterface(Component &c, const std::type_info &ti) const =0
Returns the interface or null if the interface is not implemented.
virtual bool onHasInterface(const std::type_info &ti) const =0
Returns true if the interface is implemented.
Interface base class.
Definition: IUnknown.h:44
bool hasFeatureId(const char *featureId) const
Returns true if the given feature ID is implemented.
Definition: IComponentType.h:116
const char * classId() const
Returns the class ID of the component.
Definition: IComponentType.h:128
const IEnumerable< const char * > & featureIds() const
Returns the implemented feature IDs.
Definition: IComponentType.h:122
bool hasInterface() const
Returns true if the interface is implemented.
Definition: IComponentType.h:135
virtual bool onHasFeatureId(const char *featureId) const =0
Returns true if the given feature ID is implemented.