From 4dfc82415691fe298f21bb2f81fed5c168ee14e5 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 25 Mar 2013 22:40:43 +0100 Subject: Moved documentation out of class definition Inline documentation is in general needlessly verbose and only makes it harder to read the actual class API. This change moves this kind of documentation to the function implementation for the 'Entity' class. For inline methods, the implementation is moved outside of the class using the 'inline' keyword. This provides a good place to put the documentation, but it also further cleans up the class definition. The class definition now gives a much better overview over its API. And if needed, details can be looked up at the function implementations. Reviewed-by: Erik Schilling --- src/game-server/entity.cpp | 3 + src/game-server/entity.h | 162 ++++++++++++++++++++++++++------------------- 2 files changed, 97 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/game-server/entity.cpp b/src/game-server/entity.cpp index 3593d902..cbfa96f3 100644 --- a/src/game-server/entity.cpp +++ b/src/game-server/entity.cpp @@ -35,6 +35,9 @@ Entity::~Entity() delete mComponents[i]; } +/** + * Updates the internal status. By default, calls update on all its components. + */ void Entity::update() { for (int i = 0; i < ComponentTypeCount; ++i) diff --git a/src/game-server/entity.h b/src/game-server/entity.h index 7aed29e6..9d418df3 100644 --- a/src/game-server/entity.h +++ b/src/game-server/entity.h @@ -48,76 +48,21 @@ class Entity : public sigc::trackable virtual ~Entity(); - /** - * Gets type of this entity. - * - * @return the type of this entity. - */ - EntityType getType() const - { return mType; } - - /** - * Adds a component. Only one component of a given type can be added. - * Entity takes ownership of \a component. - */ - template - void addComponent(T *component) - { - assert(!mComponents[T::type]); - mComponents[T::type] = component; - } - - /** - * Returns the component of the given type, or 0 when no such component - * was set. - */ - Component *getComponent(ComponentType type) const - { return mComponents[type]; } - - /** - * Get a component by its class. Avoids the need for doing a static- - * cast in the calling code. - */ - template - T *getComponent() const - { return static_cast(getComponent(T::type)); } - - /** - * Returns whether this entity is visible on the map or not. (Actor) - */ - bool isVisible() const - { return mType != OBJECT_OTHER; } - - /** - * Returns whether this entity can move on the map or not. (Actor) - */ - bool canMove() const - { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER || - mType == OBJECT_NPC; } - - /** - * Returns whether this entity can fight or not. (Being) - */ - bool canFight() const - { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER; } - - /** - * Updates the internal status. By default, calls update on all its - * components. - */ - virtual void update(); + EntityType getType() const; + + template void addComponent(T *component); + template T *getComponent() const; + + Component *getComponent(ComponentType type) const; - /** - * Gets the map this entity is located on. - */ - MapComposite *getMap() const - { return mMap; } + bool isVisible() const; + bool canMove() const; + bool canFight() const; - /** - * Sets the map this entity is located on. - */ - virtual void setMap(MapComposite *map) - { mMap = map; } + virtual void update(); + + MapComposite *getMap() const; + virtual void setMap(MapComposite *map); sigc::signal signal_inserted; sigc::signal signal_removed; @@ -129,4 +74,85 @@ class Entity : public sigc::trackable Component *mComponents[ComponentTypeCount]; }; +/** + * Gets type of this entity. + * + * @return the type of this entity. + */ +inline EntityType Entity::getType() const +{ + return mType; +} + +/** + * Adds a component. Only one component of a given type can be added. + * Entity takes ownership of \a component. + */ +template +inline void Entity::addComponent(T *component) +{ + assert(!mComponents[T::type]); + mComponents[T::type] = component; +} + +/** + * Returns the component of the given type, or 0 when no such component + * was set. + */ +inline Component *Entity::getComponent(ComponentType type) const +{ + return mComponents[type]; +} + +/** + * Get a component by its class. Avoids the need for doing a static- + * cast in the calling code. + */ +template +inline T *Entity::getComponent() const +{ + return static_cast(getComponent(T::type)); +} + +/** + * Returns whether this entity is visible on the map or not. (Actor) + */ +inline bool Entity::isVisible() const +{ + return mType != OBJECT_OTHER; +} + +/** + * Returns whether this entity can move on the map or not. (Actor) + */ +inline bool Entity::canMove() const +{ + return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER || + mType == OBJECT_NPC; +} + +/** + * Returns whether this entity can fight or not. (Being) + */ +inline bool Entity::canFight() const +{ + return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER; +} + +/** + * Gets the map this entity is located on. + */ +inline MapComposite *Entity::getMap() const +{ + return mMap; +} + +/** + * Sets the map this entity is located on. + */ +inline void Entity::setMap(MapComposite *map) +{ + mMap = map; +} + #endif // ENTITY_H -- cgit v1.2.3-60-g2f50