LCOV - code coverage report
Current view: top level - irohad/consensus/yac/impl - cluster_order.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 15 15 100.0 %
Date: 2018-12-05 17:11:35 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
       3             :  * http://soramitsu.co.jp
       4             :  *
       5             :  * Licensed under the Apache License, Version 2.0 (the "License");
       6             :  * you may not use this file except in compliance with the License.
       7             :  * You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  * Unless required by applicable law or agreed to in writing, software
      12             :  * distributed under the License is distributed on an "AS IS" BASIS,
      13             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  * See the License for the specific language governing permissions and
      15             :  * limitations under the License.
      16             :  */
      17             : 
      18             : #include "consensus/yac/cluster_order.hpp"
      19             : 
      20             : namespace iroha {
      21             :   namespace consensus {
      22             :     namespace yac {
      23             : 
      24             :       boost::optional<ClusterOrdering> ClusterOrdering::create(
      25             :           const std::vector<std::shared_ptr<shared_model::interface::Peer>>
      26             :               &order) {
      27        1711 :         if (order.empty()) {
      28           1 :           return boost::none;
      29             :         }
      30        1710 :         return ClusterOrdering(order);
      31        1711 :       }
      32             : 
      33             :       ClusterOrdering::ClusterOrdering(
      34             :           std::vector<std::shared_ptr<shared_model::interface::Peer>> order)
      35        1710 :           : order_(std::move(order)) {}
      36             : 
      37             :     // TODO :  24/03/2018 x3medima17: make it const, IR-1164
      38             :     const shared_model::interface::Peer& ClusterOrdering::currentLeader() {
      39         738 :         if (index_ >= order_.size()) {
      40           1 :           index_ = 0;
      41           1 :         }
      42         738 :         return *order_.at(index_);
      43             :       }
      44             : 
      45             :       bool ClusterOrdering::hasNext() const {
      46         735 :         return index_ != order_.size();
      47             :       }
      48             : 
      49             :       ClusterOrdering &ClusterOrdering::switchToNext() {
      50         737 :         ++index_;
      51         737 :         return *this;
      52             :       }
      53             : 
      54             :       std::vector<std::shared_ptr<shared_model::interface::Peer>>
      55             :       ClusterOrdering::getPeers() const {
      56        2161 :         return order_;
      57             :       }
      58             : 
      59             :       size_t ClusterOrdering::getNumberOfPeers() const {
      60        1465 :         return order_.size();
      61             :       }
      62             :     }  // namespace yac
      63             :   }    // namespace consensus
      64             : }  // namespace iroha

Generated by: LCOV version 1.13