From 7ae3138863480eba443870bc94da65bab85b36c4 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 13:02:05 +0300 Subject: [PATCH] #235 match_object : delete custom variant and Stream operator functions --- .../include/graphene/chain/match_object.hpp | 85 +------------------ .../include/graphene/chain/protocol/types.hpp | 1 + libraries/chain/match_object.cpp | 55 ------------ libraries/chain/small_objects.cpp | 2 + 4 files changed, 7 insertions(+), 136 deletions(-) diff --git a/libraries/chain/include/graphene/chain/match_object.hpp b/libraries/chain/include/graphene/chain/match_object.hpp index 381c5dca..2f5152cc 100644 --- a/libraries/chain/include/graphene/chain/match_object.hpp +++ b/libraries/chain/include/graphene/chain/match_object.hpp @@ -1,20 +1,6 @@ #pragma once -#include -#include -#include -#include +#include #include -#include -#include - -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 - friend Stream& operator<<( Stream& s, const match_object& match_obj ); - - template - 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_index; - template - 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 >(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 - inline Stream& operator>>( Stream& s, match_object& match_obj ) - { - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(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)) \ No newline at end of file + (end_time)) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::match_object ) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 321b08d9..701a4888 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -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 ) diff --git a/libraries/chain/match_object.cpp b/libraries/chain/match_object.cpp index e11f0e8a..c0b75755 100644 --- a/libraries/chain/match_object.cpp +++ b/libraries/chain/match_object.cpp @@ -28,8 +28,6 @@ #include #include -#include -#include #include #include @@ -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( max_depth ); - match_obj.tournament_id = v["tournament_id"].as( max_depth ); - match_obj.players = v["players"].as >( max_depth ); - match_obj.games = v["games"].as >( max_depth ); - match_obj.game_winners = v["game_winners"].as > >( max_depth ); - match_obj.number_of_wins = v["number_of_wins"].as >( max_depth ); - match_obj.number_of_ties = v["number_of_ties"].as( max_depth ); - match_obj.match_winners = v["match_winners"].as >( max_depth ); - match_obj.start_time = v["start_time"].as( max_depth ); - match_obj.end_time = v["end_time"].as >( max_depth ); - graphene::chain::match_state state = v["state"].as( max_depth ); - const_cast(match_obj.my->state_machine.current_state())[0] = (int)state; - } FC_RETHROW_EXCEPTIONS(warn, "") } -} //end namespace fc - diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index a08ff691..9c54fba3 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -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 )