LCOV - code coverage report
Current view: top level - shared_model/backend/protobuf/common_objects - trivial_proto.hpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 4 7 57.1 %
Date: 2019-03-07 14:46:43 Functions: 274 640 42.8 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #ifndef IROHA_SHARED_MODEL_TRIVIAL_PROTO_HPP
       7             : #define IROHA_SHARED_MODEL_TRIVIAL_PROTO_HPP
       8             : 
       9             : #include "utils/reference_holder.hpp"
      10             : 
      11             : namespace shared_model {
      12             :   namespace proto {
      13             :     /**
      14             :      * Simple generic class for handling proto objects
      15             :      * @tparam Iface is interface to inherit from
      16             :      * @tparam Proto is protobuf container
      17             :      */
      18             :     template <typename Iface, typename Proto>
      19             :     class TrivialProto final : public Iface {
      20             :      public:
      21             :       /**
      22             :        * @tparm ProtoLoader generic param so it can be handled
      23             :        *                    in the load for the boost::variant
      24             :        */
      25             :       template <typename ProtoLoader>
      26             :       explicit TrivialProto(ProtoLoader &&ref)
      27        1913 :           : proto_(std::forward<ProtoLoader>(ref)) {}
      28             : 
      29             :      protected:
      30             :       typename Iface::ModelType *clone() const override {
      31           0 :         return new TrivialProto(Proto(*proto_));
      32           0 :       }
      33             : 
      34             :      private:
      35             :       detail::ReferenceHolder<Proto> proto_;
      36             :     };
      37             : 
      38             :     /**
      39             :      * Simple generic class for handling proto objects
      40             :      * @tparam Iface is interface to inherit from
      41             :      * @tparam Proto is protobuf container
      42             :      * @tparam Impl is implementation of Iface
      43             :      */
      44             :     template <typename Iface, typename Proto, typename Impl>
      45             :     class CopyableProto : public Iface {
      46             :      public:
      47             :       /**
      48             :        * @tparm ProtoLoader generic param so it can be handled
      49             :        *                    in the load for the boost::variant
      50             :        */
      51             :       template <typename ProtoLoader>
      52             :       explicit CopyableProto(ProtoLoader &&ref)
      53      112438 :           : proto_(std::forward<ProtoLoader>(ref)) {}
      54             : 
      55             :       using TransportType = Proto;
      56             : 
      57             :       const Proto &getTransport() const {
      58           4 :         return *proto_;
      59             :       }
      60             : 
      61             :      protected:
      62             :       typename Iface::ModelType *clone() const override final {
      63         721 :         return new Impl(Proto(*proto_));
      64           0 :       }
      65             :       detail::ReferenceHolder<Proto> proto_;
      66             :     };
      67             :   }  // namespace proto
      68             : }  // namespace shared_model
      69             : 
      70             : #endif  // IROHA_SHARED_MODEL_TRIVIAL_PROTO_HPP

Generated by: LCOV version 1.13