Kata Tournament Runner  0.1.00
 All Classes Namespaces Functions Variables Enumerations Groups Pages
tournament.h
1 #ifndef TOURNAMENT_RUNNER_TOURNAMENT_H_
2 #define TOURNAMENT_RUNNER_TOURNAMENT_H_
3 
4 #include <string>
5 #include <vector>
6 #include <utility>
7 #include <cstdint>
8 
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/vector.hpp>
11 #include <boost/serialization/nvp.hpp>
12 
13 #include "tournament_runner/karateka.h"
14 #include "tournament_runner/date.h"
15 
16 using boost::serialization::make_nvp;
17 
21 namespace TournamentRunner
22 {
23 
28 {
34  TournamentData& with_name (const std::string& name)
35  {
36  name_ = name;
37  return *this;
38  }
39 
43  TournamentData& with_name (std::string&& name) noexcept
44  {
45  name_ = std::move(name);
46  return *this;
47  }
48 
54  TournamentData& on_date (const Date& date)
55  {
56  date_ = date;
57  return *this;
58  }
59 
63  TournamentData& on_date (Date&& date) noexcept
64  {
65  date_ = std::move(date);
66  return *this;
67  }
68 
75  TournamentData& on_date (const std::string& date_as_string)
76  {
77  date_ = Date(date_as_string);
78  return *this;
79  }
80 
86  TournamentData& at_location (const std::string& address)
87  {
88  location_ = address;
89  return *this;
90  }
91 
95  TournamentData& at_location (std::string&& address) noexcept
96  {
97  location_ = std::move(address);
98  return *this;
99  }
100 
101  std::string name_{};
102  Date date_{};
103  std::string location_{};
104 };
105 
111 {
112 public:
116  Tournament () = default;
117 
122  explicit Tournament (TournamentData data);
123 
128  std::string name () const;
129 
134  std::string date_as_string () const;
135 
140  Date date() const;
141 
146  std::string location () const;
147 
152  void update_data (const TournamentData& data);
153 
158  void add_participant (const Karateka& participant);
159 
164  size_t number_of_participants () const;
165 
171  Karateka& get_participant (size_t start_number);
172 
177  void remove_participant (size_t start_number);
178 
183  std::vector<Karateka> get_ranked_list_of_participants () const;
184 
185  using RankAnnotatedParticipant = std::pair<size_t, Karateka>;
186 
187  static constexpr auto rank_annotated_participant_rank_idx = 0u;
188  static constexpr auto rank_annotated_participant_karateka_idx = 1u;
193  std::vector<RankAnnotatedParticipant> get_anotated_ranked_list_of_participants() const;
194 
199  uint8_t get_current_round () const;
200 
205  uint8_t start_next_kata_round ();
206 
213  std::vector<size_t> get_startlist_for_next_kata_round(size_t no_of_participants_for_round) const;
214 
215 private:
216  void reassign_startnumbers ();
217  friend class boost::serialization::access;
218 
219  template<class Archive>
220  void serialize (Archive& archive,
221  const unsigned int version);
222 
223  std::vector<size_t> get_list_of_participants_for_next_kata_round (size_t no_of_participants_for_round) const;
224 
225  TournamentData data_{};
226  std::vector<Karateka> participants_;
227  uint8_t current_kata_round_{};
228 };
229 
230 
231 inline std::string Tournament::name () const
232 {
233  return data_.name_;
234 }
235 
236 inline std::string Tournament::location () const
237 {
238  return data_.location_;
239 }
240 
241 inline Date Tournament::date () const
242 {
243  return data_.date_;
244 }
245 
246 inline void Tournament::update_data(const TournamentData& data)
247 {
248  data_ = data;
249 }
250 
251 inline uint8_t Tournament::get_current_round() const
252 {
253  return current_kata_round_;
254 }
255 
257 {
258  return participants_.size();
259 }
260 
261 
262 inline Karateka& Tournament::get_participant (size_t start_number)
263 {
264  return participants_.at(start_number);
265 }
266 
267 template<class Archive>
268 void Tournament::serialize (Archive& archive,
269  const unsigned int)
270 {
271  archive & make_nvp("CurrentKataRound", current_kata_round_);
272  archive & make_nvp("Name", data_.name_);
273  archive & make_nvp("Location", data_.location_);
274  archive & make_nvp("Date", data_.date_);
275  archive & make_nvp("Participants", participants_);
276 }
277 
278 } // namespace TournamentRunner
279 
280 #endif // TOURNAMENT_RUNNER_TOURNAMENT_H_
void update_data(const TournamentData &data)
Update the tournament data.
Definition: tournament.h:246
TournamentData & on_date(const std::string &date_as_string)
Set the tournament date.
Definition: tournament.h:75
TournamentData & with_name(const std::string &name)
Set the tournament name.
Definition: tournament.h:34
std::vector< Karateka > get_ranked_list_of_participants() const
Return a ranked list of participants. The highest ranked comes first.
Definition: tournament.cpp:40
The Tournament class is the starting point for the tournament management.
Definition: tournament.h:110
void add_participant(const Karateka &participant)
Register a participant to the tournament.
Definition: tournament.cpp:20
TournamentData & at_location(std::string &&address) noexcept
Definition: tournament.h:95
The Karateka class.
Definition: karateka.h:33
TournamentData & on_date(Date &&date) noexcept
Definition: tournament.h:63
TournamentData & with_name(std::string &&name) noexcept
Definition: tournament.h:43
void remove_participant(size_t start_number)
remove_participant
Definition: tournament.cpp:28
std::vector< RankAnnotatedParticipant > get_anotated_ranked_list_of_participants() const
Return a ranked list of participants anotated with the actual rank.
Definition: tournament.cpp:49
Tournament()=default
Default empty Tournament constructor.
std::string date_as_string() const
Return the date the tournament is held as ISO 8601 extended format string (CCYY-MM-DD) ...
Definition: tournament.cpp:15
The Date class provides Date handling based on the boost::gregorian::date.
Definition: date.h:21
Date date() const
Return the date the tournament is held as Date.
Definition: tournament.h:241
TournamentData & on_date(const Date &date)
Set the tournament date.
Definition: tournament.h:54
uint8_t get_current_round() const
Return the current active round.
Definition: tournament.h:251
std::string name() const
Tournament name.
Definition: tournament.h:231
std::vector< size_t > get_startlist_for_next_kata_round(size_t no_of_participants_for_round) const
Return the startlist for the next kata round.
Definition: tournament.cpp:86
TournamentData & at_location(const std::string &address)
Set the location the tournament is held.
Definition: tournament.h:86
Karateka & get_participant(size_t start_number)
Return the participant with the given startnumber.
Definition: tournament.h:262
uint8_t start_next_kata_round()
Start the next kata round.
Definition: tournament.cpp:74
The TournamentData struct holding all tournament relevant informations.
Definition: tournament.h:27
std::string location() const
Tournament location address.
Definition: tournament.h:236
size_t number_of_participants() const
Return the number of registred participants.
Definition: tournament.h:256