Predictive.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::armem::core::base::detail
17 * @author phesch ( phesch at student dot kit dot edu )
18 * @date 2022
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
27
28#include "derived.h"
29
31{
32
33 /**
34 * @brief Something that supports a set of prediction engines.
35 */
36 template <class DerivedT>
38 {
39 public:
40 explicit Predictive(const std::vector<PredictionEngine>& engines = {}) :
41 _predictionEngines(engines)
42 {
43 }
44
45 const std::vector<PredictionEngine>&
47 {
48 return _predictionEngines;
49 }
50
51 void
53 {
54 _predictionEngines.push_back(engine);
55 }
56
57 void
58 setPredictionEngines(const std::vector<PredictionEngine>& engines)
59 {
60 this->_predictionEngines = engines;
61 }
62
63 std::map<MemoryID, std::vector<PredictionEngine>>
65 {
66 std::map<MemoryID, std::vector<PredictionEngine>> engines;
67
68 // Add own engines.
69 const auto& derivedThis = derived<DerivedT>(this);
70 const auto& ownEngines = derivedThis.predictionEngines();
71 if (not ownEngines.empty())
72 {
73 engines.emplace(derivedThis.id(), derivedThis.predictionEngines());
74 }
75
76 return engines;
77 }
78
79
80 private:
81 std::vector<PredictionEngine> _predictionEngines;
82 };
83
84 /**
85 * @brief Something that supports a set of prediction engines.
86 */
87 template <class DerivedT>
88 class PredictiveContainer : public Predictive<DerivedT>
89 {
90 public:
91 using Predictive<DerivedT>::Predictive;
92
93 std::map<MemoryID, std::vector<PredictionEngine>>
95 {
96 std::map<MemoryID, std::vector<PredictionEngine>> engines;
97
98 // Collect engines of children.
99 const auto& derivedThis = derived<DerivedT>(this);
100 derivedThis.forEachChild(
101 [&engines](const auto& child)
102 {
103 const auto& childMap = child.getAllPredictionEngines();
104 engines.insert(childMap.begin(), childMap.end());
105 });
106
107 // Add own engines.
108 const auto& ownEngines = derivedThis.predictionEngines();
109 if (not ownEngines.empty())
110 {
111 engines.emplace(derivedThis.id(), derivedThis.predictionEngines());
112 }
113
114 return engines;
115 }
116 };
117
118
119} // namespace armarx::armem::base::detail
Something that supports a set of prediction engines.
Definition Predictive.h:89
std::map< MemoryID, std::vector< PredictionEngine > > getAllPredictionEngines() const
Definition Predictive.h:94
Predictive(const std::vector< PredictionEngine > &engines={})
Definition Predictive.h:40
const std::vector< PredictionEngine > & predictionEngines() const
Definition Predictive.h:46
std::map< MemoryID, std::vector< PredictionEngine > > getAllPredictionEngines() const
Definition Predictive.h:64
void addPredictionEngine(const PredictionEngine &engine)
Definition Predictive.h:52
void setPredictionEngines(const std::vector< PredictionEngine > &engines)
Definition Predictive.h:58
DerivedT & derived(ThisT *t)
Definition derived.h:8