#235 match_object : delete custom variant and Stream operator functions

This commit is contained in:
Vlad Dobromyslov 2022-02-16 13:02:05 +03:00
parent 4267e6323a
commit 7ae3138863
4 changed files with 7 additions and 136 deletions

View file

@ -1,20 +1,6 @@
#pragma once
#include <graphene/chain/protocol/tournament.hpp>
#include <graphene/chain/rock_paper_scissors.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <graphene/db/flat_index.hpp>
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>
#include <fc/crypto/hex.hpp>
#include <sstream>
namespace graphene { namespace chain {
class match_object;
} }
namespace fc {
void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth = 1);
void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth = 1);
} //end namespace fc
namespace graphene { namespace chain {
class database;
@ -75,20 +61,6 @@ namespace graphene { namespace chain {
match_state get_state() const;
// serialization functions:
// for serializing to raw, go through a temporary sstream object to avoid
// having to implement serialization in the header file
template<typename Stream>
friend Stream& operator<<( Stream& s, const match_object& match_obj );
template<typename Stream>
friend Stream& operator>>( Stream& s, match_object& match_obj );
friend void ::fc::to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth);
friend void ::fc::from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth);
void pack_impl(std::ostream& stream) const;
void unpack_impl(std::istream& stream);
void on_initiate_match(database& db);
void on_game_complete(database& db, const game_object& game);
game_id_type start_next_game(database& db, match_id_type match_id);
@ -104,57 +76,6 @@ namespace graphene { namespace chain {
> match_object_multi_index_type;
typedef generic_index<match_object, match_object_multi_index_type> match_index;
template<typename Stream>
inline Stream& operator<<( Stream& s, const match_object& match_obj )
{
// pack all fields exposed in the header in the usual way
// instead of calling the derived pack, just serialize the one field in the base class
// fc::raw::pack<Stream, const graphene::db::abstract_object<match_object> >(s, match_obj);
fc::raw::pack(s, match_obj.id);
fc::raw::pack(s, match_obj.tournament_id);
fc::raw::pack(s, match_obj.players);
fc::raw::pack(s, match_obj.games);
fc::raw::pack(s, match_obj.game_winners);
fc::raw::pack(s, match_obj.number_of_wins);
fc::raw::pack(s, match_obj.number_of_ties);
fc::raw::pack(s, match_obj.match_winners);
fc::raw::pack(s, match_obj.start_time);
fc::raw::pack(s, match_obj.end_time);
// fc::raw::pack the contents hidden in the impl class
std::ostringstream stream;
match_obj.pack_impl(stream);
std::string stringified_stream(stream.str());
fc::raw::pack(s, stream.str());
return s;
}
template<typename Stream>
inline Stream& operator>>( Stream& s, match_object& match_obj )
{
// unpack all fields exposed in the header in the usual way
//fc::raw::unpack<Stream, graphene::db::abstract_object<match_object> >(s, match_obj);
fc::raw::unpack(s, match_obj.id);
fc::raw::unpack(s, match_obj.tournament_id);
fc::raw::unpack(s, match_obj.players);
fc::raw::unpack(s, match_obj.games);
fc::raw::unpack(s, match_obj.game_winners);
fc::raw::unpack(s, match_obj.number_of_wins);
fc::raw::unpack(s, match_obj.number_of_ties);
fc::raw::unpack(s, match_obj.match_winners);
fc::raw::unpack(s, match_obj.start_time);
fc::raw::unpack(s, match_obj.end_time);
// fc::raw::unpack the contents hidden in the impl class
std::string stringified_stream;
fc::raw::unpack(s, stringified_stream);
std::istringstream stream(stringified_stream);
match_obj.unpack_impl(stream);
return s;
}
} }
FC_REFLECT_ENUM(graphene::chain::match_state,
@ -172,4 +93,6 @@ FC_REFLECT_DERIVED(graphene::chain::match_object, (graphene::db::object),
(number_of_ties)
(match_winners)
(start_time)
(end_time))
(end_time))
GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::match_object )

View file

@ -577,6 +577,7 @@ FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type )
FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type )
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
FC_REFLECT_TYPENAME( graphene::chain::match_id_type )
FC_REFLECT_TYPENAME( graphene::chain::custom_permission_id_type )
FC_REFLECT_TYPENAME( graphene::chain::custom_account_authority_id_type )
FC_REFLECT_TYPENAME( graphene::chain::offer_history_id_type )

