Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
csvreport.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file ored/report/csvreport.hpp
20 \brief CSV Report class
21 \ingroup report
22*/
23
24#pragma once
25
27#include <stdio.h>
28#include <vector>
29
30namespace ore {
31namespace data {
32
33class ReportTypePrinter;
34/*! CSV Report class
35
36\ingroup report
37*/
38class CSVFileReport : public Report {
39public:
40 /*! Create a report with the given filename, will throw if it cannot open the file.
41 \param filename name of the csv file that is created
42 \param sep separator character for the csv file. It defaults to a comma.
43 \param commentCharacter if \c true, the first row starts with the \c # character.
44 \param quoteChar character to use to quote strings. If not provided, strings are not quoted.
45 \param nullString string used to represent \c QuantLib::Null values or infinite values. If not provided,
46 this defaults to \c \#N/A.
47 \param lowerHeader if \c true, makes the first character of each header lower case.
48 \param rolloverSize in MB, if set we rollover over to a new csv when file size grows above this
49 */
50 CSVFileReport(const string& filename, const char sep = ',', const bool commentCharacter = true,
51 char quoteChar = '\0', const std::string& nullString = "#N/A", bool lowerHeader = false,
52 QuantLib::Size rolloverSize = QuantLib::Null<QuantLib::Size>());
54
55 void open();
56 void rollover();
57 Report& addColumn(const string& name, const ReportType& rt, Size precision = 0) override;
58 Report& next() override;
59 Report& add(const ReportType& rt) override;
60 void end() override;
61 void flush() override;
62
63private:
64 void checkIsOpen(const std::string& op) const;
65
66 std::vector<ReportType> columnTypes_;
67 std::vector<ReportTypePrinter> printers_;
69 char sep_;
72 std::string nullString_;
74 QuantLib::Size rolloverSize_;
75 Size i_, j_ = 0;
76 Size version_ = 0;
77 FILE* fp_;
78 bool finalized_ = false;
79 std::vector<std::string> headers_;
80};
81} // namespace data
82} // namespace ore
std::string baseFilename_
Definition: csvreport.hpp:68
void flush() override
Definition: csvreport.cpp:130
Report & add(const ReportType &rt) override
Definition: csvreport.cpp:175
std::vector< ReportTypePrinter > printers_
Definition: csvreport.hpp:67
std::vector< std::string > headers_
Definition: csvreport.hpp:79
void end() override
Definition: csvreport.cpp:191
Report & next() override
Definition: csvreport.cpp:153
void checkIsOpen(const std::string &op) const
Definition: csvreport.cpp:211
QuantLib::Size rolloverSize_
Definition: csvreport.hpp:74
Report & addColumn(const string &name, const ReportType &rt, Size precision=0) override
Definition: csvreport.cpp:136
std::vector< ReportType > columnTypes_
Definition: csvreport.hpp:66
boost::variant< Size, Real, string, Date, Period > ReportType
Definition: report.hpp:66
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Report interface class.
string name