CPP04 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Character クラス

Represents a character capable of equipping and using Materias. [詳解]

#include <Character.hpp>

Character の継承関係図
Inheritance graph
Character 連携図
Collaboration graph

公開メンバ関数

 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.
 
Characteroperator= (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.
 
AMateriagetMateriaAtSlot (int idx) const
 Gets a pointer to the Materia at a specific inventory slot.
 
- 基底クラス ICharacter に属する継承公開メンバ関数
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.hpp39 行目に定義があります。

構築子と解体子

◆ Character() [1/2]

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.

引数
nameThe name of the character.

Character.cpp33 行目に定義があります。

◆ Character() [2/2]

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.

引数
otherThe Character object to copy from.

Character.cpp46 行目に定義があります。

◆ ~Character()

Character::~Character ( )
virtual

Destroys the Character object. Deallocates all dynamically allocated Materia objects currently in the inventory to prevent memory leaks.

Character.cpp88 行目に定義があります。

関数詳解

◆ equip()

void Character::equip ( AMateria m)
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.

引数
mA pointer to the AMateria object to equip. Takes ownership of the Materia.

ICharacterを実装しています。

Character.cpp107 行目に定義があります。

◆ getMateriaAtSlot()

AMateria * Character::getMateriaAtSlot ( int  idx) const
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.

引数
idxThe index of the inventory slot (0-3).
戻り値
A pointer to the AMateria object if the slot is valid and occupied, otherwise returns NULL.

ICharacterを実装しています。

Character.cpp175 行目に定義があります。

◆ getName()

std::string const & Character::getName ( ) const
virtual

Gets the name of the character.

戻り値
A constant reference to the character's name string.

ICharacterを実装しています。

Character.cpp100 行目に定義があります。

◆ isMateriaEquipped()

bool Character::isMateriaEquipped ( int  idx) const

Checks if a Materia is equipped at a specific inventory slot.

引数
idxThe index of the inventory slot (0-3) to check.
戻り値
True if a Materia is equipped at the given slot, false otherwise (including invalid indices).

Character.cpp163 行目に定義があります。

◆ operator=()

Character & 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.

引数
otherThe Character object to assign from.
戻り値
A reference to the assigned Character object.

Character.cpp64 行目に定義があります。

◆ unequip()

void Character::unequip ( int  idx)
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.

引数
idxThe index of the inventory slot (0-3) to unequip from.

ICharacterを実装しています。

Character.cpp131 行目に定義があります。

◆ use()

void Character::use ( int  idx,
ICharacter target 
)
virtual

Uses the Materia at a specific inventory slot on a target character. Performs bounds checking and checks if the slot is occupied.

引数
idxThe index of the inventory slot (0-3) containing the Materia to use.
targetThe ICharacter object on which the Materia will be used.

ICharacterを実装しています。

Character.cpp148 行目に定義があります。


このクラス詳解は次のファイルから抽出されました: