KADATH
dim_array.hpp
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 #ifndef __DIM_ARRAY_HPP_
21 #define __DIM_ARRAY_HPP_
22 
23 #include "headcpp.hpp"
24 
25 namespace Kadath {
34 class Dim_array : public Memory_mapped_array<int> {
35  public:
37  using Data_type = Memory_mapped_array<int>;
39  using size_type = int;
43  explicit Dim_array (int dim) : Data_type{dim} {}
47  Dim_array (const Dim_array &so): Data_type{so} {}
48  Dim_array (FILE*) ;
49 
54  int& set(int i) {assert(i>=0); assert(i<size); return data[i];}
59  int operator() (int i) const {assert(i>=0); assert(i<size); return data[i];}
63  int get_ndim() const {return size ;} ;
67  void operator= (const Dim_array& so) {assert (size==so.size);for (int i=0 ;i<size;i++) data[i] = so.data[i];}
68 
70  void swap(Dim_array & so) {}
71  void save (FILE*) const ;
72 
73  Dim_array(Dim_array &&so) : Memory_mapped_array<int>{std::forward<Dim_array&&>(so)} {}
75  Dim_array & operator=(Dim_array && so) {Memory_mapped_array<int>::operator=(std::forward<Dim_array&&>(so)); return *this;}
76 } ;
77 
78 ostream& operator<< (ostream&, const Dim_array&) ;
79 inline bool operator== (const Dim_array& a, const Dim_array& b) {
80  bool res = (a.get_ndim()==b.get_ndim()) ? true : false ;
81  if (res)
82  for (int i=0 ; i<a.get_ndim() && res ; i++)
83  res = (a(i) == b(i));
84  return res ;
85 }
86 // Anti-comparison operator
87 inline bool operator!= (const Dim_array& a, const Dim_array& b) {return !(a==b) ;}
88 }
89 #endif
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
int & set(int i)
Read/write of the size of a given dimension.
Definition: dim_array.hpp:54
void save(FILE *) const
Save function.
Definition: dim_array.cpp:32
Dim_array(const Dim_array &so)
Copy constructor.
Definition: dim_array.hpp:47
int operator()(int i) const
Read only of the size of a given dimension.
Definition: dim_array.hpp:59
Dim_array & operator=(Dim_array &&so)
Operator =.
Definition: dim_array.hpp:75
int size_type
Sylvain's stuff.
Definition: dim_array.hpp:39
Dim_array(Dim_array &&so)
Move constructor.
Definition: dim_array.hpp:73
void swap(Dim_array &so)
Sylvain's stuff.
Definition: dim_array.hpp:70
void operator=(const Dim_array &so)
Assignement to annother Dim_array.
Definition: dim_array.hpp:67
Memory_mapped_array< int > Data_type
Sylvain's stuff.
Definition: dim_array.hpp:37