SOLA
Loading...
Searching...
No Matches
consensus_base.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_PATH_PLANNING_CONSENSUS_CONSENSUS_BASE_H_
18#define DAISI_PATH_PLANNING_CONSENSUS_CONSENSUS_BASE_H_
19
20#include <functional>
21#include <memory>
22
23#include "path_planning/constants.h"
24#include "sola-ns3/sola_ns3_wrapper.h"
25
26namespace daisi::path_planning::consensus {
27
29template <typename T, typename DataContainer> class ConsensusBase {
30public:
31 explicit ConsensusBase(std::shared_ptr<DataContainer> container)
32 : container_(std::move(container)) {}
33
34 ~ConsensusBase() = default;
35 void findConsensus(const PointTimePairs &points, double seconds_earliest_start,
36 std::function<void(uint32_t id, double start_time)> success_cb,
37 std::function<void(uint32_t id)> fail_cb) {
38 static_cast<T *>(this)->findConsensusImpl(points, seconds_earliest_start, success_cb, fail_cb);
39 }
40
41 void recvTopicMessage(const std::string &topic, const std::string &msg) {
42 return static_cast<T *>(this)->recvTopicMessageImpl(topic, msg);
43 }
44
45protected:
46 std::shared_ptr<DataContainer> container_;
48};
49} // namespace daisi::path_planning::consensus
50
51#endif // DAISI_PATH_PLANNING_CONSENSUS_CONSENSUS_BASE_H_
CRTP base class for a consensus algorithm.
Definition consensus_base.h:29
std::shared_ptr< DataContainer > container_
Definition consensus_base.h:46