TPIE

11a2c2d
factory_base.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2011, 2012, 2013, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
23 
24 #ifndef __TPIE_PIPELINING_FACTORY_BASE_H__
25 #define __TPIE_PIPELINING_FACTORY_BASE_H__
26 
27 #include <tpie/tpie_export.h>
28 #include <tpie/pipelining/node_set.h>
29 #include <tpie/pipelining/node.h>
30 #include <tpie/pipelining/tokens.h>
31 
32 namespace tpie::pipelining {
33 
35 public:
36  virtual void init_node(node & r) = 0;
37  virtual ~factory_init_hook() {
38  }
39 };
40 
42  enum type {
43  none,
44  push,
45  pull
46  };
47 };
48 
73 class TPIE_EXPORT factory_base {
74 public:
75  factory_base() = default;
76  factory_base(const factory_base & other) = delete;
77  factory_base(factory_base &&) = default;
78  factory_base & operator=(const factory_base & other) = delete;
79  factory_base & operator=(factory_base &&) = default;
80 
87  inline void memory(double amount) noexcept {
88  m_amount = amount;
89  m_set = true;
90  }
91 
99  inline double memory() const noexcept {
100  return m_amount;
101  }
102 
109  void hook_initialization(factory_init_hook * hook);
110 
114  void copy_hooks_to(factory_base & other) const;
115 
126  void init_node(node & r);
127 
138  void init_sub_node(node & r);
139 
144  void add_default_edge(node & r, const node & dest) const;
145 
150  void add_default_edge(node & r, const node_token & dest) const;
151 
152  void add_node_set_edges(node & r) const;
153 
160  inline void name(const std::string & n, priority_type p) {
161  m_name = n;
162  m_namePriority = p;
163  }
164 
171  inline void phase_name(const std::string & n, priority_type p) {
172  m_phaseName = n;
173  m_phaseNamePriority = p;
174  }
175 
176 
183  inline void push_breadcrumb(const std::string & n) {
184  if (m_breadcrumbs.empty()) m_breadcrumbs = n;
185  else m_breadcrumbs = n + " | " + m_breadcrumbs;
186  }
187 
192  void set_destination_kind_push() noexcept {
193  m_destinationKind = destination_kind::push;
194  }
195 
200  void set_destination_kind_pull() noexcept {
201  m_destinationKind = destination_kind::pull;
202  }
203 
204  void add_to_set(node_set s);
205 
206  void add_dependencies(node_set s);
207 
208  void add_forwarding_dependencies(node_set s);
209 
210  void forward(const std::string & key, any_noncopyable value);
211 
212 private:
213  void init_common(node & r);
214 
215  double m_amount = 0;
216  bool m_set = false;
217  destination_kind::type m_destinationKind = destination_kind::none;
218  std::string m_name, m_phaseName;
219  std::string m_breadcrumbs;
220  priority_type m_namePriority = PRIORITY_NO_NAME, m_phaseNamePriority = PRIORITY_NO_NAME;
221  std::vector<factory_init_hook *> m_hooks;
222  std::vector<node_set> m_add_to_set;
223  std::vector<std::pair<node_set, bits::node_relation> > m_add_relations;
224  std::vector<std::pair<std::string, any_noncopyable> > m_forwards;
225 };
226 
227 } // namespace tpie::pipelining
228 
229 #endif // __TPIE_PIPELINING_FACTORY_BASE_H__
tpie::pipelining
pipelining/factory_base.h Base class of pipelining factories
Definition: ami_glue.h:23
tpie::pipelining::factory_base::memory
double memory() const noexcept
Set memory fraction for this node in the pipeline phase.
Definition: factory_base.h:99
tpie::pipelining::factory_base::push_breadcrumb
void push_breadcrumb(const std::string &n)
Set a prefix for the name of this node.
Definition: factory_base.h:183
tpie::pipelining::factory_base::phase_name
void phase_name(const std::string &n, priority_type p)
Set name for this phase.
Definition: factory_base.h:171
tpie::pipelining::factory_base::set_destination_kind_pull
void set_destination_kind_pull() noexcept
Used by pipe_base classes to indicate that the default actor edge is a pull edge.
Definition: factory_base.h:200
tpie::pipelining::factory_base::memory
void memory(double amount) noexcept
Set memory fraction for this node in the pipeline phase.
Definition: factory_base.h:87
tpie::pipelining::factory_base
Base class of all pipelining factories.
Definition: factory_base.h:73
tpie::pipelining::factory_base::set_destination_kind_push
void set_destination_kind_push() noexcept
Used by pipe_base classes to indicate that the default actor edge is a push edge.
Definition: factory_base.h:192
tpie::pipelining::destination_kind
Definition: factory_base.h:41
tokens.h
tpie::pipelining::factory_base::name
void name(const std::string &n, priority_type p)
Set name for this node.
Definition: factory_base.h:160
tpie::pipelining::node
Base class of all nodes.
Definition: node.h:77
tpie::pipelining::node_token
Definition: tokens.h:292
tpie::pipelining::factory_init_hook
Definition: factory_base.h:34
tpie::pipelining::any_noncopyable
Definition: container.h:195