Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
copyable.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
20
21#ifndef HEDGEHOG_COPYABLE_H
22#define HEDGEHOG_COPYABLE_H
23
24#include <memory>
25#include "node.h"
26#include "../core/abstractions/base/any_groupable_abstraction.h"
27
29namespace hh {
31namespace behavior {
32
36template<class NodeType>
37class Copyable {
38 private:
39 size_t const numberThreads_ = 0;
40 public:
41
45
47 virtual ~Copyable() = default;
48
51 [[nodiscard]] size_t numberThreads() const { return numberThreads_; }
52
55 std::vector<NodeType const *> group() const {
56 std::vector<NodeType const *> ret;
57 std::shared_ptr<hh::core::abstraction::NodeAbstraction> core = dynamic_cast<Node const *>(this)->core();
58 if (core) {
59 auto groupableNode = std::dynamic_pointer_cast<core::abstraction::AnyGroupableAbstraction>(core);
60 if (groupableNode) {
61 auto group = groupableNode->groupAsNodes();
62 for (auto &coresInGroup : *group) {
63 if (coresInGroup){ ret.push_back(dynamic_cast<NodeType *>(coresInGroup->node())); }
64 else { return {}; }
65 }
66 } else { // if (groupable)
67 std::ostringstream oss;
68 oss << "The core attached to the node " << this << " does not derives from hh::core::abstraction::AnyGroupableAbstraction.";
69 throw(std::runtime_error(oss.str()));
70 }
71 return ret;
72 } else { // if (core)
73 std::ostringstream oss;
74 oss << "The core attached to the node " << this << " is ill-formed.";
75 throw std::runtime_error(oss.str());
76 }
77 }
78
82 virtual std::shared_ptr<NodeType> copy() { return nullptr; }
83};
84}
85}
86#endif //HEDGEHOG_COPYABLE_H
Hedgehog main namespace.
Copy interface used to copy a node when either a group of nodes is created or a node is duplicated wh...
Definition: copyable.h:37
virtual ~Copyable()=default
Default destructor.
size_t numberThreads() const
Number of threads accessor.
Definition: copyable.h:51
size_t const numberThreads_
Number of threads.
Definition: copyable.h:39
std::vector< NodeType const * > group() const
Get the group of nodes that hold the current nodes.
Definition: copyable.h:55
virtual std::shared_ptr< NodeType > copy()
Copy method called to either create a group of node or duplicate a node when an execution pipeline is...
Definition: copyable.h:82
Copyable(size_t const numberThreads)
Copyable constructor, set the number of threads for a node.
Definition: copyable.h:44
Behavior abstraction for the base node.
Definition: node.h:32