Eile Mit Weile
Loading...
Searching...
No Matches
ClientRequest Class Reference

Base class for all requests that are being sent from the client to the server. More...

#include <ClientRequest.hpp>

Inheritance diagram for ClientRequest:
Serializable join_game_request move_figure_request skip_turn_request start_game_request throw_dice_request

Classes

struct  BaseClassProperties
 Holds the properties that are common to all ClientRequest subclasses. More...
 

Public Member Functions

RequestType GetType () const
 
std::string GetReqId () const
 
std::string GetGameId () const
 
std::string GetPlayerId () const
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
 
- Public Member Functions inherited from Serializable
virtual rapidjson::DocumentToJson () const
 

Static Public Attributes

static const std::unordered_map< std::string, RequestType_string_to_request_type
 
static const std::unordered_map< RequestType, std::string > _request_type_to_string
 

Protected Member Functions

 ClientRequest (const BaseClassProperties &)
 

Static Protected Member Functions

static BaseClassProperties CreateBaseClassProperties (RequestType type, std::string req_id, std::string &player_id, std::string &game_id)
 
static BaseClassProperties ExtractBaseClassProperties (const rapidjson::Value &json)
 

Protected Attributes

RequestType _type
 
std::string _req_id
 
std::string _player_id
 
std::string _game_id
 

Detailed Description

Base class for all requests that are being sent from the client to the server.

It offers a function to deserialize a ClientRequest subclass from a valid json. This class uses the RequestType enum to specify the type of the request.

Constructor & Destructor Documentation

◆ ClientRequest()

ClientRequest::ClientRequest ( const BaseClassProperties props)
explicitprotected

Base constructor. Used by subclasses to initialize the BaseClassProperties.

Member Function Documentation

◆ CreateBaseClassProperties()

ClientRequest::BaseClassProperties ClientRequest::CreateBaseClassProperties ( RequestType  type,
std::string  req_id,
std::string &  player_id,
std::string &  game_id 
)
staticprotected

Creates a BaseClassProperties object from the provided parameters.

◆ ExtractBaseClassProperties()

ClientRequest::BaseClassProperties ClientRequest::ExtractBaseClassProperties ( const rapidjson::Value json)
staticprotected

Extracts the BaseClassProperties from the provided json object.

◆ GetGameId()

std::string ClientRequest::GetGameId ( ) const

Returns the unique id of the game that the request is related to.

◆ GetPlayerId()

std::string ClientRequest::GetPlayerId ( ) const

Returns the id of the player that sent the request.

◆ GetReqId()

std::string ClientRequest::GetReqId ( ) const

Returns the unique id of the request.

◆ GetType()

RequestType ClientRequest::GetType ( ) const

Returns the type of the request.

◆ WriteIntoJson()

void ClientRequest::WriteIntoJson ( rapidjson::Value json,
rapidjson::Document::AllocatorType &  allocator 
) const
overridevirtual

Writes the ClientRequest into a json object (serialization). Note that a corresponding FromJson function is defined by the children of this base class.

Implements Serializable.

Reimplemented in join_game_request, move_figure_request, skip_turn_request, start_game_request, and throw_dice_request.

Member Data Documentation

◆ _game_id

std::string ClientRequest::_game_id
protected

The unique id of the game that the request is related to

◆ _player_id

std::string ClientRequest::_player_id
protected

The id of the player that sent the request

◆ _req_id

std::string ClientRequest::_req_id
protected

The unique id of the request

◆ _request_type_to_string

const std::unordered_map< RequestType, std::string > ClientRequest::_request_type_to_string
static
Initial value:
= {
{ RequestType::join_game, "join_game" },
{ RequestType::start_game, "start_game"},
{ RequestType::move_figure, "move_figure"},
{ RequestType::skip_turn, "skip_turn"},
{ RequestType::throw_dice, "throw_dice"},
}

Maps the RequestType enum to the string representation of the RequestType. For serialization.

◆ _string_to_request_type

const std::unordered_map< std::string, RequestType > ClientRequest::_string_to_request_type
static
Initial value:
= {
{"join_game", RequestType::join_game },
{"start_game", RequestType::start_game},
{"move_figure", RequestType::move_figure},
{"skip_turn", RequestType::skip_turn},
{"throw_dice", RequestType::throw_dice},
}

Maps the string representation of the RequestType to the RequestType enum. For deserialization.

◆ _type

RequestType ClientRequest::_type
protected

The type of the request


The documentation for this class was generated from the following files: