27 #ifndef COSMO_COMPONENT_PLUGIN_H
28 #define COSMO_COMPONENT_PLUGIN_H
30 #include <Pt/Cosmo/ComponentMode.h>
31 #include <Pt/Cosmo/Enumerable.h>
32 #include <Pt/Cosmo/AutoReleasePool.h>
33 #include <Pt/Cosmo/IComponentPlugin.h>
46 class IComponentManager;
51 class ComponentFactory
68 void destroy(Component* instance)
80 explicit FromReference(T& instance)
81 : _instance(&instance)
84 Cosmo::Component* create()
87 void destroy(Cosmo::Component* )
103 template <
typename T,
typename Factory = ComponentFactory<T> >
107 class IdListEnumeration :
public IEnumeration<const char*>
110 IdListEnumeration(
const std::vector<std::string>& list)
112 , _it( list.begin() )
116 virtual bool onIsValid()
const override
118 return _it != _list.end();
121 virtual void onAdvance()
override
126 virtual const char* onGet()
const override
132 const std::vector<std::string>& _list;
133 typename std::vector<std::string>::const_iterator _it;
140 const std::vector<std::string>& strings)
148 IdListEnumeration* e =
new IdListEnumeration(_strings);
154 const std::vector<std::string>& _strings;
160 const Factory& factory = ComponentFactory<T>());
170 const Factory& factory = ComponentFactory<T>());
178 template <
typename I>
183 template <
typename I>
209 const std::type_info& ti)
const override;
214 const std::string& instance)
override;
218 const std::string& instance)
override;
241 template <
typename I>
244 template <
typename I>
247 typedef std::map<std::type_index, IThunk*> ThunkMap;
251 std::string _classId;
252 std::vector<std::string> _featureIds;
255 std::vector<std::string> _dependencies;
258 std::string> _componentManager;
261 IdList _featureIdsEnum;
262 IdList _dependenciesEnum;
269 #include <Pt/Cosmo/ComponentPlugin.tpp>
virtual ComponentMode onGetMode() const override
Returns the component mode.
Core module.
Definition: Allocator.h:33
Enumerable interface.
Definition: IEnumerable.h:58
virtual const char * onGetInfo() const override
Returns the info string of the component.
virtual void onDetach(IComponentManager &cm) override
The plugin is detached from a component manager.
Enumerator implementation.
Definition: IEnumerable.h:118
virtual IUnknown * onQueryInterface(Component &c, const std::type_info &ti) const override
Returns the interface or null if the interface is not implemented.
virtual bool onHasFeatureId(const char *featureId) const override
Returns true if the given feature ID is implemented.
Component base class.
Definition: Component.h:52
virtual void onAttach(IComponentManager &cm, const std::string &instance) override
The plugin is attached to a component manager.
Component plugin interface.
Definition: IComponentPlugin.h:51
Auto-release pool interface.
Definition: IAutoReleasePool.h:46
virtual void onDetach(IComponentManager &cm, const std::string &instance) override
The plugin is detached from a component manager.
Interface base class.
Definition: IUnknown.h:44
Component manager interface.
Definition: IComponentManager.h:55
virtual Component * onCreate() override
Creates a component instance.
Auto-release pool implementation.
Definition: AutoReleasePool.h:45
void registerFeatureId(const char *featureId)
Registers a feature ID.
Default component plugin.
Definition: ComponentPlugin.h:105
void registerInterface()
Registers a component interface.
void registerInterface(I *(T::*getter)())
Registers a component interface.
const char * classId() const
Returns the class ID of the component.
Definition: IComponentType.h:128
~ComponentPlugin()
Destructor.
const char * info() const
Returns the info string of the component.
Definition: IComponentPlugin.h:136
Component flags.
Definition: ComponentMode.h:45
virtual void onDestroy(Component *instance) override
Destroys a component instance.
virtual const IEnumerable< const char * > & onGetFeatureIds() const override
Returns the implemented feature IDs.
bool onHasInterface(const std::type_info &ti) const override
Returns true if the interface is implemented.
ComponentPlugin(const char *featureId, const char *classId, const char *info, ComponentMode mode=ComponentMode::None, const Factory &factory=ComponentFactory< T >())
Constructor.
virtual const IEnumerable< const char * > & onGetDependencies() const override
Returns the feature IDs of the depencies.
void registerDependency(const char *featureId)
Registers the dependency to another component.
Enumerator for IEnumerables.
Definition: IEnumerable.h:283
ComponentMode mode() const
Returns the component mode.
Definition: IComponentPlugin.h:130
virtual const char * onGetClassId() const override
Returns the class ID of the component.