summaryrefslogtreecommitdiff
path: root/common/message.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/message.h')
-rw-r--r--common/message.h113
1 files changed, 56 insertions, 57 deletions
diff --git a/common/message.h b/common/message.h
index 1c9276d..d2eb5d7 100644
--- a/common/message.h
+++ b/common/message.h
@@ -36,109 +36,96 @@ namespace Message {
class Base {
protected:
- Base(Type t);
+ Base(Type t) : type(t) {}
+ virtual ~Base() {}
public:
const Type type;
-
- virtual std::pair<uint8_t*, std::size_t> serialize() = 0;
- virtual void deserialize(uint8_t* data, std::size_t bytes) = 0;
- };
-
- class NullBase : public Base {
- protected:
- NullBase(Type t);
-
- public:
- virtual std::pair<uint8_t*, std::size_t> serialize();
- virtual void deserialize(uint8_t* data, std::size_t bytes);
- };
-
- template<class Sub>
- class BoostBase : public Base {
- protected:
- BoostBase(Type t);
-
- public:
- virtual std::pair<uint8_t*, std::size_t> serialize();
- virtual void deserialize(uint8_t* data, std::size_t bytes);
-
- template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
- ar & dynamic_cast<Sub&>(*this);
- }
};
class Hello : public Base {
public:
typedef boost::shared_ptr<Hello> p;
- Hello();
- Hello(const std::string& v);
+ Hello(const std::string& v = "") : Base(Types::Hello), version(v) {}
std::string version;
- virtual std::pair<uint8_t*, std::size_t> serialize();
- virtual void deserialize(uint8_t* data, std::size_t bytes);
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int v) {
+ ar & version;
+ }
};
class Login : public Base {
public:
typedef boost::shared_ptr<Login> p;
- Login();
- Login(const std::string& n);
+ Login(const std::string& n = "") : Base(Types::Login), nick(n) {}
std::string nick;
- virtual std::pair<uint8_t*, std::size_t> serialize();
- virtual void deserialize(uint8_t* data, std::size_t bytes);
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int v) {
+ ar & nick;
+ }
};
class LoginResponse : public Base {
public:
typedef boost::shared_ptr<LoginResponse> p;
- LoginResponse();
- LoginResponse(bool ok);
+ LoginResponse(bool ok = false) : Base(Types::LoginResponse), login_ok(ok) {}
bool login_ok;
- virtual std::pair<uint8_t*, std::size_t> serialize();
- virtual void deserialize(uint8_t* data, std::size_t bytes);
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int v) {
+ ar & login_ok;
+ }
};
- class GameStart : public BoostBase<GameStart> {
+ class GameStart : public Base {
public:
typedef boost::shared_ptr<GameStart> p;
- GameStart();
+ GameStart() : Base(Types::GameStart) {}
std::vector<std::string> players;
int player_id;
template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
+ void serialize(Archive & ar, const unsigned int v) {
ar & players;
ar & player_id;
}
};
- class Ready : public NullBase {
+ class Ready : public Base {
public:
typedef boost::shared_ptr<Ready> p;
- Ready();
+ Ready() : Base(Types::Ready) {}
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int v) {
+
+ }
};
- class RoundStart : public NullBase {
+ class RoundStart : public Base {
public:
typedef boost::shared_ptr<RoundStart> p;
- RoundStart();
+ RoundStart() : Base(Types::RoundStart) {}
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int v) {
+
+ }
};
- class RoundState : public BoostBase<RoundState> {
+ class RoundState : public Base {
public:
typedef boost::shared_ptr<RoundState> p;
@@ -152,15 +139,21 @@ namespace Message {
Tiles pond;
template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
+ void serialize(Archive & ar, const unsigned int v) {
ar & hand;
ar & open;
ar & pond;
}
};
- RoundState();
- RoundState(const Player& pl_d, const Player& pl_r, const Player& pl_u, const Player& pl_l, const Tiles& d, const Actions& a);
+ RoundState() : Base(Types::RoundState) {}
+ RoundState(const Player& pl_d, const Player& pl_r, const Player& pl_u, const Player& pl_l, const Tiles& d, const Actions& a)
+ : Base(Types::RoundState), dora(d), possible_actions(a) {
+ players[0] = pl_d;
+ players[1] = pl_r;
+ players[2] = pl_u;
+ players[3] = pl_l;
+ }
Player players[4];
@@ -169,33 +162,39 @@ namespace Message {
Actions possible_actions;
template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
+ void serialize(Archive & ar, const unsigned int v) {
ar & players;
ar & dora;
ar & possible_actions;
}
};
- class RoundAction : public BoostBase<RoundAction> {
+ class RoundAction : public Base {
public:
typedef boost::shared_ptr<RoundAction> p;
- RoundAction();
+ RoundAction() : Base(Types::RoundAction) {}
Action action;
template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
+ void serialize(Archive & ar, const unsigned int v) {
ar & action;
}
};
- class RoundEnd : public NullBase {
+ class RoundEnd : public Base {
public:
typedef boost::shared_ptr<RoundEnd> p;
- RoundEnd();
+ RoundEnd() : Base(Types::RoundEnd) {}
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int v) {
+
+ }
};
+
typedef boost::shared_ptr<Base> p;
};