Skip to content

Commit a68b252

Browse files
committed
Added code documentation for common classes
1 parent 809b107 commit a68b252

File tree

6 files changed

+94
-6
lines changed

6 files changed

+94
-6
lines changed

common_src/closed_queue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
class ClosedQueue: public std::runtime_error {
77
public:
8+
/*
9+
* Exception that indicates when a Queue is closed and an operation was performed over it
10+
*/
811
explicit ClosedQueue(const int line_number);
912
};
1013

common_src/game_commands.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,34 @@ class GameCommands {
2424
*/
2525
GameCommands();
2626

27+
/*
28+
* Returns the command code that represents an attack
29+
*/
2730
const uint8_t get_client_attack_code() const;
2831

32+
/*
33+
* Returns the command code that represents the beginning of the server broadcast
34+
*/
2935
const uint8_t get_server_start_broadcast_code() const;
3036

37+
/*
38+
* Returns the command code that represents an enemy death
39+
*/
3140
const uint8_t get_enemy_died_code() const;
3241

42+
/*
43+
* Returns the command code that represents an enemy revival
44+
*/
3345
const uint8_t get_enemy_revived_code() const;
3446

3547
/*
36-
* Returns the action name for a given action by its code
48+
* Returns the command name for a given command by its code
3749
*/
38-
const std::string get_key_from_code(const uint8_t& action_code) const;
50+
const std::string get_key_from_code(const uint8_t& cmd_code) const;
3951

52+
/*
53+
* Returns the command code for a given command by its name
54+
*/
4055
const uint8_t get_code_from_key(const std::string& cmd_key) const;
4156
};
4257

common_src/game_message.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@ class GameMessage {
1414
const std::string enemy_event;
1515

1616
public:
17+
/*
18+
* GameMessage encapsulates essential information for both server and client messages
19+
*/
1720
explicit GameMessage(const uint16_t& enemies_alive, const uint16_t& enemies_dead,
1821
const std::string& enemy_event);
1922

23+
/*
24+
* Returns the number of enemies alive at the time of the creation of the message
25+
*/
2026
const uint16_t get_enemies_alive() const;
2127

28+
/*
29+
* Returns the number of enemies dead at the time of the creation of the message
30+
*/
2231
const uint16_t get_enemies_dead() const;
2332

33+
/*
34+
* Returns the string representation of the enemy event, it can be a revival or death event
35+
*/
2436
const std::string get_enemy_event() const;
2537
};
2638

common_src/jazz_jackrabbit_2_error.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ class JazzJackrabbit2Error: public std::exception {
1414
std::string final_message;
1515

1616
public:
17+
/*
18+
* Custom exception created to be used throught the game, both in the server and in the
19+
* client. It's an upgrade from a regular std::exception because it carries the line number
20+
* (__LINE__) and module name (__FILE__) where the exception was thrown, this has to be filled
21+
* at the time of instantiation by the caller
22+
*/
1723
JazzJackrabbit2Error(const std::string& base_message, const int32_t& line_number,
1824
const std::string& module);
1925

common_src/logger.h

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,92 @@ class Logger {
2525
bool is_activated;
2626

2727
/*
28-
* Logger description. Private constructor to prevent instantiation.
28+
* A mutex is used to ensure the logfile will be accessed by one thread at a time
29+
*/
30+
std::mutex mutex;
31+
32+
/*
33+
* Logger that logs events to a file. It can be used both in the server and in the client with
34+
* their respective methods. It is built using the Singleton pattern. This way we use a single
35+
* logger throughout the process. That is why the constructor is hidden and the instance can be
36+
* accessed with the Logger::get_instance static method
2937
*/
3038
Logger();
3139

3240
/*
33-
* Delete copy constructor. Delete assignment operator.
41+
* Delete copy constructor and copy assignment operator.
3442
*/
3543
Logger(const Logger&) = delete;
3644
Logger& operator=(const Logger&) = delete;
3745

46+
/*
47+
* Delete move constructor and move assignment operator.
48+
*/
49+
Logger(const Logger&&) = delete;
50+
Logger& operator=(const Logger&&) = delete;
3851

52+
/*
53+
* Closes the logfile
54+
*/
3955
void close();
4056

57+
/*
58+
* Returns current time with the format defined by Logger::time_format
59+
*/
4160
const std::string get_current_time();
4261

62+
/*
63+
* Writes in the file the logging output using the time format, the message and the log level
64+
*/
4365
void log(const std::string& log_level, const std::string& message);
4466

45-
std::mutex mutex;
4667

4768
public:
69+
/*
70+
* Uses the Singleton design pattern
71+
* Return the instance
72+
*/
4873
static Logger& get_instance();
4974

75+
/*
76+
* It's a client method, so the log line will include the CLIENT keyword
77+
* Logs the message with log level Logger::LEVEL_INFO
78+
*/
5079
void client_info(const std::string& message);
5180

81+
/*
82+
* It's a client method, so the log line will include the CLIENT keyword
83+
* Logs the message with log level Logger::LEVEL_WARNING
84+
*/
5285
void client_warning(const std::string& message);
5386

87+
/*
88+
* It's a client method, so the log line will include the CLIENT keyword
89+
* Logs the message with log level Logger::LEVEL_ERROR
90+
*/
5491
void client_error(const std::string& message);
5592

93+
/*
94+
* It's a server method, so the log line will include the SERVER keyword
95+
* Logs the message with log level Logger::LEVEL_INFO
96+
*/
5697
void server_info(const std::string& message);
5798

99+
/*
100+
* It's a server method, so the log line will include the SERVER keyword
101+
* Logs the message with log level Logger::LEVEL_WARNING
102+
*/
58103
void server_warning(const std::string& message);
59104

105+
/*
106+
* It's a server method, so the log line will include the SERVER keyword
107+
* Logs the message with log level Logger::LEVEL_ERROR
108+
*/
60109
void server_error(const std::string& message);
61110

111+
/*
112+
* Closes the file before destroying member variables
113+
*/
62114
~Logger();
63115
};
64116

common_src/thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ class Thread: public Runnable {
4343
Thread& operator=(Thread&& other) = delete;
4444
};
4545

46-
#endif
46+
#endif // THREAD_H_

0 commit comments

Comments
 (0)