20 #ifndef __TPIE_PIPELINING_FILE_STREAM_H__
21 #define __TPIE_PIPELINING_FILE_STREAM_H__
23 #include <tpie/file_stream.h>
25 #include <tpie/pipelining/node.h>
26 #include <tpie/pipelining/factory_helpers.h>
27 #include <tpie/pipelining/pipe_base.h>
29 #include <tpie/flags.h>
38 TPIE_DECLARE_OPERATORS_FOR_FLAGS(stream_option)
48 template <
typename dest_t>
55 set_name(
"Read", PRIORITY_INSIGNIFICANT);
60 if (options & STREAM_RESET) fs.seek(0);
63 forward(
"items", fs.size() - fs.offset());
72 while (fs.can_read()) {
80 if (options & STREAM_CLOSE) fs.close();
94 template <
typename dest_t>
99 named_input_t(dest_t dest, std::string path) : dest(std::move(dest)), path(path) {
101 set_name(
"Read", PRIORITY_INSIGNIFICANT);
113 while (fs->can_read()) {
114 dest.push(fs->read());
131 template <
typename T>
137 set_name(
"Read", PRIORITY_INSIGNIFICANT);
142 if (options & STREAM_RESET) fs.seek(0);
143 forward(
"items", fs.size()-fs.offset());
153 return fs.can_read();
157 if (options & STREAM_CLOSE) fs.close();
170 template <
typename T>
176 set_name(
"Read", PRIORITY_INSIGNIFICANT);
188 return fs.read_back();
192 return fs.can_read_back();
196 if (options & STREAM_CLOSE) fs.close();
209 template <
typename T>
215 set_name(
"Read", PRIORITY_INSIGNIFICANT);
232 return fs->can_read();
250 template <
typename T>
256 set_name(
"Write", PRIORITY_INSIGNIFICANT);
260 void push(
const T & item) {
272 template <
typename T>
278 set_name(
"Write", PRIORITY_INSIGNIFICANT);
287 void push(
const T & item) {
306 template <
typename source_t>
313 set_name(
"Write", PRIORITY_INSIGNIFICANT);
319 while (source.can_pull()) {
320 fs.write(source.pull());
330 template <
typename dest_t,
typename T>
338 void push(
const item_type & i) {
347 template <
typename source_t,
typename T>
352 set_minimum_memory(fs.memory_usage());
356 return source.can_pull();
360 item_type i = source.pull();
380 return {fs, options};
399 return {fs, options};
412 return {fs, options};
421 return {std::move(path)};
429 template <
typename T>
438 template <
typename T>
440 return {std::move(path)};
458 template <
typename T>
468 template <
typename T>
@ access_write
Open a file for writing only, content is truncated.
pipelining/factory_base.h Base class of pipelining factories
pullpipe_end< factory< bits::pull_output_t, file_stream< T > & > > pull_output(file_stream< T > &fs)
A pull-pipe node that writes the pulled items to a file stream.
void add_pull_source(const node_token &dest)
Called by implementers to declare a pull source.
const T & read()
Reads next item from stream if can_read() == true.
void go() override
For initiator nodes, execute this phase by pushing all items to be pushed.
void set_minimum_memory(memory_size_type minimumMemory)
Called by implementers to declare minimum memory requirements.
Class to deduce the item_type of a node of type T.
pipe_middle< tfactory< bits::tee_t, Args< typename T::item_type >, T & > > tee(T &fs)
A pipelining node that writes the pushed to a file stream and then pushes the items to the next node.
void forward(std::string key, T value, memory_size_type k=std::numeric_limits< memory_size_type >::max())
Called by implementers to forward auxiliary data to successors.
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
void end() override
End pipeline processing phase.
pullpipe_middle< tfactory< bits::pull_tee_t, Args< typename T::item_type >, T & > > pull_tee(T &fs)
A pull-pipe node that when pulled from will pull from its source, write its item to disk and then ret...
pipe_begin< factory< bits::named_input_t, std::string > > named_input
Pipelining nodes that pushes the contents of the named file stream to the next node in the pipeline.
void step(stream_size_type steps=1)
Step the progress indicator.
void set_steps(stream_size_type steps)
Called by implementers that intend to call step().
pullpipe_begin< termfactory< bits::pull_input_t< T >, file_stream< T > &, stream_options > > pull_input(file_stream< T > &fs, stream_options options=stream_options())
A pipelining pull-node that reads items from the given file_stream.
pipe_begin< factory< bits::input_t, file_stream< T > &, stream_options > > input(file_stream< T > &fs, stream_options options=stream_options())
Pipelining nodes that pushes the contents of the given file stream to the next node in the pipeline.
pullpipe_begin< termfactory< bits::pull_reverse_input_t< T >, file_stream< T > &, stream_options > > pull_reverse_input(file_stream< T > &fs, stream_options options=stream_options())
A pipelining pull-node that reads items in reverse order from the given file_stream.
pullpipe_begin< termfactory< bits::named_pull_input_t< T >, std::string > > named_pull_input(std::string path)
A pipelining pull-node that reads items from the given file path.
pipe_end< termfactory< bits::named_output_t< T >, std::string > > named_output(std::string path)
A pipelining node that writes the pushed items to a named file stream.
void begin() override
Begin pipeline processing phase.
pipe_end< termfactory< bits::output_t< T >, file_stream< T > & > > output(file_stream< T > &fs)
A pipelining node that writes the pushed items to a file stream.
@ access_read
Open a file for reading.