24 #ifndef __TPIE_PIPELINING_FACTORY_BASE_H__
25 #define __TPIE_PIPELINING_FACTORY_BASE_H__
26 #include <tpie/pipelining/node_set.h>
27 #include <tpie/pipelining/node.h>
32 namespace pipelining {
36 virtual void init_node(
node & r) = 0;
75 factory_base() : m_amount(0), m_set(
false), m_destinationKind(destination_kind::none) {
112 m_hooks.push_back(hook);
119 for (
size_t i = 0; i < m_hooks.size(); ++i) {
120 other.m_hooks.push_back(m_hooks[i]);
135 if (!m_name.empty()) {
138 if (!m_phaseName.empty()) {
141 if (!m_breadcrumbs.empty()) {
158 if (m_breadcrumbs.empty()) {
159 if (m_name.empty()) {
165 if (m_name.empty()) {
188 switch (m_destinationKind) {
189 case destination_kind::none:
191 case destination_kind::push:
194 case destination_kind::pull:
200 void add_node_set_edges(
node & r)
const {
202 for (
size_t i=0; i < m_add_to_set.size(); ++i) {
203 bits::node_map::ptr m2=m_add_to_set[i]->m_map;
207 for (
size_t i=0; i < m_add_relations.size(); ++i) {
208 bits::node_map::ptr m2=m_add_relations[i].first->m_map;
212 m = m->find_authority();
213 for (
size_t i=0; i < m_add_to_set.size(); ++i)
214 m_add_to_set[i]->m_map = m;
215 for (
size_t i=0; i < m_add_relations.size(); ++i)
216 m_add_relations[i].first->m_map = m;
218 for (
size_t i=0; i < m_add_to_set.size(); ++i) {
219 node_set s=m_add_to_set[i];
220 for (
size_t j=0; j < s->m_relations.size(); ++j)
221 m->add_relation(s->m_relations[j].first, r.
get_id(), s->m_relations[j].second);
222 s->m_nodes.push_back(r.
get_id());
225 for (
size_t i=0; i < m_add_relations.size(); ++i) {
226 node_set s=m_add_relations[i].first;
227 bits::node_relation relation = m_add_relations[i].second;
228 for (
size_t j=0; j < s->m_nodes.size(); ++j)
229 m->add_relation(r.
get_id(), s->m_nodes[j], relation);
230 s->m_relations.push_back(std::make_pair(r.
get_id(), relation));
241 inline void name(
const std::string & n, priority_type p) {
252 inline void phase_name(
const std::string & n, priority_type p) {
254 m_phaseNamePriority = p;
265 if (m_breadcrumbs.empty()) m_breadcrumbs = n;
266 else m_breadcrumbs = n +
" | " + m_breadcrumbs;
274 m_destinationKind = destination_kind::push;
282 m_destinationKind = destination_kind::pull;
285 void add_to_set(node_set s) {
287 m_add_to_set.push_back(s);
290 void add_dependencies(node_set s) {
292 m_add_relations.push_back(std::make_pair(s,bits::no_forward_depends));
295 void add_forwarding_dependencies(node_set s) {
297 m_add_relations.push_back(std::make_pair(s,bits::depends));
300 void forward(
const std::string & key, any_noncopyable value) {
301 m_forwards.push_back({key, std::move(value)});
305 void init_common(node & r) {
306 if (m_set) r.set_memory_fraction(
memory());
308 for (
size_t i = 0; i < m_hooks.size(); ++i) {
309 m_hooks[i]->init_node(r);
312 auto nodeMap = r.get_node_map()->find_authority();
314 for (
auto &p : m_forwards) {
315 nodeMap->forward_from_pipe_base(r.get_id(), p.first, std::move(p.second));
321 destination_kind::type m_destinationKind;
322 std::string m_name, m_phaseName;
323 std::string m_breadcrumbs;
324 priority_type m_namePriority, m_phaseNamePriority;
325 std::vector<factory_init_hook *> m_hooks;
326 std::vector<node_set> m_add_to_set;
327 std::vector<std::pair<node_set, bits::node_relation> > m_add_relations;
328 std::vector<std::pair<std::string, any_noncopyable> > m_forwards;
335 #endif // __TPIE_PIPELINING_FACTORY_BASE_H__
void set_destination_kind_push()
Used by pipe_base classes to indicate that the default actor edge is a push edge. ...
void hook_initialization(factory_init_hook *hook)
Add a node initialization hook.
void memory(double amount)
Set memory fraction for this node in the pipeline phase.
void add_default_edge(node &r, const node &dest) const
Used by pipe_base classes to set a default actor edge for ordinary push/pull nodes.
void set_phase_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's phase name.
void add_pull_source(const node_token &dest)
Called by implementers to declare a pull source.
bits::node_map::ptr get_node_map() const
Get the local node map, mapping node IDs to node pointers for all the nodes reachable from this one...
void add_default_edge(node &r, const node_token &dest) const
Used by pipe_base classes to set a default actor edge for ordinary push/pull nodes.
Base class of all pipelining factories.
void copy_hooks_to(factory_base &other) const
Copy the hooks that have been added to this factory to another.
const node_token & get_token() const
Get the node_token that maps this node's ID to a pointer to this.
void init_node(node &r)
Initialize node constructed in a subclass.
void phase_name(const std::string &n, priority_type p)
Set name for this phase.
void set_breadcrumb(const std::string &breadcrumb)
Used internally when a pair_factory has a name set.
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
void name(const std::string &n, priority_type p)
Set name for this node.
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
void init_sub_node(node &r)
Initialize node constructed in a subclass.
double memory() const
Set memory fraction for this node in the pipeline phase.
node_token::id_t get_id() const
Get the internal node ID of this node (mainly for debugging purposes).
void set_destination_kind_pull()
Used by pipe_base classes to indicate that the default actor edge is a pull edge. ...
void push_breadcrumb(const std::string &n)
Set a prefix for the name of this node.