IComponentPlugin.h
1 
27 #ifndef COSMO_COMPONENT_PLUGIN_INTERFACE_H
28 #define COSMO_COMPONENT_PLUGIN_INTERFACE_H
29 
30 #include <Pt/Cosmo/ComponentMode.h>
31 #include <Pt/Cosmo/IComponentType.h>
32 #include <Pt/Cosmo/IEnumerable.h>
33 
34 namespace Pt {
35 
36 namespace Cosmo {
37 
38 class Component;
39 class IComponentManager;
40 
51 {
52  friend class IComponentManager;
53 
54  public:
58  {}
59 
63 
66  ComponentMode mode() const;
67 
70  const char* info() const;
71 
75 
78  void destroy(Component* instance);
79 
80  protected:
83  virtual void onAttach(IComponentManager& cm, const std::string& instance) = 0;
84 
87  virtual void onDetach(IComponentManager& cm, const std::string& instance) = 0;
88 
91  virtual void onDetach(IComponentManager& cm) = 0;
92 
95  virtual const IEnumerable<const char*>& onGetDependencies() const = 0;
96 
99  virtual ComponentMode onGetMode() const = 0;
100 
103  virtual const char* onGetInfo() const = 0;
104 
107  virtual Component* onCreate() = 0;
108 
111  virtual void onDestroy(Component* instance) = 0;
112 };
113 
114 } // namespace Cosmo
115 
116 } // namespace Pt
117 
118 #include <Pt/Cosmo/Component.h>
119 
120 namespace Pt {
121 
122 namespace Cosmo {
123 
125 {
126  return onGetDependencies();
127 }
128 
129 
131 {
132  return onGetMode();
133 }
134 
135 
136 inline const char* IComponentPlugin::info() const
137 {
138  return onGetInfo();
139 }
140 
141 
143 {
144  Component* component = this->onCreate();
145  component->init(this, decl);
146  return component;
147 }
148 
149 
150 inline void IComponentPlugin::destroy(Component* instance)
151 {
152  onDestroy(instance);
153 }
154 
155 } // namespace Cosmo
156 
157 } // namespace Pt
158 
159 #endif
Core module.
Definition: Allocator.h:33
virtual void onDetach(IComponentManager &cm)=0
The plugin is detached from a component manager.
virtual Component * onCreate()=0
Creates a component instance.
void init(const IComponentType *type, const IComponentDeclaration *decl)
Initializes the component.
virtual void onAttach(IComponentManager &cm, const std::string &instance)=0
The plugin is attached to a component manager.
Component base class.
Definition: Component.h:52
virtual void onDetach(IComponentManager &cm, const std::string &instance)=0
The plugin is detached from a component manager.
void destroy(Component *instance)
Destroys a component instance.
Definition: IComponentPlugin.h:150
virtual ComponentMode onGetMode() const =0
Returns the component mode.
Component interface query.
Definition: IComponentType.h:50
const IEnumerable< const char * > & dependencies() const
Returns the feature IDs of the dependencies.
Definition: IComponentPlugin.h:124
Component plugin interface.
Definition: IComponentPlugin.h:51
virtual void onDestroy(Component *instance)=0
Destroys a component instance.
Component manager interface.
Definition: IComponentManager.h:55
virtual const char * onGetInfo() const =0
Returns the info string of the component.
virtual ~IComponentPlugin()
Destructor.
Definition: IComponentPlugin.h:57
const char * info() const
Returns the info string of the component.
Definition: IComponentPlugin.h:136
Component flags.
Definition: ComponentMode.h:45
Component instance declaration.
Definition: IComponentDeclaration.h:45
virtual const IEnumerable< const char * > & onGetDependencies() const =0
Returns the feature IDs of the depencies.
Component * create(const IComponentDeclaration *decl)
Creates a component instance.
Definition: IComponentPlugin.h:142
ComponentMode mode() const
Returns the component mode.
Definition: IComponentPlugin.h:130