Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
matrix-bypass-load.h
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21
22#ifndef __ANTARES_LIBS_ARRAY_MATRIX_BYPASS_LOAD_H__
23#define __ANTARES_LIBS_ARRAY_MATRIX_BYPASS_LOAD_H__
24
25#include "fill-matrix.h"
26
27using namespace Yuni;
28
29namespace Antares
30{
31namespace UnitTests
32{
34{
35 template<class U>
36 inline U operator()(const U& value) const
37 {
38 return value;
39 }
40};
41} // namespace UnitTests
42} // namespace Antares
43
44template<class T = double, class ReadWriteT = T>
45class Matrix_load_bypass: public Matrix_easy_to_fill<T, ReadWriteT>
46{
47 using BufferType = typename Matrix<T, ReadWriteT>::BufferType;
48
49public:
52 loadFromCSVFile_called(false)
53 {
54 }
55
58 loadFromCSVFile_called(false)
59 {
60 }
61
62 Matrix_load_bypass(uint height, uint width, const vector<T>& vec):
64 loadFromCSVFile_called(false)
65 {
66 }
67
68 bool loadFromCSVFile(const AnyString& /* filename */,
69 uint /* minWidth */,
70 uint /* maxHeight */,
71 uint /* options */,
72 BufferType* /* buffer */) override
73 {
74 loadFromCSVFile_called = true;
75 return true;
76 }
77
78public:
79 bool loadFromCSVFile_called;
80};
81
82template<class T = double, class ReadWriteT = T>
84{
85public:
87 buffer_precision_(0),
88 buffer_print_dimensions_(false)
89 {
90 }
91
92 ~fake_buffer_factory() = default;
93
94 void matrix_to_build_buffer_with(Matrix_easy_to_fill<T, ReadWriteT>* mtx)
95 {
96 mtx_to_build_buffer_with_ = mtx;
97 }
98
99 void set_precision(uint precision)
100 {
101 buffer_precision_ = precision;
102 }
103
104 void print_dimensions(bool print_dims)
105 {
106 buffer_print_dimensions_ = print_dims;
107 }
108
109 Clob* build_buffer()
110 {
111 Clob* buffer_to_return = new Clob;
112 std::string buffer;
114
115 mtx_to_build_buffer_with_->saveToFileDescriptor(buffer,
116 buffer_precision_,
117 buffer_print_dimensions_,
118 predicate);
119
120 buffer_to_return->append(buffer);
121
122 return buffer_to_return;
123 }
124
125private:
126 uint buffer_precision_;
127 bool buffer_print_dimensions_;
128 Matrix_easy_to_fill<T, ReadWriteT>* mtx_to_build_buffer_with_;
129};
130
131template<class T = double, class ReadWriteT = T>
132class Matrix_mock_load_to_buffer: public Matrix<T, ReadWriteT>
133{
134public:
137 fake_mtx_error_when_loading_(IO::errNone)
138 {
139 }
140
143 fake_mtx_error_when_loading_(IO::errNone)
144 {
145 }
146
147 Matrix_mock_load_to_buffer(uint height, uint width, const vector<T>& vec):
149 fake_mtx_error_when_loading_(IO::errNone)
150 {
151 }
152
153 IO::Error loadFromFileToBuffer(typename Matrix<T, ReadWriteT>::BufferType& /* buffer */,
154 const AnyString& /* filename */) const override
155 {
156 return fake_mtx_error_when_loading_;
157 }
158
159 void error_when_loading_from_file(IO::Error err)
160 {
161 fake_mtx_error_when_loading_ = err;
162 }
163
164private:
165 IO::Error fake_mtx_error_when_loading_;
166};
167
168#endif // __ANTARES_LIBS_ARRAY_MATRIX_BYPASS_LOAD_H__
A n-by-n matrix.
Definition jit.h:30
uint width
Definition matrix.h:441
uint height
Definition matrix.h:443
Matrix()
Definition matrix.hxx:202
Yuni::Clob BufferType
A buffer, for large amount of data.
Definition matrix.h:65
Definition fill-matrix.h:36
Definition matrix-bypass-load.h:46
bool loadFromCSVFile(const AnyString &, uint, uint, uint, BufferType *) override
Load entries from a CSV file.
Definition matrix-bypass-load.h:68
Definition matrix-bypass-load.h:133
Definition matrix-bypass-load.h:84
Definition matrix-bypass-load.h:34