IComponentType.h
1
26
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
35namespace Pt {
36
37namespace Cosmo {
38
39class Component;
40
50{
51 public:
55 {}
56
61 bool hasFeatureId(const char* featureId) const;
62
66
69 const char* classId() const;
70
73 template <typename I>
74 bool hasInterface() const;
75
80 template <typename I>
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
112namespace Pt {
113
114namespace Cosmo {
115
116inline bool IComponentType::hasFeatureId(const char* featureId) const
117{
118 return onHasFeatureId(featureId);
119}
120
121
123{
124 return onGetFeatureIds();
125}
126
127
128inline const char* IComponentType::classId() const
129{
130 return onGetClassId();
131}
132
133
134template <typename I>
136{
137 const std::type_info& ti = typeid(I);
138 return onHasInterface(ti);
139}
140
141
142template <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
Component base class.
Definition Component.h:52
Component interface query.
Definition IComponentType.h:50
bool hasFeatureId(const char *featureId) const
Returns true if the given feature ID is implemented.
Definition IComponentType.h:116
virtual bool onHasInterface(const std::type_info &ti) const =0
Returns true if the interface is implemented.
bool hasInterface() const
Returns true if the interface is implemented.
Definition IComponentType.h:135
const IEnumerable< const char * > & featureIds() const
Returns the implemented feature IDs.
Definition IComponentType.h:122
I * queryInterface(Component &c) const
Returns the interface or null if not implemented.
Definition IComponentType.h:143
const char * classId() const
Returns the class ID of the component.
Definition IComponentType.h:128
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 onHasFeatureId(const char *featureId) const =0
Returns true if the given feature ID is implemented.
virtual const char * onGetClassId() const =0
Returns the class ID of the component.
virtual ~IComponentType()
Destructor.
Definition IComponentType.h:54
virtual const IEnumerable< const char * > & onGetFeatureIds() const =0
Returns the implemented feature IDs.
Enumerable interface.
Definition IEnumerable.h:58
Interface base class.
Definition IUnknown.h:44
Cosmo Component Model.
Definition Api.h:53
Core module.
Definition Allocator.h:33