LCOV - code coverage report
Current view: top level - shared_model/backend/protobuf/commands/impl - proto_command.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 10 13 76.9 %
Date: 2018-12-05 17:11:35 Functions: 13 21 61.9 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "backend/protobuf/commands/proto_command.hpp"
       7             : 
       8             : #include "backend/protobuf/commands/proto_add_asset_quantity.hpp"
       9             : #include "backend/protobuf/commands/proto_add_peer.hpp"
      10             : #include "backend/protobuf/commands/proto_add_signatory.hpp"
      11             : #include "backend/protobuf/commands/proto_append_role.hpp"
      12             : #include "backend/protobuf/commands/proto_create_account.hpp"
      13             : #include "backend/protobuf/commands/proto_create_asset.hpp"
      14             : #include "backend/protobuf/commands/proto_create_domain.hpp"
      15             : #include "backend/protobuf/commands/proto_create_role.hpp"
      16             : #include "backend/protobuf/commands/proto_detach_role.hpp"
      17             : #include "backend/protobuf/commands/proto_grant_permission.hpp"
      18             : #include "backend/protobuf/commands/proto_remove_signatory.hpp"
      19             : #include "backend/protobuf/commands/proto_revoke_permission.hpp"
      20             : #include "backend/protobuf/commands/proto_set_account_detail.hpp"
      21             : #include "backend/protobuf/commands/proto_set_quorum.hpp"
      22             : #include "backend/protobuf/commands/proto_subtract_asset_quantity.hpp"
      23             : #include "backend/protobuf/commands/proto_transfer_asset.hpp"
      24             : #include "utils/reference_holder.hpp"
      25             : #include "utils/variant_deserializer.hpp"
      26             : 
      27             : namespace {
      28             :   /// type of proto variant
      29             :   using ProtoCommandVariantType =
      30             :       ::boost::variant<shared_model::proto::AddAssetQuantity,
      31             :                        shared_model::proto::AddPeer,
      32             :                        shared_model::proto::AddSignatory,
      33             :                        shared_model::proto::AppendRole,
      34             :                        shared_model::proto::CreateAccount,
      35             :                        shared_model::proto::CreateAsset,
      36             :                        shared_model::proto::CreateDomain,
      37             :                        shared_model::proto::CreateRole,
      38             :                        shared_model::proto::DetachRole,
      39             :                        shared_model::proto::GrantPermission,
      40             :                        shared_model::proto::RemoveSignatory,
      41             :                        shared_model::proto::RevokePermission,
      42             :                        shared_model::proto::SetAccountDetail,
      43             :                        shared_model::proto::SetQuorum,
      44             :                        shared_model::proto::SubtractAssetQuantity,
      45             :                        shared_model::proto::TransferAsset>;
      46             : 
      47             :   /// list of types in proto variant
      48             :   using ProtoCommandListType = ProtoCommandVariantType::types;
      49             : }  // namespace
      50             : 
      51             : namespace shared_model {
      52             :   namespace proto {
      53             : 
      54             :     struct Command::Impl {
      55             :       explicit Impl(TransportType &&ref) : proto_(std::move(ref)) {}
      56             :       explicit Impl(const TransportType &ref) : proto_(ref) {}
      57             : 
      58             :       detail::ReferenceHolder<TransportType> proto_;
      59             : 
      60             :       ProtoCommandVariantType variant_{[this] {
      61       53910 :         auto &&ar = *proto_;
      62       53910 :         int which =
      63       53910 :             ar.GetDescriptor()->FindFieldByNumber(ar.command_case())->index();
      64       53910 :         return shared_model::detail::variant_impl<ProtoCommandListType>::
      65             :             template load<ProtoCommandVariantType>(
      66       53910 :                 std::forward<decltype(ar)>(ar), which);
      67             :       }()};
      68             : 
      69       53898 :       CommandVariantType ivariant_{
      70             :           [this] { return CommandVariantType(variant_); }()};
      71             :     };
      72             : 
      73             :     Command::Command(const Command &o) : Command(*o.impl_->proto_) {}
      74             :     Command::Command(Command &&o) noexcept = default;
      75             : 
      76             :     Command::Command(const TransportType &ref) {
      77       53911 :       impl_ = std::make_unique<Impl>(ref);
      78       53911 :     }
      79             :     Command::Command(TransportType &&ref) {
      80           0 :       impl_ = std::make_unique<Impl>(std::move(ref));
      81           0 :     }
      82             : 
      83             :     Command::~Command() = default;
      84             : 
      85             :     const Command::CommandVariantType &Command::get() const {
      86       26730 :       return impl_->ivariant_;
      87             :     }
      88             : 
      89             :     Command *Command::clone() const {
      90         843 :       return new Command(*impl_->proto_);
      91           0 :     }
      92             : 
      93             :   }  // namespace proto
      94             : }  // namespace shared_model

Generated by: LCOV version 1.13