20 #ifndef __TPIE_PIPELINING_REVERSE_H__
21 #define __TPIE_PIPELINING_REVERSE_H__
23 #include <tpie/pipelining/node.h>
24 #include <tpie/pipelining/pipe_base.h>
25 #include <tpie/pipelining/factory_helpers.h>
30 namespace pipelining {
35 typedef std::vector<T> buf_t;
46 set_name(
"Input items to reverse", PRIORITY_INSIGNIFICANT);
49 inline void push(
const T & item) {
55 typename buf_t::iterator it;
58 template <
typename dest_t>
70 set_name(
"Output reversed items", PRIORITY_INSIGNIFICANT);
74 forward(
"items", static_cast<stream_size_type>(buffer.size()));
78 pi.
init(buffer.size());
79 while (it != buffer.rend()) {
89 typename buf_t::const_reverse_iterator it;
99 inline pipe_end<termfactory_2<sink_t, buf_t &, const node_token &> >
101 return termfactory_2<sink_t, buf_t &, const node_token &>(buffer, sink_token);
104 inline pipe_begin<factory_2<source_t, const buf_t &, const node_token &> >
106 return factory_2<source_t, const buf_t &, const node_token &>(buffer, sink_token);
111 node_token sink_token;
116 template <
typename T>
124 set_name(
"Store items", PRIORITY_SIGNIFICANT);
129 the_stack = tpie_new<stack<item_type> >();
133 void push(
const T & t) {
140 template <
typename dest_t>
143 typedef typename dest_t::item_type item_type;
150 set_name(
"Output reversed", PRIORITY_INSIGNIFICANT);
155 the_stack = fetch<stack<item_type> *>(
"stack");
160 virtual void go()
override {
161 while (!the_stack->
empty()) {
162 dest.push(the_stack->
pop());
167 virtual void end()
override {
176 template <
typename dest_t>
179 typedef typename dest_t::item_type item_type;
187 , output(dest, input_token)
190 set_name(
"Reverser", PRIORITY_INSIGNIFICANT);
195 , input_token(o.input_token)
201 void push(
const item_type & i) {input.push(i);}
217 #endif // __TPIE_PIPELINING_REVERSE_H__
virtual void go() override
For initiator nodes, execute this phase by pushing all items to be pushed.
virtual void propagate() override
Propagate stream metadata.
The base class for indicating the progress of some task.
const T & pop()
Pops one item from the stack.
virtual void done()
Advance the indicator to the end.
An implementation of an external-memory stack.
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
stream_size_type size() const
Returns the number of items currently on the stack.
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
void set_minimum_memory(memory_size_type minimumMemory)
Called by implementers to declare minimum memory requirements.
void step(stream_size_type step=1)
Record an increment to the indicator and advance the indicator.
void add_dependency(const node_token &dest)
Called by implementers to declare a node dependency, that is, a requirement that another node has end...
void step(stream_size_type steps=1)
Step the progress indicator.
bool empty() const
Returns whether the stack is empty or not.
A pipe_middle class pushes input down the pipeline.
static memory_size_type memory_usage(float blockFactor=1.0)
Compute the memory used by a stack.
void tpie_delete(T *p)
Delete an object allocated with tpie_new.
void set_steps(stream_size_type steps)
Called by implementers that intend to call step().
void go(progress_indicator_base &pi)
Deprecated go()-implementation signature.
node()
Default constructor, using a new node_token.
void forward(std::string key, T value, bool explicitForward=true)
Called by implementers to forward auxiliary data to successors.
virtual void end() override
End pipeline processing phase.
virtual void propagate() override
Propagate stream metadata.
Node factory for 0-argument generator.
virtual void init(stream_size_type range=0)
Initialize progress indicator.