Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
sensitivityfilestream.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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 orea/engine/sensitivityfilestream.hpp
20 \brief Class for streaming SensitivityRecords from file
21 */
22
23#pragma once
24
26
27#include <fstream>
28#include <string>
29
30namespace ore {
31namespace analytics {
32
33//! Class for streaming SensitivityRecords from csv file
35public:
36 //! Constructor
37 SensitivityInputStream(char delim = ',', const std::string& comment = "#")
38 : delim_(delim), comment_(comment), lineNo_(0) {}
39 virtual ~SensitivityInputStream() {} // Declare virtual destructor
40
41 /*! Set stream for function */
42 void setStream(std::istream* stream);
43 //! Returns the next SensitivityRecord in the stream
44 SensitivityRecord next() override;
45 //! Resets the stream so that SensitivityRecord objects can be streamed again
46 void reset() override;
47
48private:
49 //! Handle on the stram
50 std::istream* stream_;
51 //! Csv file delimiter
52 char delim_;
53 //! Csv file comment string
54 std::string comment_;
55 //! Keep track of line number for messages
56 QuantLib::Size lineNo_;
57
58 //! Create a record from a collection of strings
59 SensitivityRecord processRecord(const std::vector<std::string>& entries) const;
60};
61
63public:
64 //! Constructor providing path to csv file \p fileName
65 SensitivityFileStream(const std::string& fileName, char delim = ',', const std::string& comment = "#");
66
67 ~SensitivityFileStream() override;
68
69private:
70 std::ifstream* file_;
71};
72
74public:
75 //! Constructor providing path to csv file \p fileName
76 SensitivityBufferStream(const std::string& buffer, char delim = ',', const std::string& comment = "#");
77};
78
79} // namespace analytics
80} // namespace ore
Class for streaming SensitivityRecords from csv file.
QuantLib::Size lineNo_
Keep track of line number for messages.
std::istream * stream_
Handle on the stram.
std::string comment_
Csv file comment string.
SensitivityRecord processRecord(const std::vector< std::string > &entries) const
Create a record from a collection of strings.
SensitivityInputStream(char delim=',', const std::string &comment="#")
Constructor.
void reset() override
Resets the stream so that SensitivityRecord objects can be streamed again.
SensitivityRecord next() override
Returns the next SensitivityRecord in the stream.
Base Class for streaming SensitivityRecords.
Base class for sensitivity record streamer.