Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
InMemoryReport Class Reference

#include <ored/report/inmemoryreport.hpp>

+ Inheritance diagram for InMemoryReport:
+ Collaboration diagram for InMemoryReport:

Public Member Functions

 InMemoryReport ()
 
ReportaddColumn (const string &name, const ReportType &rt, Size precision=0) override
 
Reportnext () override
 
Reportadd (const ReportType &rt) override
 
Reportadd (const InMemoryReport &report)
 
void end () override
 
Size columns () const
 
Size rows () const
 
const string & header (Size i) const
 
bool hasHeader (string h) const
 
ReportType columnType (Size i) const
 
Size columnPrecision (Size i) const
 
const vector< ReportType > & data (Size i) const
 Returns the data. More...
 
void toFile (const string &filename, const char sep=',', const bool commentCharacter=true, char quoteChar='\0', const string &nullString="#N/A", bool lowerHeader=false)
 
void jumpToColumn (Size i)
 
- Public Member Functions inherited from Report
virtual ~Report ()
 
virtual ReportaddColumn (const string &name, const ReportType &, Size precision=0)=0
 
virtual Reportnext ()=0
 
virtual Reportadd (const ReportType &rt)=0
 
virtual void end ()=0
 
virtual void flush ()
 

Private Attributes

Size i_
 
vector< string > headers_
 
vector< ReportTypecolumnTypes_
 
vector< Size > columnPrecision_
 
vector< vector< ReportType > > data_
 

Additional Inherited Members

- Public Types inherited from Report
typedef boost::variant< Size, Real, string, Date, Period > ReportType
 

Detailed Description

InMemoryReport just stores report information in local vectors and provides an interface to access the values. It could be used as a backend to a GUI

Definition at line 41 of file inmemoryreport.hpp.

Constructor & Destructor Documentation

◆ InMemoryReport()

Definition at line 43 of file inmemoryreport.hpp.

Member Function Documentation

◆ addColumn()

Report & addColumn ( const string &  name,
const ReportType rt,
Size  precision = 0 
)
overridevirtual

Implements Report.

Definition at line 26 of file inmemoryreport.cpp.

26 {
27 headers_.push_back(name);
28 columnTypes_.push_back(rt);
29 columnPrecision_.push_back(precision);
30 data_.push_back(vector<ReportType>()); // Initialise vector for
31 i_++;
32 return *this;
33}
vector< Size > columnPrecision_
vector< ReportType > columnTypes_
vector< vector< ReportType > > data_
string name

◆ next()

Report & next ( )
overridevirtual

Implements Report.

Definition at line 35 of file inmemoryreport.cpp.

35 {
36 QL_REQUIRE(i_ == headers_.size(), "Cannot go to next line, only " << i_ << " entires filled, report headers are: "
37 << boost::join(headers_, ","));
38 i_ = 0;
39 return *this;
40}
+ Here is the caller graph for this function:

◆ add() [1/2]

Report & add ( const ReportType rt)
overridevirtual

Implements Report.

Definition at line 42 of file inmemoryreport.cpp.

42 {
43 // check type is valid
44 QL_REQUIRE(i_ < headers_.size(), "No column to add [" << rt << "] to.");
45 QL_REQUIRE(rt.which() == columnTypes_[i_].which(), "Cannot add value "
46 << rt << " of type " << rt.which() << " to column "
47 << headers_[i_] << " of type " << columnTypes_[i_].which()
48 << ", report headers are: " << boost::join(headers_, ","));
49
50 data_[i_].push_back(rt);
51 i_++;
52 return *this;
53}
+ Here is the caller graph for this function:

◆ add() [2/2]

Report & add ( const InMemoryReport report)

Definition at line 55 of file inmemoryreport.cpp.

