24 #ifndef TPIE_PIPELINING_SERIALIZATION_H
25 #define TPIE_PIPELINING_SERIALIZATION_H
27 #include <tpie/pipelining/node.h>
28 #include <tpie/pipelining/factory_helpers.h>
29 #include <tpie/pipelining/pair_factory.h>
34 namespace pipelining {
36 namespace serialization_bits {
38 template <
typename dest_t>
44 typedef typename dest_t::item_type item_type;
59 virtual void go()
override {
61 stream_size_type bytesRead = 0;
62 while (rd->can_read()) {
66 stream_size_type bytesRead2 = rd->
offset();
67 step(bytesRead2 - bytesRead);
68 bytesRead = bytesRead2;
90 void push(
const T & x) {
107 template <
typename T>
108 pipe_end<typename serialization_bits::output_factory<T>::type>
110 return typename serialization_bits::output_factory<T>::type(&wr);
113 namespace serialization_bits {
117 template <
typename dest_t>
127 typedef typename dest_t::item_type item_type;
129 rev_output_t(
const dest_t & dest)
133 this->
set_name(
"Serialization reverse reader");
141 rd.open(m_stack->
path());
145 virtual void go()
override {
147 stream_size_type bytesRead = 0;
148 while (rd.can_read()) {
152 stream_size_type bytesRead2 = rd.
offset();
153 step(bytesRead2 - bytesRead);
154 bytesRead = bytesRead2;
158 virtual void end()
override {
165 template <
typename dest_t>
168 template <
typename output_dest_t>
174 stream_size_type items;
177 typedef typename dest_t::item_type item_type;
184 this->set_name(
"Serialization reverse writer");
190 wr.open(dest.m_stack->
path());
193 void push(
const item_type & x) {
198 virtual void end()
override {
200 this->forward<stream_size_type>(
"items", items);
210 pipe_middle<serialization_bits::reverse_factory>
211 inline serialization_reverser() {
212 serialization_bits::rev_input_factory i;
213 serialization_bits::rev_output_factory o;
214 return serialization_bits::reverse_factory(i, o);
221 #endif // TPIE_PIPELINING_SERIALIZATION_H
stream_size_type offset()
Number of bytes read, not including the header.
virtual void propagate() override
Propagate stream metadata.
Node factory for 1-argument terminator.
Stream of serializable items.
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
stream_size_type size()
Size of file in bytes, not including the header.
void serialize(const T &v)
Serialize a serializable item and write it to the stream.
stream_size_type offset()
Number of bytes read, not including the header.
const std::string & path()
Get the path of the associated file.
void unserialize(T &v)
Unserialize an unserializable item from the stream.
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
Class representing the existence of a temporary file.
void set_minimum_memory(memory_size_type minimumMemory)
Called by implementers to declare minimum memory requirements.
Node factory for 1-argument generator.
void add_dependency(const node_token &dest)
Called by implementers to declare a node dependency, that is, a requirement that another node has end...
virtual void end() override
End pipeline processing phase.
void step(stream_size_type steps=1)
Step the progress indicator.
virtual void go() override
For initiator nodes, execute this phase by pushing all items to be pushed.
void set_steps(stream_size_type steps)
Called by implementers that intend to call step().
Node factory for 0-argument generator.