View file

@ -28,8 +28,6 @@
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/msm/back/tools.hpp>
#include <boost/range/algorithm/copy.hpp>
@ -327,18 +325,6 @@ namespace graphene { namespace chain {
return state;
}
void match_object::pack_impl(std::ostream& stream) const
{
boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking);
oa << my->state_machine;
}
void match_object::unpack_impl(std::istream& stream)
{
boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking);
ia >> my->state_machine;
}
void match_object::on_initiate_match(database& db)
{
my->state_machine.process_event(initiate_match(db));
@ -362,45 +348,4 @@ namespace graphene { namespace chain {
} } // graphene::chain
namespace fc {
// Manually reflect match_object to variant to properly reflect "state"
void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth)
{ try {
fc_elog(fc::logger::get("tournament"), "In match_obj to_variant");
elog("In match_obj to_variant");
fc::mutable_variant_object o;
o("id", fc::variant(match_obj.id, max_depth))
("tournament_id", fc::variant(match_obj.tournament_id, max_depth))
("players", fc::variant(match_obj.players, max_depth))
("games", fc::variant(match_obj.games, max_depth))
("game_winners", fc::variant(match_obj.game_winners, max_depth))
("number_of_wins", fc::variant(match_obj.number_of_wins, max_depth))
("number_of_ties", fc::variant(match_obj.number_of_ties, max_depth))
("match_winners", fc::variant(match_obj.match_winners, max_depth))
("start_time", fc::variant(match_obj.start_time, max_depth))
("end_time", fc::variant(match_obj.end_time, max_depth))
("state", fc::variant(match_obj.get_state(), max_depth));
v = o;
} FC_RETHROW_EXCEPTIONS(warn, "") }
// Manually reflect match_object to variant to properly reflect "state"
void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth)
{ try {
fc_elog(fc::logger::get("tournament"), "In match_obj from_variant");
match_obj.id = v["id"].as<graphene::chain::match_id_type>( max_depth );
match_obj.tournament_id = v["tournament_id"].as<graphene::chain::tournament_id_type>( max_depth );
match_obj.players = v["players"].as<std::vector<graphene::chain::account_id_type> >( max_depth );
match_obj.games = v["games"].as<std::vector<graphene::chain::game_id_type> >( max_depth );
match_obj.game_winners = v["game_winners"].as<std::vector<flat_set<graphene::chain::account_id_type> > >( max_depth );
match_obj.number_of_wins = v["number_of_wins"].as<std::vector<uint32_t> >( max_depth );
match_obj.number_of_ties = v["number_of_ties"].as<uint32_t>( max_depth );
match_obj.match_winners = v["match_winners"].as<flat_set<graphene::chain::account_id_type> >( max_depth );
match_obj.start_time = v["start_time"].as<time_point_sec>( max_depth );
match_obj.end_time = v["end_time"].as<optional<time_point_sec> >( max_depth );
graphene::chain::match_state state = v["state"].as<graphene::chain::match_state>( max_depth );
const_cast<int*>(match_obj.my->state_machine.current_state())[0] = (int)state;
} FC_RETHROW_EXCEPTIONS(warn, "") }
} //end namespace fc

View file

@ -44,6 +44,7 @@
#include <graphene/chain/witness_scheduler.hpp>
#include <graphene/chain/worker_object.hpp>
#include <graphene/chain/tournament_object.hpp>
#include <graphene/chain/match_object.hpp>
#include <fc/io/raw.hpp>
@ -74,3 +75,4 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedu
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedule_object )
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object )
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object )
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object )