55 {
56 QL_REQUIRE(columns() == report.columns(), "Cannot combine reports of different sizes ("
57 << columns() << " vs " << report.columns()
58 << "), report headers are: " << boost::join(headers_, ","));
59 end();
60 for (Size i = 0; i < columns(); i++) {
61 string h1 = headers_[i];
62 string h2 = report.header(i);
63 QL_REQUIRE(h1 == h2, "Cannot combine reports with different headers (\""
64 << h1 << "\" and \"" << h2
65 << "\"), report headers are: " << boost::join(headers_, ","));
66 }
67
68 if (i_ == headers_.size())
69 next();
70
71 for (Size rowIdx = 0; rowIdx < report.rows(); rowIdx++) {
72 for (Size columnIdx = 0; columnIdx < report.columns(); columnIdx++) {
73 add(report.data(columnIdx)[rowIdx]);
74 }
75 next();
76 }
77
78 return *this;
79}
Report & add(const ReportType &rt) override
Report & next() override
+ Here is the call graph for this function:

◆ end()

void end ( )
overridevirtual

Implements Report.

Definition at line 81 of file inmemoryreport.cpp.

81 {
82 QL_REQUIRE(i_ == headers_.size() || i_ == 0, "report is finalized with incomplete row, got data for "
83 << i_ << " columns out of " << columns()
84 << ", report headers are: " << boost::join(headers_, ","));
85}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ columns()

Size columns ( ) const

Definition at line 52 of file inmemoryreport.hpp.

52{ return headers_.size(); }
+ Here is the caller graph for this function:

◆ rows()

Size rows ( ) const

Definition at line 53 of file inmemoryreport.hpp.

53{ return columns() == 0 ? 0 : data_[0].size(); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ header()

const string & header ( Size  i) const

Definition at line 54 of file inmemoryreport.hpp.

54{ return headers_[i]; }
+ Here is the caller graph for this function:

◆ hasHeader()

bool hasHeader ( string  h) const

Definition at line 55 of file inmemoryreport.hpp.

55{ return std::find(headers_.begin(), headers_.end(), h) != headers_.end(); }

◆ columnType()

ReportType columnType ( Size  i) const

Definition at line 56 of file inmemoryreport.hpp.

56{ return columnTypes_[i]; }

◆ columnPrecision()

Size columnPrecision ( Size  i) const

Definition at line 57 of file inmemoryreport.hpp.

57{ return columnPrecision_[i]; }

◆ data()

const vector< Report::ReportType > & data ( Size  i) const

Returns the data.

Definition at line 87 of file inmemoryreport.cpp.

87 {
88 QL_REQUIRE(data_[i].size() == rows(), "internal error: report column "
89 << i << " (" << header(i) << ") contains " << data_[i].size()
90 << " rows, expected are " << rows()
91 << " rows, report headers are: " << boost::join(headers_, ","));
92 return data_[i];
93}
const string & header(Size i) const
Size size(const ValueType &v)
Definition: value.cpp:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toFile()

void toFile ( const string &  filename,
const char  sep = ',',
const bool  commentCharacter = true,
char  quoteChar = '\0',
const string &  nullString = "#N/A",
bool  lowerHeader = false 
)

Definition at line 95 of file inmemoryreport.cpp.

96 {
97
98 CSVFileReport cReport(filename, sep, commentCharacter, quoteChar, nullString, lowerHeader);
99
100 for (Size i = 0; i < headers_.size(); i++) {
101 cReport.addColumn(headers_[i], columnTypes_[i], columnPrecision_[i]);
102 }
103
104 auto numColumns = columns();
105 if (numColumns > 0) {
106 auto numRows = data_[0].size();
107
108 for (Size i = 0; i < numRows; i++) {
109 cReport.next();
110 for (Size j = 0; j < numColumns; j++) {
111 cReport.add(data_[j][i]);
112 }
113 }
114 }
115
116 cReport.end();
117}
+ Here is the call graph for this function:

◆ jumpToColumn()

void jumpToColumn ( Size  i)

Definition at line 62 of file inmemoryreport.hpp.

62{ i_ = i; }

Member Data Documentation

◆ i_

Size i_
private

Definition at line 65 of file inmemoryreport.hpp.

◆ headers_

vector<string> headers_
private

Definition at line 66 of file inmemoryreport.hpp.

◆ columnTypes_

vector<ReportType> columnTypes_
private

Definition at line 67 of file inmemoryreport.hpp.

◆ columnPrecision_

vector<Size> columnPrecision_
private

Definition at line 68 of file inmemoryreport.hpp.

◆ data_

vector<vector<ReportType> > data_
private

Definition at line 69 of file inmemoryreport.hpp.