24 #ifndef __TPIE_PIPELINING_VIRTUAL_H__
25 #define __TPIE_PIPELINING_VIRTUAL_H__
29 namespace pipelining {
49 typedef const T & type;
54 typedef const T & type;
59 typedef const T * type;
77 template <
typename Input>
79 typedef typename maybe_add_const_ref<Input>::type input_type;
83 virtual void push(input_type v) = 0;
89 template <
typename dest_t>
92 typedef typename dest_t::item_type item_type;
95 typedef typename maybe_add_const_ref<item_type>::type input_type;
103 this->
set_name(
"Virtual source", PRIORITY_INSIGNIFICANT);
110 void push(input_type v) {
120 template <
typename Output>
126 typedef Output item_type;
133 set_name(
"Virtual destination", PRIORITY_INSIGNIFICANT);
138 , m_self(other.m_self)
139 , m_virtdest(other.m_virtdest)
146 if (m_virtdest == 0) {
151 void push(
typename maybe_add_const_ref<Output>::type v) {
155 void set_destination(virtsrc<Output> * dest) {
156 if (m_virtdest != 0) {
177 typedef boost::shared_ptr<virt_node> ptr;
180 std::auto_ptr<node> m_pipeSegment;
181 std::auto_ptr<virtual_container> m_container;
191 n->m_pipeSegment.reset(pipe);
212 m_container.reset(ctr);
221 template <
typename T,
typename U,
typename Result>
223 static Result go(...) {
233 template <
typename T,
typename Result>
235 static Result go(Result r) {
246 virt_node::ptr m_node;
250 virt_node::ptr get_node()
const {
return m_node; }
254 this->m_segmap = segmap;
258 this->m_segmap = segmap;
262 m_node->set_container(ctr);
265 operator bool() {
return m_node; }
271 template <
typename Input>
275 template <
typename Input,
typename Output>
279 template <
typename Output>
287 template <
typename,
typename>
292 template <
typename Input>
294 template <
typename Input,
typename Output>
296 template <
typename Input,
typename Output>
298 template <
typename Output>
307 template <
typename Input>
314 src_type * get_source()
const {
return m_src; }
328 template <
typename fact_t>
339 template <
typename M
id>
346 template <
typename fact_t>
349 log_error() <<
"Virtual chunk assigned twice" << std::endl;
353 typedef typename fact_t::constructed_type constructed_type;
365 template <
typename Input,
typename Output=Input>
366 class virtual_chunk :
public bits::virtual_chunk_base {
367 friend class bits::access;
368 typedef bits::access acc;
369 typedef bits::virtsrc<Input> src_type;
370 typedef bits::virtrecv<Output> recv_type;
373 src_type * get_source()
const {
return m_src; }
374 recv_type * get_destination()
const {
return m_recv; }
389 template <
typename fact_t>
400 template <
typename M
id>
403 : virtual_chunk_base(left.get_node_map(), bits::virt_node::combine(left.get_node(), right.get_node()))
405 m_src = acc::get_source(left);
406 m_recv = acc::get_destination(right);
412 template <
typename fact_t>
415 log_error() <<
"Virtual chunk assigned twice" << std::endl;
418 typedef typename fact_t::template constructed<recv_type>::type constructed_type;
430 template <
typename NextOutput>
436 m_recv->set_destination(acc::get_source(dest));
448 m_recv->set_destination(acc::get_source(dest));
453 template <
typename Input>
454 template <
typename M
id>
457 : virtual_chunk_base(left.get_node_map(),
458 bits::virt_node::combine(left.get_node(), right.get_node()))
460 m_src = acc::get_source(left);
466 template <
typename Output>
472 recv_type * get_destination()
const {
return m_recv; }
486 template <
typename fact_t>
497 template <
typename M
id>
500 : virtual_chunk_base(left.get_node_map(),
501 bits::virt_node::combine(left.get_node(), right.get_node()))
503 m_recv = acc::get_destination(right);
509 template <
typename fact_t>
512 log_error() <<
"Virtual chunk assigned twice" << std::endl;
515 typedef typename fact_t::template constructed<recv_type>::type constructed_type;
525 template <
typename NextOutput>
532 m_recv->set_destination(acc::get_source(dest));
542 m_recv->set_destination(acc::get_source(dest));
543 return virtual_chunk_base(this->m_segmap,
550 template <
typename Input>
551 virtsrc<Input> * access::get_source(
const virtual_chunk_end<Input> & chunk) {
552 return chunk.get_source();
555 template <
typename Input,
typename Output>
556 virtsrc<Input> * access::get_source(
const virtual_chunk<Input, Output> & chunk) {
557 return chunk.get_source();
560 template <
typename Input,
typename Output>
561 virtrecv<Output> * access::get_destination(
const virtual_chunk<Input, Output> & chunk) {
562 return chunk.get_destination();
565 template <
typename Output>
566 virtrecv<Output> * access::get_destination(
const virtual_chunk_begin<Output> & chunk) {
567 return chunk.get_destination();
576 #endif // __TPIE_PIPELINING_VIRTUAL_H__
virtual void begin()
Begin pipeline processing phase.
virtual_chunk< Input, NextOutput > operator|(virtual_chunk< Output, NextOutput > dest)
Connect this virtual chunk to another chunk.
virtual_chunk()
Constructor that leaves the virtual chunk unassigned.
virtual_chunk_begin< NextOutput > operator|(virtual_chunk< Output, NextOutput > dest)
Connect this virtual chunk to another chunk.
void begin()
Begin pipeline processing phase.
virtual_chunk(const pipe_middle< fact_t > &pipe, virtual_container *ctr=0)
Constructor that recursively constructs a node and takes ownership of it.
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...
Virtual node that is injected into the end of a virtual chunk.
Base class of virtual chunks. Owns a virt_node.
static ptr combine(ptr left, ptr right)
Aggregate ownership of virt_nodes.
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
Virtual chunk that has no output (that is, virtual consumer).
const node_token & get_token()
Get the node_token that maps this node's ID to a pointer to this.
Virtual superclass for pipelines implementing the function call operator.
virtual_chunk_begin()
Constructor that leaves the virtual chunk unassigned.
Virtual base class for extra data to go with virtual chunks.
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
Virtual chunk that has no input (that is, virtual producer).
The maybe_add_const_ref helper struct adds const & to a type unless the type is already const...
static ptr take_own(node *pipe)
Take std::new-ownership of given node.
Helper class that throws an exception on behalf of virtual_chunks that have not been assigned a pipe_...
void set_container(virtual_container *ctr)
Set and/or reset the virtual_container assigned to this virtual node.
virtual_chunk_end()
Constructor that leaves the virtual chunk unassigned.
A pipe_middle class pushes input down the pipeline.
Virtual base node that is injected into the beginning of a virtual chunk.
virtual_chunk_begin(const virtual_chunk_begin< Mid > &left, const virtual_chunk< Mid, Output > &right)
Constructor that combines two virtual chunks.
node()
Default constructor, using a new node_token.
virtual_chunk_end & operator=(const pipe_end< fact_t > &pipe)
Construct a node and assign it to this virtual chunk.
virtual_chunk_end< Input > operator|(virtual_chunk_end< Output > dest)
Connect this virtual chunk to another chunk.
Concrete implementation of virtsrc.
logstream & log_error()
Return logstream for writing error log messages.
virtual_chunk(const virtual_chunk< Input, Mid > &left, const virtual_chunk< Mid, Output > &right)
Constructor that combines two virtual chunks.
Virtual chunk that has input and output.
virtual_chunk_base operator|(virtual_chunk_end< Output > dest)
Connect this virtual chunk to another chunk.
virtual_chunk & operator=(const pipe_middle< fact_t > &pipe)
Construct a node and assign it to this virtual chunk.
virtual_chunk_begin & operator=(const pipe_begin< fact_t > &pipe)
Construct a node and assign it to this virtual chunk.
virtual_chunk_begin(const pipe_begin< fact_t > &pipe, virtual_container *ctr=0)
Constructor that recursively constructs a node and takes ownership of it.
virtual_chunk_end(const pipe_end< fact_t > &pipe, virtual_container *ctr=0)
Constructor that recursively constructs a node and takes ownership of it.