Antares Simulator
Power System Simulator
fill-matrix.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_FILL_MTX_H__
23 #define __ANTARES_LIBS_ARRAY_MATRIX_FILL_MTX_H__
24 
25 #include <vector>
26 
27 #include <boost/test/unit_test.hpp>
28 
29 #include <antares/array/matrix.h>
30 
31 using namespace std;
32 using namespace Antares;
33 
34 template<class T = double, class ReadWriteT = T>
35 class Matrix_easy_to_fill: public Matrix<T, ReadWriteT>
36 {
37 public:
40  {
41  }
42 
43  Matrix_easy_to_fill(uint height, uint width):
44  Matrix<T, ReadWriteT>(height, width)
45  {
46  }
47 
48  Matrix_easy_to_fill(uint height, uint width, const vector<T>& vec):
50  {
51  BOOST_REQUIRE_EQUAL(height * width, vec.size());
52  this->reset(width, height, true);
53  uint count = 0;
54  for (uint j = 0; j < height; j++)
55  {
56  for (uint i = 0; i < width; i++)
57  {
58  this->entry[i][j] = vec[count];
59  count++;
60  }
61  }
62  }
63 
64  bool openFile(Yuni::IO::File::Stream& /* file */,
65  const AnyString& /* filename */) const override
66  {
67  return true;
68  }
69 
70  void saveBufferToFile(std::string& buffer, Yuni::IO::File::Stream& /* f */) const override
71  {
72  data = buffer;
73  }
74 
75 public:
76  mutable std::string data;
77 };
78 
79 #endif // __ANTARES_LIBS_ARRAY_MATRIX_FILL_MTX_H__
A n-by-n matrix.
Definition: matrix.h:44
Definition: fill-matrix.h:36
bool openFile(Yuni::IO::File::Stream &, const AnyString &) const override
Trying to open a file.
Definition: fill-matrix.h:64