CPP04 1.0
|
Represents a character capable of equipping and using Materias. [詳解]
#include <Character.hpp>
公開メンバ関数 | |
Character (std::string const &name) | |
Constructs a Character object with a given name. Initializes the character's name and sets all inventory slots to NULL. | |
Character (const Character &other) | |
Copy constructor for Character. Performs a deep copy of the other character's name and equipped materias. Existing materias in the new character's inventory (if any, from default init) are cleared, and new clones of the other's materias are equipped. | |
Character & | operator= (const Character &other) |
Copy assignment operator for Character. Assigns values from another Character object, ensuring a deep copy of materias. It first deallocates any currently held materias to prevent leaks, then clones and equips materias from the 'other' character. | |
virtual | ~Character () |
Destroys the Character object. Deallocates all dynamically allocated Materia objects currently in the inventory to prevent memory leaks. | |
std::string const & | getName () const |
Gets the name of the character. | |
void | equip (AMateria *m) |
Equips a Materia into the first available inventory slot (0-3). If the inventory is full, the passed Materia is deleted to prevent leaks. | |
void | unequip (int idx) |
Unequips a Materia from a specific inventory slot. The Materia object itself is NOT deleted, only removed from the inventory slot. It's the caller's responsibility to manage the unequipped Materia's memory. | |
void | use (int idx, ICharacter &target) |
Uses the Materia at a specific inventory slot on a target character. Performs bounds checking and checks if the slot is occupied. | |
bool | isMateriaEquipped (int idx) const |
Checks if a Materia is equipped at a specific inventory slot. | |
AMateria * | getMateriaAtSlot (int idx) const |
Gets a pointer to the Materia at a specific inventory slot. | |
![]() | |
virtual | ~ICharacter () |
Virtual destructor for the ICharacter interface. Ensures proper cleanup of derived class objects when deleted through an ICharacter pointer. It has an empty implementation here as it's an interface. | |
Represents a character capable of equipping and using Materias.
The Character
class is a concrete implementation of the ICharacter
interface. Each character has a name and a fixed-size inventory (4 slots) for AMateria
objects. It manages the lifecycle of Materias it owns, performing deep copies during copy construction and assignment to ensure unique Materia instances.
Character.hpp の 39 行目に定義があります。
Character::Character | ( | std::string const & | name | ) |
Constructs a Character object with a given name. Initializes the character's name and sets all inventory slots to NULL.
name | The name of the character. |
Character.cpp の 33 行目に定義があります。
Character::Character | ( | const Character & | other | ) |
Copy constructor for Character. Performs a deep copy of the other character's name and equipped materias. Existing materias in the new character's inventory (if any, from default init) are cleared, and new clones of the other's materias are equipped.
other | The Character object to copy from. |
Character.cpp の 46 行目に定義があります。
|
virtual |
Destroys the Character object. Deallocates all dynamically allocated Materia objects currently in the inventory to prevent memory leaks.
Character.cpp の 88 行目に定義があります。
|
virtual |
Equips a Materia into the first available inventory slot (0-3). If the inventory is full, the passed Materia is deleted to prevent leaks.
m | A pointer to the AMateria object to equip. Takes ownership of the Materia. |
ICharacterを実装しています。
Character.cpp の 107 行目に定義があります。
|
virtual |
Gets a pointer to the Materia at a specific inventory slot.
This method provides read-only access to the Materia pointer at the given index. It performs bounds checking.
idx | The index of the inventory slot (0-3). |
ICharacterを実装しています。
Character.cpp の 175 行目に定義があります。
|
virtual |
Gets the name of the character.
ICharacterを実装しています。
Character.cpp の 100 行目に定義があります。
bool Character::isMateriaEquipped | ( | int | idx | ) | const |
Checks if a Materia is equipped at a specific inventory slot.
idx | The index of the inventory slot (0-3) to check. |
Character.cpp の 163 行目に定義があります。
Copy assignment operator for Character. Assigns values from another Character object, ensuring a deep copy of materias. It first deallocates any currently held materias to prevent leaks, then clones and equips materias from the 'other' character.
other | The Character object to assign from. |
Character.cpp の 64 行目に定義があります。
|
virtual |
Unequips a Materia from a specific inventory slot. The Materia object itself is NOT deleted, only removed from the inventory slot. It's the caller's responsibility to manage the unequipped Materia's memory.
idx | The index of the inventory slot (0-3) to unequip from. |
ICharacterを実装しています。
Character.cpp の 131 行目に定義があります。
|
virtual |
Uses the Materia at a specific inventory slot on a target character. Performs bounds checking and checks if the slot is occupied.
idx | The index of the inventory slot (0-3) containing the Materia to use. |
target | The ICharacter object on which the Materia will be used. |
ICharacterを実装しています。
Character.cpp の 148 行目に定義があります。