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 
30 
32 {
33 
34  /**
35  * @brief Something that supports a set of prediction engines.
36  */
37  template <class DerivedT>
38  class Predictive
39  {
40  public:
41 
42  explicit Predictive(const std::vector<PredictionEngine>& engines = {}) :
43  _predictionEngines(engines)
44  {
45  }
46 
47  const std::vector<PredictionEngine>&
49  {
50  return _predictionEngines;
51  }
52 
54  {
55  _predictionEngines.push_back(engine);
56  }
57 
58  void 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 
82  std::vector<PredictionEngine> _predictionEngines;
83 
84  };
85 
86 
87  /**
88  * @brief Something that supports a set of prediction engines.
89  */
90  template <class DerivedT>
91  class PredictiveContainer : public Predictive<DerivedT>
92  {
93  public:
94 
96 
97 
98  std::map<MemoryID, std::vector<PredictionEngine>>
100  {
101  std::map<MemoryID, std::vector<PredictionEngine>> engines;
102 
103  // Collect engines of children.
104  const auto& derivedThis = derived<DerivedT>(this);
105  derivedThis.forEachChild(
106  [&engines](const auto& child)
107  {
108  const auto& childMap = child.getAllPredictionEngines();
109  engines.insert(childMap.begin(), childMap.end());
110  });
111 
112  // Add own engines.
113  const auto& ownEngines = derivedThis.predictionEngines();
114  if (not ownEngines.empty())
115  {
116  engines.emplace(derivedThis.id(), derivedThis.predictionEngines());
117  }
118 
119  return engines;
120  }
121 
122  };
123 
124 
125 } // namespace armarx::armem::base::detail
MemoryID.h
Prediction.h
armarx::armem::base::detail
Definition: AronTyped.cpp:6
armarx::armem::base::detail::PredictiveContainer
Something that supports a set of prediction engines.
Definition: Predictive.h:91
armarx::armem::base::detail::Predictive::setPredictionEngines
void setPredictionEngines(const std::vector< PredictionEngine > &engines)
Definition: Predictive.h:58
armarx::armem::base::detail::Predictive::Predictive
Predictive(const std::vector< PredictionEngine > &engines={})
Definition: Predictive.h:42
armarx::armem::base::detail::PredictiveContainer::getAllPredictionEngines
std::map< MemoryID, std::vector< PredictionEngine > > getAllPredictionEngines() const
Definition: Predictive.h:99
armarx::armem::PredictionEngine
Definition: Prediction.h:33
derived.h
armarx::armem::base::detail::Predictive::getAllPredictionEngines
std::map< MemoryID, std::vector< PredictionEngine > > getAllPredictionEngines() const
Definition: Predictive.h:64
armarx::armem::base::detail::Predictive::addPredictionEngine
void addPredictionEngine(const PredictionEngine &engine)
Definition: Predictive.h:53
armarx::armem::base::detail::Predictive::predictionEngines
const std::vector< PredictionEngine > & predictionEngines() const
Definition: Predictive.h:48
armarx::armem::base::detail::Predictive
Something that supports a set of prediction engines.
Definition: Predictive.h:38