20 #ifndef __TPIE_PIPELINING_PAIR_FACTORY_H__
21 #define __TPIE_PIPELINING_PAIR_FACTORY_H__
24 #include <tpie/pipelining/priority_type.h>
25 #include <tpie/pipelining/factory_base.h>
29 namespace pipelining {
33 template <
typename child_t>
37 : m_maps(
new node_map::ptr[2])
43 : m_maps(
new node_map::ptr[2])
44 , m_final(other.m_final)
46 m_maps[0] = other.m_maps[0];
47 m_maps[1] = other.m_maps[1];
50 inline double memory()
const {
51 return self().fact1.memory() +
self().fact2.memory();
54 inline void name(
const std::string & n, priority_type) {
58 void push_breadcrumb(
const std::string & n) {
59 self().fact1.push_breadcrumb(n);
60 self().fact2.push_breadcrumb(n);
67 self().hook_initialization_impl(hook);
74 template <
typename pipe_t>
75 pipe_t
record(
size_t idx,
const pipe_t & pipe)
const {
76 m_maps[idx] = pipe.get_node_map();
77 if (idx == 0 && m_final) {
81 self().recursive_connected_check();
86 void assert_connected()
const {
87 if (m_maps[0]->find_authority() != m_maps[1]->find_authority()) {
88 log_error() <<
"Segment map disconnected - more information in debug log." << std::endl;
90 <<
"Note about node implementations.\n\n"
91 "In a node constructor that accepts a destination node,\n"
92 "a relation should always be established between the current node\n"
93 "and the destination using one of the member functions add_push_destination,\n"
94 "add_pull_source and add_dependency.\n\n"
95 "If this relational graph is not connected, some nodes will not\n"
96 "be initialized: prepare(), begin(), end() and other methods will never\n"
97 "be called, and memory will not be assigned.\n"
98 "---------------------------------------------------------------------------" << std::endl;
99 throw tpie::exception(
"Segment map disconnected - did you forget to add_push_destination?");
113 inline child_t &
self() {
return *
static_cast<child_t*
>(
this);}
114 inline const child_t &
self()
const {
return *
static_cast<const child_t*
>(
this);}
116 boost::scoped_array<node_map::ptr> m_maps;
124 template <
typename fact_t>
127 template <
typename fact1_t,
typename fact2_t>
130 template <
typename dest_t>
135 inline pair_factory(
const fact1_t & fact1,
const fact2_t & fact2)
136 : fact1(fact1), fact2(fact2) {
139 template <
typename dest_t>
140 typename constructed<dest_t>::type
141 construct(
const dest_t & dest)
const {
142 return this->
record(0, fact1.construct(this->record(1, fact2.construct(dest))));
145 void recursive_connected_check()
const {
146 maybe_check_connected<fact1_t>::check(fact1);
147 maybe_check_connected<fact2_t>::check(fact2);
150 void hook_initialization_impl(factory_init_hook * hook) {
151 fact1.hook_initialization(hook);
152 fact2.hook_initialization(hook);
159 template <
typename fact1_t,
typename termfact2_t>
162 typedef typename fact1_t::template constructed<typename termfact2_t::constructed_type>::type constructed_type;
173 constructed_type construct()
const {
174 return this->
record(0, fact1.construct(this->record(1, fact2.construct())));
177 void recursive_connected_check()
const {
183 fact1.hook_initialization(hook);
184 fact2.hook_initialization(hook);
192 template <
typename fact1_t,
typename fact2_t>
195 fact.assert_connected();
202 template <
typename fact1_t,
typename termfact2_t>
205 fact.assert_connected();
213 template <
typename fact_t>
215 static void check(
const fact_t & ) {
225 #endif // __TPIE_PIPELINING_PAIR_FACTORY_H__
void hook_initialization(factory_init_hook *hook)
See factory_base::hook_initialization.
Contains a method check that calls recursive_connected_check when fact_t is a pair factory...
pipe_t record(size_t idx, const pipe_t &pipe) const
Internal - used by subclasses to record references to node_maps for a later connectivity check...
logstream & log_debug()
Return logstream for writing debug log messages.
logstream & log_error()
Return logstream for writing error log messages.