ROOT
ROOT project
Loading...
Searching...
No Matches
writer_def.hpp
Go to the documentation of this file.
1
16#ifndef ROOT_WRITER_DEF_HPP
17#define ROOT_WRITER_DEF_HPP
18
19#include <Eigen/Dense>
20#include <fstream>
21#include <iostream>
22#include <string>
23
25
26template <typename V>
27class PrinterBase;
28
32template <typename T>
33class Writer {
34 private:
35 friend class WriterBaseTester; //<! Friend test fixture class for unit testing.
40 template <typename V>
41 void build_printer(std::unique_ptr<PrinterBase<V>>& printer);
42
43 protected:
46 char separator;
47 bool overwrite;
48 std::string filename;
49
50 public:
59 Writer(const T& vals_to_write, WritingMethod write_method, std::string filename = "output", char separator = ',',
60 bool overwrite = true);
64 void write();
65};
66
68template <typename V>
70 public:
72 PrinterBase() = default;
74 virtual ~PrinterBase() = default;
79 virtual void write_values(const V& value) = 0;
80};
81
83template <typename V>
84class PrinterCLI : public PrinterBase<V> {
85 public:
87 PrinterCLI();
92 void write_values(const V& value) override;
93};
94
96template <typename V>
97class PrinterFile : public PrinterBase<V> {
98 protected:
99 std::string filename;
100 bool append;
102 std::ofstream file;
103
104 public:
110 PrinterFile(const std::string& fname, bool ow_mode);
111};
112
114template <typename V>
115class PrinterDAT : public PrinterFile<V> {
116 public:
122 PrinterDAT(const std::string& fname, bool ow_mode);
127 void write_values(const V& value) override;
128};
129
131template <typename V>
132class PrinterCSV : public PrinterFile<V> {
133 private:
135
136 public:
143 PrinterCSV(const std::string& fname, char sep, bool ow_mode);
149 void write_values(const V& value) override;
150};
151
153template <typename V>
154// LLM
155class PrinterGNUPlot : public PrinterDAT<V> {
156 public:
162 PrinterGNUPlot(const std::string& fname, bool ow_mode);
165};
166
167#include "writer.hpp"
168
169#endif // ROOT_WRITER_HPP
Abstract Printer class.
Definition writer_def.hpp:69
virtual ~PrinterBase()=default
Virtual destructor for the PrinterBase class.
PrinterBase()=default
Default constructor for the PrinterBase class.
virtual void write_values(const V &value)=0
Pure virtual method to write a given value.
The class to print out the values in the CLI.
Definition writer_def.hpp:84
void write_values(const V &value) override
Method to actually print a given value in the output.
PrinterCLI()
Constructor for the PrinterCLI class - just prints out a string.
Definition writer.hpp:68
Class to write on .csv the result.
Definition writer_def.hpp:132
void write_values(const V &value) override
Writes a given result into the .csv file with the sotred separator.
char separator
Separator for the .csv output file, given at construction time.
Definition writer_def.hpp:134
Class to write on .dat the result - daughter of FilePrinter and Mother of GnuPlotPrinter.
Definition writer_def.hpp:115
void write_values(const V &value) override
Writes a given result into the .dat file.
Mother class for all the Printers which print in a file.
Definition writer_def.hpp:97
bool append
Definition writer_def.hpp:100
std::ofstream file
The actual file, saved in order not to access it at each printing iteration.
Definition writer_def.hpp:102
std::string filename
The name of output file, without the extension.
Definition writer_def.hpp:99
Class Daughter of PrinterDAT to write on .dat (inherited) and produce a gnu plot for the results.
Definition writer_def.hpp:155
void generate_gnuplot_script() const
Calls the generation of the .png output plot.
Tester class for Writer class unit tests.
Definition writer_tester.hpp:22
Class to store required arguments and handle the printing flow.
Definition writer_def.hpp:33
Writer(const T &vals_to_write, WritingMethod write_method, std::string filename="output", char separator=',', bool overwrite=true)
Constructor for a Writer object.
char separator
Separator for .csv files.
Definition writer_def.hpp:46
void build_printer(std::unique_ptr< PrinterBase< V > > &printer)
Method to convert the generic Printer into a typed one for a specific output destination.
Definition writer.hpp:47
bool overwrite
Option to overwrite or append the output file.
Definition writer_def.hpp:47
void write()
Method to run the printing loop and correctly initialize the Printer.
WritingMethod method
Method to write with - defined thanks to.
Definition writer_def.hpp:45
std::string filename
Name of the output file.
Definition writer_def.hpp:48
T values
Templated values to write to allow different usage of the class.
Definition writer_def.hpp:44
WritingMethod
Definition writer_def.hpp:24
@ CONSOLE
Definition writer_def.hpp:24
@ CSV
Definition writer_def.hpp:24
@ DAT
Definition writer_def.hpp:24
@ GNUPLOT
Definition writer_def.hpp:24