Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
groupable_abstraction.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_ABSTRACTION_H
22#define HEDGEHOG_COPYABLE_ABSTRACTION_H
23
24#include <ostream>
25
28
30namespace hh {
32namespace core {
34namespace abstraction {
35
39template<tool::CopyableNode CopyableNode, class CopyableCore>
41 public CopyableAbstraction<CopyableNode>,
43 private:
44 int
47
48 public:
52 GroupableAbstraction(CopyableNode *const copyableNode, size_t const &numberThreads)
53 : CopyableAbstraction<CopyableNode>(copyableNode),
55
57 ~GroupableAbstraction() override = default;
58
61 [[nodiscard]] int threadId() const { return threadId_;}
62
63
67 std::shared_ptr<CopyableNode> callCopyAndRegisterInGroup() {
68 auto copy = this->callCopy();
69
70 auto copyableCore = dynamic_cast<AnyGroupableAbstraction *>(copy->core().get());
71
72 if (copyableCore == nullptr) {
73 std::ostringstream oss;
74 if (auto node = dynamic_cast<NodeAbstraction *>(this))
75 oss << "A copy for the node \"" << node->name()
76 << "\" has a core that does not have the right structure (missing inheritance to GroupableAbstraction).";
77 else {
78 oss << "A copy for the node has a core that does not have the right structure (missing inheritance to "
79 "GroupableAbstraction).";
80 }
81 throw (std::runtime_error(oss.str()));
82 }
83
84 copyableCore->groupRepresentative(this);
85 this->group()->insert(copyableCore);
86 copyableCore->group(this->group());
87
88 auto copyAsCopyable = dynamic_cast<GroupableAbstraction<CopyableNode, CopyableCore>*>(copyableCore);
89 if (copyAsCopyable != nullptr) {
90 copyAsCopyable->threadId_ = numberThreadsCreated_++;
91 }else {
92 std::ostringstream oss;
93 oss << "A copy for the node has a core that does not have the right structure (missing inheritance to GroupableAbstraction).";
94 throw (std::runtime_error(oss.str()));
95 }
96
97 return copy;
98 }
99
102 virtual void copyInnerStructure(CopyableCore *copyableCore) = 0;
103
104};
105}
106}
107}
108#endif //HEDGEHOG_COPYABLE_ABSTRACTION_H
Hedgehog main namespace.
Abstraction for cores/nodes that can form groups.
std::shared_ptr< std::set< AnyGroupableAbstraction * > > const & group() const
Group of cores accessor.
AnyGroupableAbstraction * groupRepresentative() const
Group representative accessor.
size_t numberThreads() const
Accessor to the number of threads.
Core abstraction for copyable nodes.
std::shared_ptr< CopyableNode > callCopy()
Interface to call user-defined copy method.
Typed abstraction for groupable node.
GroupableAbstraction(CopyableNode *const copyableNode, size_t const &numberThreads)
Constructor using the node abstraction to call the user-defined copy and the number of threads.
~GroupableAbstraction() override=default
Default destructor.
std::shared_ptr< CopyableNode > callCopyAndRegisterInGroup()
Call the used-defined copy and register the copy in the group.
int threadId() const
Accessor to thread id.
virtual void copyInnerStructure(CopyableCore *copyableCore)=0
Copy the inner structure of the core.
int numberThreadsCreated_
Number of thread created for the group.