Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Implement serialisation for all required objects #34

Merged
merged 9 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(testmatch_backend)
include(CTest)
include(GenerateExportHeader)

# Build options
option(BUILD_TESTS "Option to also compile testing executables" ON)
Expand Down Expand Up @@ -32,6 +33,11 @@ target_link_libraries(TestMatch PUBLIC
)


# Generate macros for exporting functions
generate_export_header(TestMatch)
target_include_directories(TestMatch PUBLIC ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR})


# OPTIONAL: Build tests:
if (BUILD_TESTS)
add_subdirectory(test)
Expand Down
178 changes: 173 additions & 5 deletions include/Cards.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// -*- lsst-c++ -*-
/* Cards.h
/**
* @file Cards.h
* @author L. Blake
* @brief
* @version 0.1
* @date 2021-03-28
*
* @copyright Copyright (c) 2021
*
*/

Expand All @@ -10,6 +16,8 @@
#include <random>
#include <string>

#include <boost/serialization/base_object.hpp>

#include "Player.h"

// Global Parameters
Expand All @@ -35,6 +43,18 @@ struct BatStats {
int balls;
int fours;
int sixes;

// Serialisation methods
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& bat_avg;
ar& strike_rate;
ar& bat_hand;
ar& runs;
ar& balls;
ar& fours;
ar& sixes;
};
};

/**
Expand Down Expand Up @@ -66,6 +86,26 @@ struct BowlStats {
int spell_maidens;
int spell_runs;
int spell_wickets;

// Serialisation methods
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& bowl_avg;
ar& strike_rate;
ar& bowl_type;
ar& balls;
ar& overs;
ar& over_balls;
ar& maidens;
ar& runs;
ar& wickets;
ar& legal_balls;
ar& spell_balls;
ar& spell_overs;
ar& spell_maidens;
ar& spell_runs;
ar& spell_wickets;
};
};

/**
Expand Down Expand Up @@ -114,6 +154,15 @@ class Dismissal {
* @return
*/
Player* get_fielder();

// Serialisation methods
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& mode;
ar& mode;
ar& bowler;
ar& fielder;
};
};

/**
Expand Down Expand Up @@ -173,13 +222,18 @@ class PlayerCard {
virtual std::string print_card(void) = 0;

// Default destructor

// Serialisation methods
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& player;
};
};

/**
* @brief
*/
class BatterCard : public PlayerCard {
// TODO: implement MATCHTIME

private:
BatStats stats;
Expand Down Expand Up @@ -211,6 +265,17 @@ class BatterCard : public PlayerCard {
// BatterCard(const BatterCard& bc);

~BatterCard();

// Serialisation methods
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<PlayerCard>(*this);
ar& stats;
ar& active;
ar& out;
ar& dism;
ar& mins;
};
};

/**
Expand All @@ -231,7 +296,7 @@ class BowlerCard : public PlayerCard {

// Tracks number of runs in a current over to determine whether that over was
// a maiden
bool is_maiden;
bool is_maiden = true;

void add_ball();

Expand All @@ -254,6 +319,16 @@ class BowlerCard : public PlayerCard {

std::string print_card(void);
std::string print_spell(void);

// Serialisation methods
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<PlayerCard>(*this);
ar& stats;
ar& active;
ar& competency;
ar& add_ball;
};
};

template <typename T>
Expand All @@ -271,17 +346,31 @@ BowlerCard** create_bowling_cards(Team* team);
struct PitchFactors {
double seam;
double spin;

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& seam;
ar& spin;
};
};

/**
* @brief
* @brief Describes a venue and pitch conditions.
*/
struct Venue {
std::string name;
std::string city;
std::string country;

PitchFactors* pitch_factors;

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& name;
ar& city;
ar& country;
ar& pitch_factors;
};
};

/**
Expand All @@ -307,6 +396,16 @@ struct Ball {
Ball* next = nullptr;

Ball* get_next() { return next; };

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& bowler;
ar& batter;
ar& outcome;
ar& legal;
ar& commentary;
ar& next;
};
};

/**
Expand Down Expand Up @@ -354,6 +453,16 @@ class Over {
void add_ball(Ball* ball);

~Over();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& over_num;
ar& first;
ar& last;
ar& num_balls;
ar& num_legal_delivs;
ar& next;
};
};

class Extras {
Expand All @@ -369,6 +478,14 @@ class Extras {
bool update_score(std::string outcome);
std::string print();
int total();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& byes;
ar& legbyes;
ar& noballs;
ar& wides;
}
};

struct FOW {
Expand All @@ -382,6 +499,14 @@ struct FOW {
std::string print();

// TODO: implement value checking for 0 <= balls < 6

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& wkts;
ar& runs;
ar& overs;
ar& balls;
}
};

/**
Expand Down Expand Up @@ -425,6 +550,18 @@ class Partnership {
*/
void add_runs(unsigned int n_runs, bool scorer, bool add_ball);
void end();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& bat1;
ar& bat2;
ar& runs;
ar& bat1_runs;
ar& bat1_balls;
ar& bat2_runs;
ar& bat2_balls;
ar& not_out;
};
};

//~~~~~~~~~~~~~~ Match End Objects ~~~~~~~~~~~~~~//
Expand All @@ -447,6 +584,12 @@ class EndMatch {
virtual std::string print() = 0;

// Default destructor

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& winner;
ar& margin;
};
};

/**
Expand All @@ -457,6 +600,11 @@ class EndInningsWin : public EndMatch {
EndInningsWin(Team* c_winner, int c_runs);

std::string print();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<EndMatch>(*this);
};
};

/**
Expand All @@ -467,6 +615,11 @@ class EndBowlWin : public EndMatch {
EndBowlWin(Team* c_winner, int c_runs);

std::string print();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<EndMatch>(*this);
};
};

/**
Expand All @@ -477,6 +630,11 @@ class EndChaseWin : public EndMatch {
EndChaseWin(Team* c_winner, int c_wkts);

std::string print();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<EndMatch>(*this);
};
};

/**
Expand All @@ -487,6 +645,11 @@ class EndDraw : public EndMatch {
EndDraw();

virtual std::string print();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<EndMatch>(*this);
};
};

/**
Expand All @@ -497,6 +660,11 @@ class EndTie : public EndDraw {
EndTie();

std::string print();

template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<EndDraw>(*this);
};
};

///// CURRENTLY UNDEFINED - FOR TRACKING MILESTONES
Expand Down Expand Up @@ -559,4 +727,4 @@ class BowlMilestone : public Milestone {
std::string string();
};

#endif // CARDS_H
#endif // CARDS_H
Loading