Kata Tournament Runner  0.1.00
 All Classes Namespaces Functions Variables Enumerations Groups Pages
karateka.h
1 #ifndef TOURNAMENT_RUNNER_KARATEKA_H_
2 #define TOURNAMENT_RUNNER_KARATEKA_H_
3 
4 #include <string>
5 #include <cstdint>
6 #include <vector>
7 #include <array>
8 
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/array.hpp>
11 #include <boost/serialization/nvp.hpp>
12 
13 #include "tournament_runner/date.h"
14 #include "tournament_runner/kata_performer_interface.h"
15 #include "tournament_runner/kataround_scores.h"
16 
17 using boost::array;
18 using boost::serialization::make_nvp;
19 
20 namespace TournamentRunner
21 {
22 
26 constexpr auto max_number_of_kata_rounds = 3;
27 
33 class Karateka :
34  public IKataPerformer
35 {
36 public:
37 
38  // Karateka() = default;
39 
40  Karateka& with_name (const std::string& karateka_name);
41  Karateka& with_name (std::string&& karateka_name) noexcept;
42  Karateka& with_surname (const std::string& karateka_surname);
43  Karateka& with_surname (std::string&& karateka_surname) noexcept;
44  Karateka& with_birthdate (const Date& birthdate);
45  Karateka& with_birthdate (Date&& birthdate) noexcept;
46  Karateka& with_birthdate (const std::string& birthdate_as_string);
47  Karateka& from_dojo (const std::string& dojo_name);
48  Karateka& from_dojo (std::string&& dojo_name) noexcept;
49  Karateka& with_grade (const std::string& grade_as_string);
50  Karateka& with_grade (std::string&& grade_as_string) noexcept;
51 
52 
57  void set_startnumber (size_t start_number);
58 
63  size_t get_startnumber() const;
64 
69  void add_kata_score (float score) final;
70 
75  void add_deduction (float deduction) final;
76 
81  uint8_t next_round () final;
82 
86  float get_maximum_score_of_round (uint8_t round) const final;
87 
91  float get_minimum_score_of_round (uint8_t round) const final;
92 
96  float get_overall_score_of_round (uint8_t round) const final;
97 
101  float get_maximum_score_of_current_round () const final;
102 
106  float get_minimum_score_of_current_round () const final;
107 
111  float get_overall_score_of_current_round () const final;
112 
113 
119  KataRoundScores::ScoreVectorType get_scores (uint8_t round) const;
120 
121  float get_deduction (uint8_t round) const;
122 
127  std::string name () const;
132  std::string surname () const;
133 
138  std::string date_of_birth_as_string () const;
139 
144  Date date_of_birth () const;
145 
150  std::string dojo () const;
155  std::string grade () const;
156 
157 private:
158 
159  friend class boost::serialization::access;
160 
164  template<class Archive>
165  void serialize (Archive& archive, const unsigned int version);
166 
167  std::string name_{};
168  std::string surname_{};
169  Date date_of_birth_{};
170  std::string dojo_{};
171  std::string grade_{};
172  array<KataRoundScores, max_number_of_kata_rounds> kata_scores_;
173  size_t start_number_{};
174  uint8_t current_kata_round_{};
175 };
176 
189  const IKataPerformer& rhs);
190 
197 bool kata_score_is_equal(const IKataPerformer& lhs,
198  const IKataPerformer& rhs);
199 
200 inline void Karateka::set_startnumber (size_t start_number)
201 {
202  start_number_ = start_number;
203 }
204 
205 inline size_t Karateka::get_startnumber () const
206 {
207  return start_number_;
208 }
209 
210 inline std::string Karateka::name () const
211 {
212  return name_;
213 }
214 
215 inline std::string Karateka::surname () const
216 {
217  return surname_;
218 }
219 
220 inline std::string Karateka::date_of_birth_as_string () const
221 {
222  return date_of_birth_.to_iso_extended_string();
223 }
224 
226 {
227  return date_of_birth_;
228 }
229 
230 inline std::string Karateka::dojo () const
231 {
232  return dojo_;
233 }
234 
235 inline std::string Karateka::grade () const
236 {
237  return grade_;
238 }
239 
240 template<class Archive>
241 void Karateka::serialize (Archive& archive,
242  const unsigned int)
243 {
244  archive & make_nvp("Name", name_);
245  archive & make_nvp("Surname", surname_);
246  archive & make_nvp("DateOfBirth", date_of_birth_);
247  archive & make_nvp("Dojo", dojo_);
248  archive & make_nvp("Grade", grade_);
249  archive & make_nvp("Scores", kata_scores_);
250  archive & make_nvp("Startnumber", start_number_);
251  archive & make_nvp("CurrentKataRound", current_kata_round_);
252 }
253 
254 } //namespace TournamentRunner
255 
256 #endif // TOURNAMENT_RUNNER_KARATEKA_H_
std::string dojo() const
Return the dojo the Karateka belongs to.
Definition: karateka.h:230
KataRoundScores::ScoreVectorType get_scores(uint8_t round) const
Return all scores of a round.
Definition: karateka.cpp:124
float get_minimum_score_of_current_round() const final
Return the minimum score of the current round.
Definition: karateka.cpp:114
Date date_of_birth() const
Return a date of birth string of the Karateka.
Definition: karateka.h:225
void add_deduction(float deduction) final
Add a deduction, which is subtracted from the overall score.
Definition: karateka.cpp:79
The Karateka class.
Definition: karateka.h:33
size_t get_startnumber() const
Return the startnumber.
Definition: karateka.h:205
float get_overall_score_of_round(uint8_t round) const final
Return the overall score of the given round.
Definition: karateka.cpp:104
std::string date_of_birth_as_string() const
Return the date of birth of the Karateka.
Definition: karateka.h:220
std::string grade() const
Return the rank of the Karateka.
Definition: karateka.h:235
std::string to_iso_extended_string() const
Return date as extended iso string.
Definition: date.cpp:23
float get_maximum_score_of_round(uint8_t round) const final
Return the maximum score of the given round.
Definition: karateka.cpp:94
float get_overall_score_of_current_round() const final
Return the overall score of the current round.
Definition: karateka.cpp:119
bool kata_score_sort_greater(const IKataPerformer &lhs, const IKataPerformer &rhs)
Karateka score compare method for std::sort algorithm.
Definition: karateka.cpp:171
The Date class provides Date handling based on the boost::gregorian::date.
Definition: date.h:21
void add_kata_score(float score) final
Add a kata score for the current round.
Definition: karateka.cpp:74
std::string name() const
Return the name of the Karateka.
Definition: karateka.h:210
The IKataPerformer interface.
Definition: kata_performer_interface.h:15
void set_startnumber(size_t start_number)
set_startnumber
Definition: karateka.h:200
float get_maximum_score_of_current_round() const final
Return the maximum score of the current round.
Definition: karateka.cpp:109
uint8_t next_round() final
Move to next round.
Definition: karateka.cpp:84
bool kata_score_is_equal(const IKataPerformer &lhs, const IKataPerformer &rhs)
kata_score_is_equal
Definition: karateka.cpp:186
constexpr auto max_number_of_kata_rounds
Max number of kata rounds (3)
Definition: karateka.h:26
std::string surname() const
Return the surname of the Karateka.
Definition: karateka.h:215
float get_minimum_score_of_round(uint8_t round) const final
Return the minimum score of the given round.
Definition: karateka.cpp:99