|
Trabalho Prático - PDS2
|
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< Player > | players |
| int | num_players |
| PlayerManager | ( | ) |
Constructs a new PlayerManager object.
Initializes the players vector and sets the number of players to zero.
| void addPlayer | ( | const std::string & | name, |
| const std::string & | nickname ) |
Adds a player to the PlayerManager.
| name | The name of the player. |
| nickname | The nickname of the player. |
| PlayerAlreadyExistsException | if a player with the same name and nickname already exists. |

| void addPlayer | ( | const std::string & | name, |
| const std::string & | nickname, | ||
| Stats | stats ) |
Adds a new player to the player manager.
| name | The name of the player. |
| nickname | The nickname of the player. |
| stats | The stats of the player. |
| InvalidInputException | if the name or nickname is invalid. |
| PlayerAlreadyExistsException | if a player with the same nickname already exists. |


| 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:
| std::runtime_error | if the file cannot be opened. |

|
private |
Get the maximum length of player names.

|
private |
Get the maximum length of nicknames among all players.

| std::vector< Player >::iterator getPlayer | ( | const std::string & | nickname | ) |
Retrieves an iterator to a player with the specified nickname.
| nickname | The nickname of the player to search for. |
std::vector<Player>::iterator An iterator pointing to the player with the specified nickname. | PlayerNotInListException | If no player with the specified nickname is found. |

| int getPlayerCount | ( | ) |
Get the current number of players.
| void loadPlayers | ( | const std::string & | filename | ) |
Loads player data from a file and adds players to the manager.
| filename | The path to the file containing player data. |
The function handles the following:


| void printPlayerByName | ( | const std::string & | name | ) |
Prints the player information by name.
| name | The name of the player to search for. |
| InexistentPlayerException | if the player with the given name does not exist. |

| void printPlayerByNickname | ( | const std::string & | nickname | ) |
Prints the player information based on the provided nickname.
| nickname | The nickname of the player to be printed. |
| InexistentPlayerException | if the player with the given nickname does not exist. |


| void printTable | ( | ) |
Prints a formatted table of player information.
This function prints a table with the following columns:
The column widths are dynamically adjusted based on the maximum lengths of the player names and nicknames to ensure proper alignment.


|
private |
Reads basic fields (id, name, and nickname) from a given input stream.
| ss | The input stream containing the player data. |
| data | The PlayerData object where the read fields will be stored. |


|
private |
Reads a field from a given input string stream.
| ss | The input string stream to read from. |
| field | The string reference where the read field will be stored. |

|
private |
Reads player data from a given input stream.
| ss | The input stream containing player data. |
| data | The PlayerData structure to be populated with the read values. |


|
private |
Reads the statistics fields from the input stream and populates the PlayerData structure.
| ss | The input string stream containing the statistics data. |
| data | The PlayerData structure to be populated with the read statistics. |


| void removePlayer | ( | const std::string & | nickname | ) |
Removes a player from the player list by their nickname.
| nickname | The nickname of the player to be removed. |
| InexistentPlayerException | if the player with the given nickname is not found in the list. |


| void updatePlayerStats | ( | const std::string & | nickname, |
| char | result ) |
Updates the statistics of a player based on the game result.
| nickname | The nickname of the player whose statistics are to be updated. |
| result | The result of the game ('W' for win, 'L' for loss, etc.). |

