Trabalho Prático - PDS2
Carregando...
Procurando...
Nenhuma entrada encontrado
Referência da Classe PlayerManager

Estruturas de Dados

struct  PlayerData
 

Membros Públicos

 PlayerManager ()
 Constructs a new PlayerManager object.
 
void loadPlayers (const std::string &filename)
 Loads player data from a file and adds players to the manager.
 
void addPlayer (const std::string &name, const std::string &nickname, Stats stats)
 Adds a new player to the player manager.
 
void addPlayer (const std::string &name, const std::string &nickname)
 Adds a player to the PlayerManager.
 
void removePlayer (const std::string &nickname)
 Removes a player from the player list by their nickname.
 
void printPlayerByNickname (const std::string &nickname)
 Prints the player information based on the provided nickname.
 
void printPlayerByName (const std::string &name)
 Prints the player information by name.
 
std::vector< Player >::iterator getPlayer (const std::string &nickname)
 Retrieves an iterator to a player with the specified nickname.
 
void updatePlayerStats (const std::string &nickname, char result)
 Updates the statistics of a player based on the game result.
 
void exportPlayerData ()
 Exports player data to a CSV file.
 
void printTable ()
 Prints a formatted table of player information.
 
int getPlayerCount ()
 Get the current number of players.
 
 ~PlayerManager ()
 Destructor for the PlayerManager class.
 

Membros privados

bool readBasicFields (std::istringstream &ss, PlayerData &data)
 Reads basic fields (id, name, and nickname) from a given input stream.
 
bool readStatsFields (std::istringstream &ss, PlayerData &data)
 Reads the statistics fields from the input stream and populates the PlayerData structure.
 
bool readField (std::istringstream &ss, std::string &field)
 Reads a field from a given input string stream.
 
bool readPlayerFromFile (std::istringstream &ss, PlayerData &data)
 Reads player data from a given input stream.
 
size_t getMaxNameLength ()
 Get the maximum length of player names.
 
size_t getMaxNicknameLength ()
 Get the maximum length of nicknames among all players.
 

Atributos Privados

std::vector< Playerplayers
 
int num_players
 

Construtores e Destrutores

◆ PlayerManager()

Constructs a new PlayerManager object.

Initializes the players vector and sets the number of players to zero.

Documentação das funções

◆ addPlayer() [1/2]

void addPlayer ( const std::string & name,
const std::string & nickname )

Adds a player to the PlayerManager.

Parâmetros
nameThe name of the player.
nicknameThe nickname of the player.
Exceções
PlayerAlreadyExistsExceptionif a player with the same name and nickname already exists.
Este é o diagrama das funções utilizadas por essa função:

◆ addPlayer() [2/2]

void addPlayer ( const std::string & name,
const std::string & nickname,
Stats stats )

Adds a new player to the player manager.

Parâmetros
nameThe name of the player.
nicknameThe nickname of the player.
statsThe stats of the player.
Exceções
InvalidInputExceptionif the name or nickname is invalid.
PlayerAlreadyExistsExceptionif a player with the same nickname already exists.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ exportPlayerData()

void exportPlayerData ( )

Exports player data to a CSV file.

This function creates and writes player data to a CSV file located at "./saves/save.csv". The CSV file contains the following columns:

  • Id: Player's unique identifier
  • Name: Player's name
  • Nickname: Player's nickname
  • TotalWins: Total number of wins
  • WinsTTT: Number of wins in Tic-Tac-Toe
  • WinsLig4: Number of wins in Connect Four
  • WinsReversi: Number of wins in Reversi
  • TotalLoses: Total number of losses
  • LosesTTT: Number of losses in Tic-Tac-Toe
  • LosesLig4: Number of losses in Connect Four
  • LosesReversi: Number of losses in Reversi
Exceções
std::runtime_errorif the file cannot be opened.
Esse é o diagrama das funções que utilizam essa função:

◆ getMaxNameLength()

size_t getMaxNameLength ( )
private

Get the maximum length of player names.

Retorna
size_t The length of the longest player name.
Esse é o diagrama das funções que utilizam essa função:

◆ getMaxNicknameLength()

size_t getMaxNicknameLength ( )
private

Get the maximum length of nicknames among all players.

