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>
68 void destroy(Component* instance)
80 explicit FromReference(T& instance)
81 : _instance(&instance)
84 Cosmo::Component* create()
87 void destroy(Cosmo::Component* )
103template <
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;
158 ComponentPlugin(
const char* featureId,
const char*
info,
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;
221 virtual void onDetach(IComponentManager& cm)
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;
257 std::multimap<IComponentManager*,
258 std::string> _componentManager;
261 IdList _featureIdsEnum;
262 IdList _dependenciesEnum;
269#include <Pt/Cosmo/ComponentPlugin.tpp>
Auto-release pool implementation.
Definition AutoReleasePool.h:45
Component flags.
Definition ComponentMode.h:45
virtual bool onHasFeatureId(const char *featureId) const override
Returns true if the given feature ID is implemented.
void registerDependency(const char *featureId)
Registers the dependency to another component.
virtual const char * onGetClassId() const override
Returns the class ID of the component.
virtual void onDetach(IComponentManager &cm) override
The plugin is detached from a component manager.
void registerFeatureId(const char *featureId)
Registers a feature ID.
virtual const IEnumerable< const char * > & onGetFeatureIds() const override
Returns the implemented feature IDs.
virtual Component * onCreate() override
Creates a component instance.
virtual IUnknown * onQueryInterface(Component &c, const std::type_info &ti) const override
Returns the interface or null if the interface is not implemented.
void registerInterface()
Registers a component interface.
~ComponentPlugin()
Destructor.
virtual void onDestroy(Component *instance) override
Destroys a component instance.
virtual ComponentMode onGetMode() const override
Returns the component mode.
void registerInterface(I *(T::*getter)())
Registers a component interface.
virtual const char * onGetInfo() const override
Returns the info string of the component.
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.
virtual void onAttach(IComponentManager &cm, const std::string &instance) override
The plugin is attached to a component manager.
virtual void onDetach(IComponentManager &cm, const std::string &instance) override
The plugin is detached from a component manager.
Component base class.
Definition Component.h:52
Enumerator for IEnumerables.
Definition IEnumerable.h:283
Auto-release pool interface.
Definition IAutoReleasePool.h:46
Component manager interface.
Definition IComponentManager.h:55
Component plugin interface.
Definition IComponentPlugin.h:51
ComponentMode mode() const
Returns the component mode.
Definition IComponentPlugin.h:130
const char * info() const
Returns the info string of the component.
Definition IComponentPlugin.h:136
const char * classId() const
Returns the class ID of the component.
Definition IComponentType.h:128
Enumerable interface.
Definition IEnumerable.h:58
Enumerator implementation.
Definition IEnumerable.h:118
Interface base class.
Definition IUnknown.h:44
Cosmo Component Model.
Definition Api.h:53
Core module.
Definition Allocator.h:33