KADATH
dim_array.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "utilities.hpp"
21 #include "dim_array.hpp"
22 namespace Kadath {
23 
25  int read_size{};
26  fread_be(&read_size, sizeof(int), 1, fd) ;
27  this->resize(read_size) ;
28  fread_be(this->set_data(), sizeof(int), size, fd) ;
29 }
30 
31 
32 void Dim_array::save (FILE* fd) const {
33  int const size{static_cast<int>(this->get_size())};
34  fwrite_be(&size, sizeof(int), 1, fd) ;
35  fwrite_be(this->get_data(), sizeof(int), size, fd) ;
36 }
37 
38 // Output
39 ostream& operator<< (ostream& o, const Dim_array& so) {
40  o << "(" ;
41  for (int i=0 ; i<so.get_ndim()-1 ; i++)
42  o << so(i) << ", " ;
43  o << so.back() << ")" ;
44  return o ;
45 }
46 
47 }
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
int get_ndim() const
Returns the number of dimensions.
Definition: dim_array.hpp:63
Dim_array(int dim)
Standard constructor.
Definition: dim_array.hpp:43
void save(FILE *) const
Save function.
Definition: dim_array.cpp:32
Memory_mapped_array< int > Data_type
Sylvain's stuff.
Definition: dim_array.hpp:37