Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
types_nodes_map.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19#ifndef HEDGEHOG_CX_TYPES_NODES_MAP_H_
20#define HEDGEHOG_CX_TYPES_NODES_MAP_H_
21
22#ifdef HH_ENABLE_HH_CX
23
24#include <vector>
25#include <algorithm>
26#include "../behavior/abstract_node.h"
27
29namespace hh_cx {
30
32namespace tool {
33
35class TypesNodesMap {
36 private:
37 std::vector<std::string> types_{};
38 std::vector<std::vector<behavior::AbstractNode const *>> nodes_{};
39 std::vector<std::vector<std::string>> nodesName_{};
40
41 public:
43 constexpr TypesNodesMap() = default;
45 constexpr ~TypesNodesMap() = default;
46
49 [[nodiscard]] constexpr size_t nbTypes() const { return types_.size(); }
50
53 [[nodiscard]] constexpr std::vector<std::string> const &types() const { return types_; }
54
57 [[nodiscard]] constexpr std::vector<std::vector<behavior::AbstractNode const *>> const &nodes() const {
58 return nodes_;
59 }
60
63 [[nodiscard]] constexpr std::vector<std::vector<std::string>> const &nodesName() const { return nodesName_; }
64
68 [[nodiscard]] constexpr std::vector<behavior::AbstractNode const *> nodes(std::string const &type) const {
69 auto posIt = std::find(types_.cbegin(), types_.cend(), type);
70 if (posIt != types_.cend()) { return nodes_.at(static_cast<unsigned long>(std::distance(types_.cbegin(), posIt))); }
71 else { return {}; }
72 }
73
75 constexpr void clear() {
76 types_.clear();
77 for (auto &nodes : nodes_) { nodes.clear(); }
78 for (auto &nodesName : nodesName_) { nodesName.clear(); }
79 }
80
84 constexpr void insert(std::string const &type, hh_cx::behavior::AbstractNode const *node) {
85 auto posIt = std::find(types_.cbegin(), types_.cend(), type);
86 if (posIt != types_.cend()) {
87 nodes_.at(static_cast<unsigned long>(std::distance(types_.cbegin(), posIt))).push_back(node);
88 nodesName_.at(static_cast<unsigned long>(std::distance(types_.cbegin(), posIt))).push_back(node->name());
89 } else {
90 types_.push_back(type);
91 nodes_.push_back(std::vector<behavior::AbstractNode const *>{node});
92 nodesName_.push_back(std::vector<std::string>{node->name()});
93 }
94 }
95
99 [[nodiscard]] constexpr bool contains(std::string const &type) const {
100 return std::find(types_.cbegin(), types_.cend(), type) != types_.cend();
101 }
102
107 [[nodiscard]] constexpr bool contains(std::string const &type, hh_cx::behavior::AbstractNode const *node) const {
108 if (contains(type)) {
109 auto nodes = this->nodes(type);
110 if (std::find(nodes.cbegin(), nodes.cend(), node) == nodes.cend()) { return false; }
111 else { return true; }
112 } else { return false; }
113 }
114
117 [[nodiscard]] constexpr size_t maxTypeSize() const {
118 if(types_.empty()) { return 0; }
119 return std::max_element(
120 types_.cbegin(), types_.cend(),
121 [](auto const &lhs, auto const &rhs) { return lhs.size() < rhs.size(); }
122 )->size();
123 }
124
127 [[nodiscard]] constexpr size_t maxNumberNodes() const {
128 if(nodes_.empty()) {
129 return 0;
130 }
131 return std::max_element(
132 nodes_.cbegin(), nodes_.cend(),
133 [](auto const &lhs, auto const &rhs) { return lhs.size() < rhs.size(); }
134 )->size();
135 }
136
139 [[nodiscard]] constexpr size_t maxSizeName() const {
140 size_t ret = 0;
141 for (auto const &type : nodesName_) {
142 for (auto const &nodeName : type) {
143 if (nodeName.size() > ret) { ret = nodeName.size(); }
144 }
145 }
146 return ret;
147 }
148};
149}
150}
151
152#endif //HH_ENABLE_HH_CX
153#endif //HEDGEHOG_CX_TYPES_NODES_MAP_H_