KADATH
point.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 __POINT_HPP_
21 #define __POINT_HPP_
22 
23 #include "headcpp.hpp"
24 namespace Kadath {
25 
30  class Point : public Memory_mapped {
31  protected:
32  int ndim ;
33  Memory_mapped_array<double> coord ;
34 
35  public:
40  explicit Point (int n) : ndim{n}, coord{ndim} {
41  for (int i=0 ; i<ndim ; i++) coord[i] = 0 ;
42  }
43  Point (FILE*) ;
44 
45  void save (FILE*) const ;
47  double& set(int i) {assert(i>0); assert(i<=ndim); return coord[i-1] ;}
49  double operator() (int i) const {assert(i>0); assert(i<=ndim); return coord[i-1] ;}
51  const int& get_ndim() const {return ndim ;} ;
52 
53  friend ostream& operator<< (ostream&, const Point&) ;
54  } ;
55 }
56 #endif
The class Point is used to store the coordinates of a point.
Definition: point.hpp:30
Memory_mapped_array< double > coord
Array on the coordinates (mainly designed for absolute Cartesian coordinates).
Definition: point.hpp:33
friend ostream & operator<<(ostream &, const Point &)
Display.
Definition: point.cpp:38
double operator()(int i) const
Read only access to a coordinate.
Definition: point.hpp:49
int ndim
Number of dimensions.
Definition: point.hpp:32
void save(FILE *) const
Saving function.
Definition: point.cpp:33
const int & get_ndim() const
Returns the number of dimensions.
Definition: point.hpp:51
Point(int n)
Standard constructor (the coordinates are not affected).
Definition: point.hpp:40
double & set(int i)
Read/write of a coordinate.
Definition: point.hpp:47