20 #ifndef __TPIE_PIPELINING_PAIR_FACTORY_H__
21 #define __TPIE_PIPELINING_PAIR_FACTORY_H__
25 #include <tpie/pipelining/priority_type.h>
26 #include <tpie/pipelining/factory_base.h>
27 #include <boost/scoped_array.hpp>
31 namespace pipelining {
35 template <
typename child_t>
39 : m_maps(
new node_map::ptr[2])
47 m_final = other.m_final;
48 swap(m_maps, other.m_maps);
54 m_final = other.m_final;
55 swap(m_maps, other.m_maps);
58 inline double memory()
const {
59 return self().fact1.memory() +
self().fact2.memory();
62 inline void name(
const std::string & n, priority_type) {
66 void push_breadcrumb(
const std::string & n) {
67 self().fact1.push_breadcrumb(n);
68 self().fact2.push_breadcrumb(n);
75 self().hook_initialization_impl(hook);
82 template <
typename pipe_t>
83 pipe_t
record(
size_t idx, pipe_t && pipe)
const {
84 m_maps[idx] = pipe.get_node_map();
85 if (idx == 0 && m_final) {
89 self().recursive_connected_check();
91 return std::move(pipe);
94 void assert_connected()
const {
95 if (m_maps[0]->find_authority() != m_maps[1]->find_authority()) {
96 log_error() <<
"Node map disconnected - more information in debug log"
97 <<
" (" <<
typeid(child_t).name() <<
")" << std::endl;
99 <<
"Note about node implementations.\n\n"
100 "In a node constructor that accepts a destination node,\n"
101 "a relation should always be established between the current node\n"
102 "and the destination using one of the member functions add_push_destination,\n"
103 "add_pull_source and add_dependency.\n\n"
104 "If this relational graph is not connected, some nodes will not\n"
105 "be initialized: prepare(), begin(), end() and other methods will never\n"
106 "be called, and memory will not be assigned.\n"
107 "---------------------------------------------------------------------------" << std::endl;
108 throw tpie::exception(
"Node map disconnected - did you forget to add_push_destination?");
124 void set_destination_kind_push() {
125 self().fact2.set_destination_kind_push();
131 void set_destination_kind_pull() {
132 self().fact1.set_destination_kind_pull();
136 inline child_t &
self() {
return *
static_cast<child_t*
>(
this);}
137 inline const child_t &
self()
const {
return *
static_cast<const child_t*
>(
this);}
139 boost::scoped_array<node_map::ptr> m_maps;
147 template <
typename fact_t>
150 template <
typename fact1_t,
typename fact2_t>
153 template <
typename dest_t>
164 : fact1(std::move(fact1)), fact2(std::move(fact2)) {
167 template <
typename dest_t>
168 typename constructed<dest_t>::type
169 construct(dest_t && dest) {
170 return this->
record(0, fact1.construct(this->record(1, fact2.construct(std::forward<dest_t>(dest)))));
173 template <
typename dest_t>
174 typename constructed<dest_t>::type
175 construct_copy(dest_t && dest) {
176 return this->
record(0, fact1.construct_copy(this->record(1, fact2.construct_copy(std::forward<dest_t>(dest)))));
179 void recursive_connected_check()
const {
180 maybe_check_connected<fact1_t>::check(fact1);
181 maybe_check_connected<fact2_t>::check(fact2);
184 void hook_initialization_impl(factory_init_hook * hook) {
185 fact1.hook_initialization(hook);
186 fact2.hook_initialization(hook);
193 template <
typename fact1_t,
typename termfact2_t>
196 typedef typename fact1_t::template constructed<typename termfact2_t::constructed_type>::type constructed_type;
206 : fact1(std::move(fact1))
207 , fact2(std::move(fact2))
214 constructed_type construct() {
215 return this->
record(0, fact1.construct(this->record(1, fact2.construct())));
218 constructed_type construct_copy() {
219 return this->
record(0, fact1.construct_copy(this->record(1, fact2.construct_copy())));
222 void recursive_connected_check()
const {
228 fact1.hook_initialization(hook);
229 fact2.hook_initialization(hook);
237 template <
typename fact1_t,
typename fact2_t>
240 fact.assert_connected();
247 template <
typename fact1_t,
typename termfact2_t>
250 fact.assert_connected();
258 template <
typename fact_t>
260 static void check(
const fact_t & ) {
270 #endif // __TPIE_PIPELINING_PAIR_FACTORY_H__
void hook_initialization(factory_init_hook *hook)
See factory_base::hook_initialization.
pipe_t record(size_t idx, pipe_t &&pipe) const
Internal - used by subclasses to record references to node_maps for a later connectivity check...
Logging functionality and log_level codes for different priorities of log messages.
Contains a method check that calls recursive_connected_check when fact_t is a pair factory...
child_t & finalize()
Signal that this factory is used to instantiate a pipeline_impl, i.e.
logstream & log_debug()
Return logstream for writing debug log messages.
logstream & log_error()
Return logstream for writing error log messages.