Antares Simulator
Power System Simulator
matrix-bypass-load.h
1 /*
2  * Copyright 2007-2025, 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 
27 using namespace Yuni;
28 
29 namespace Antares::UnitTests
30 {
32 {
33  template<class U>
34  inline U operator()(const U& value) const
35  {
36  return value;
37  }
38 };
39 } // namespace Antares::UnitTests
40 
41 template<class T = double, class ReadWriteT = T>
42 class Matrix_load_bypass: public Matrix_easy_to_fill<T, ReadWriteT>
43 {
44  using BufferType = typename Matrix<T, ReadWriteT>::BufferType;
45 
46 public:
49  loadFromCSVFile_called(false)
50  {
51  }
52 
53  Matrix_load_bypass(uint height, uint width):
55  loadFromCSVFile_called(false)
56  {
57  }
58 
59  Matrix_load_bypass(uint height, uint width, const vector<T>& vec):
60  Matrix_easy_to_fill<T, ReadWriteT>(height, width, vec),
61  loadFromCSVFile_called(false)
62  {
63  }
64 
65  bool loadFromCSVFile(const AnyString& /* filename */,
66  uint /* minWidth */,
67  uint /* maxHeight */,
68  uint /* options */,
69  BufferType* /* buffer */) override
70  {
71  loadFromCSVFile_called = true;
72  return true;
73  }
74 
75 public:
76  bool loadFromCSVFile_called;
77 };
78 
79 template<class T = double, class ReadWriteT = T>
81 {
82 public:
84  buffer_precision_(0),
85  buffer_print_dimensions_(false)
86  {
87  }
88 
89  ~fake_buffer_factory() = default;
90 
91  void matrix_to_build_buffer_with(Matrix_easy_to_fill<T, ReadWriteT>* mtx)
92  {
93  mtx_to_build_buffer_with_ = mtx;
94  }
95 
96  void set_precision(uint precision)
97  {
98  buffer_precision_ = precision;
99  }
100 
101  void print_dimensions(bool print_dims)
102  {
103  buffer_print_dimensions_ = print_dims;
104  }
105 
106  Clob* build_buffer()
107  {
108  Clob* buffer_to_return = new Clob;
109  std::string buffer;
111 
112  mtx_to_build_buffer_with_->saveToFileDescriptor(buffer,
113  buffer_precision_,
114  buffer_print_dimensions_,
115  predicate);
116 
117  buffer_to_return->append(buffer);
118 
119  return buffer_to_return;
120  }
121 
122 private:
123  uint buffer_precision_;
124  bool buffer_print_dimensions_;
125  Matrix_easy_to_fill<T, ReadWriteT>* mtx_to_build_buffer_with_;
126 };
127 
128 template<class T = double, class ReadWriteT = T>
129 class Matrix_mock_load_to_buffer: public Matrix<T, ReadWriteT>
130 {
131 public:
134  fake_mtx_error_when_loading_(IO::errNone)
135  {
136  }
137 
138  Matrix_mock_load_to_buffer(uint height, uint width):
139  Matrix<T, ReadWriteT>(height, width),
140  fake_mtx_error_when_loading_(IO::errNone)
141  {
142  }
143 
144  Matrix_mock_load_to_buffer(uint height, uint width, const vector<T>& vec):
145  Matrix<T, ReadWriteT>(height, width, vec),
146  fake_mtx_error_when_loading_(IO::errNone)
147  {
148  }
149 
150  IO::Error loadFromFileToBuffer(typename Matrix<T, ReadWriteT>::BufferType& /* buffer */,
151  const AnyString& /* filename */) const override
152  {
153  return fake_mtx_error_when_loading_;
154  }
155 
156  void error_when_loading_from_file(IO::Error err)
157  {
158  fake_mtx_error_when_loading_ = err;
159  }
160 
161 private:
162  IO::Error fake_mtx_error_when_loading_;
163 };
164 
165 #endif // __ANTARES_LIBS_ARRAY_MATRIX_BYPASS_LOAD_H__
A n-by-n matrix.
Definition: matrix.h:44
Definition: fill-matrix.h:36
Definition: matrix-bypass-load.h:43
Definition: matrix-bypass-load.h:130
Definition: matrix-bypass-load.h:81
Definition: matrix-bypass-load.h:32