Retorna
size_t The length of the longest nickname.
Esse é o diagrama das funções que utilizam essa função:

◆ getPlayer()

std::vector< Player >::iterator getPlayer ( const std::string & nickname)

Retrieves an iterator to a player with the specified nickname.

Parâmetros
nicknameThe nickname of the player to search for.
Retorna
std::vector<Player>::iterator An iterator pointing to the player with the specified nickname.
Exceções
PlayerNotInListExceptionIf no player with the specified nickname is found.
Esse é o diagrama das funções que utilizam essa função:

◆ getPlayerCount()

int getPlayerCount ( )

Get the current number of players.

Retorna
int The number of players.

◆ loadPlayers()

void loadPlayers ( const std::string & filename)

Loads player data from a file and adds players to the manager.

Parâmetros
filenameThe path to the file containing player data.

The function handles the following:

  • Opens the file and checks for errors.
  • Skips the header line.
  • Reads each line of player data and parses it.
  • Converts string data to appropriate types for player statistics.
  • Adds each player to the PlayerManager.
  • Handles exceptions for players that already exist.
Observação
If there is an error opening the file, an error message is printed to the standard error stream.
If there is an error parsing a line, an error message is printed to the standard error stream.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ printPlayerByName()

void printPlayerByName ( const std::string & name)

Prints the player information by name.

Parâmetros
nameThe name of the player to search for.
Exceções
InexistentPlayerExceptionif the player with the given name does not exist.
Esse é o diagrama das funções que utilizam essa função:

◆ printPlayerByNickname()

void printPlayerByNickname ( const std::string & nickname)

Prints the player information based on the provided nickname.

Parâmetros
nicknameThe nickname of the player to be printed.
Exceções
InexistentPlayerExceptionif the player with the given nickname does not exist.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ printTable()

void printTable ( )

Prints a formatted table of player information.

This function prints a table with the following columns:

  • Id: The player's unique identifier.
  • Apelido: The player's nickname.
  • Nome: The player's name.
  • Total de vitorias: The total number of victories the player has achieved.
  • Total de derrotas: The total number of defeats the player has suffered.

The column widths are dynamically adjusted based on the maximum lengths of the player names and nicknames to ensure proper alignment.

Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ readBasicFields()

bool readBasicFields ( std::istringstream & ss,
PlayerData & data )
private

Reads basic fields (id, name, and nickname) from a given input stream.

Parâmetros
ssThe input stream containing the player data.
dataThe PlayerData object where the read fields will be stored.
Retorna
true if all fields are successfully read, false otherwise.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ readField()

bool readField ( std::istringstream & ss,
std::string & field )
private

Reads a field from a given input string stream.

Parâmetros
ssThe input string stream to read from.
fieldThe string reference where the read field will be stored.
Retorna
true if a field was successfully read, false otherwise.
Esse é o diagrama das funções que utilizam essa função:

◆ readPlayerFromFile()

bool readPlayerFromFile ( std::istringstream & ss,
PlayerData & data )
private

Reads player data from a given input stream.

Parâmetros
ssThe input stream containing player data.
dataThe PlayerData structure to be populated with the read values.
Retorna
true if both basic fields and stats fields are successfully read, false otherwise.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ readStatsFields()

bool readStatsFields ( std::istringstream & ss,
PlayerData & data )
private

Reads the statistics fields from the input stream and populates the PlayerData structure.

Parâmetros
ssThe input string stream containing the statistics data.
dataThe PlayerData structure to be populated with the read statistics.
Retorna
true if all fields were successfully read and assigned; false otherwise.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ removePlayer()

void removePlayer ( const std::string & nickname)

Removes a player from the player list by their nickname.

Parâmetros
nicknameThe nickname of the player to be removed.
Exceções
InexistentPlayerExceptionif the player with the given nickname is not found in the list.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ updatePlayerStats()

void updatePlayerStats ( const std::string & nickname,
char result )

Updates the statistics of a player based on the game result.

Parâmetros
nicknameThe nickname of the player whose statistics are to be updated.
resultThe result of the game ('W' for win, 'L' for loss, etc.).
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

A documentação para essa classe foi gerada a partir dos seguintes arquivos: