fpmas 1.6
output.h
Go to the documentation of this file.
1#ifndef FPMAS_OUTPUT_API_H
2#define FPMAS_OUTPUT_API_H
3
5
11namespace fpmas { namespace api { namespace io {
12
16 class Output {
17 public:
21 virtual void dump() = 0;
30 virtual const scheduler::Job& job() = 0;
31
32 virtual ~Output() {}
33 };
34
45 /*
46 * Note: operator<< wrappers return std::ostream& instead of OutputStream&.
47 * This does not make much difference in terms of user experience, but is
48 * useful in the case of the DynamicFileOutput, where get() systematically
49 * reopens the file, what discard content if openmode is out.
50 * So for example, if OutputStream& is returned:
51 * ```
52 * dynamic_file_output << "hello" << "world";
53 * ```
54 * would print "world" to the file, since the second << operator call
55 * destroys the file.
56 * But, if std::ostream& is returned, only the first operator destroys the
57 * file so "helloworld" is printed.
58 *
59 * However, in the following example:
60 * ```
61 * dynamic_file_output << "hello";
62 * dynamic_file_output << "world";
63 * ```
64 * The file contains "world" since it is destroyed at the second call, what
65 * is however a relatively consistent behavior.
66 */
67 struct OutputStream {
73 virtual std::ostream& get() = 0;
74
79 std::ostream& operator<<(std::ostream& (*func)(std::ostream&)) {
80 return this->get() << func;
81 }
82
83 virtual ~OutputStream() {}
84 };
85
91 template<typename T>
92 std::ostream& operator<<(OutputStream& output, const T& data) {
93 return output.get() << data;
94 }
95
102 template<typename T>
103 using Watcher = std::function<T()>;
104}}}
105#endif
Definition: output.h:16
virtual const scheduler::Job & job()=0
virtual void dump()=0
Definition: scheduler.h:135
std::ostream & operator<<(OutputStream &output, const T &data)
Definition: output.h:92
std::function< T()> Watcher
Definition: output.h:103
Definition: fpmas.cpp:3
Definition: output.h:67
virtual std::ostream & get()=0
std::ostream & operator<<(std::ostream &(*func)(std::ostream &))
Definition: output.h:79