1 #pragma once

    2 #include <crtdbg.h>

    3 #include "EventListener.h"

    4 #include "Event.h"

    5 

    6 class GameObject;

    7 class SubSystem;

    8 

    9 /// Base class for all components, contains pointers to its owner and subsystem

   10 class Component : public EventListener

   11 {

   12 public:

   13     /**

   14     * Base constructor

   15     */

   16     Component(void);

   17 

   18     Component(const std::string& id);

   19 

   20     /**

   21     * Base destructor

   22     */

   23     virtual ~Component(void);

   24 

   25     /**

   26     * virtual familyID to represent the component family as a key value in a hash

   27     * @return the family ID

   28     */

   29     virtual const std::string& familyID() = 0;

   30 

   31     /**

   32     * set the GameObject owner

   33     * @param owner The GO component owner

   34     * @throws IllegalParametersException If owner is NULL

   35     */

   36     void setOwner(GameObject* owner);

   37 

   38     /**

   39     * Get the Owner of this component

   40     * @return the GO owner

   41     */

   42     GameObject* getOwner() const;

   43 

   44     /**

   45     * Set the subsystem

   46     * @param subSystem The subsystem of this component

   47     * @throws IllegalParametersException If subSystem is NULL

   48     */

   49     void setSubSystem(SubSystem* subSystem);

   50 

   51     /**

   52     * Get the Subsystem of this component

   53     * @return the component subsystem

   54     */

   55     SubSystem* getSubSystem();

   56 

   57     const std::string getID();

   58 

   59     /**

   60     * Duplicates this components members

   61     * Creates new Ogre objects when required

   62     * @param name the new name of the component

   63     * @return the new Cloned component

   64     * @throws IllegalParametersException If name is NULL

   65     */

   66     virtual Component* clone(const std::string& name) = 0;

   67 

   68     /**

   69     * initialization function

   70     * implemented by components that require secondary construction

   71     */

   72     virtual void init() = 0;

   73 

   74     /**

   75     * Used to receive events sent from other components/subsystems

   76     * @param event the Event to Handle

   77     */

   78     virtual void handleEvent(Event* event){}

   79 

   80 protected:

   81     GameObject* mOwner; //Parent GameObject owner

   82     SubSystem* mSubSystem; //Parent SubSystem

   83     std::string mID;

   84 private:

   85     //Uncopyable

   86     explicit Component(const Component& co);

   87     Component& operator= (const Component& co);

   88 

   89 };

   90