KADATH
point.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 "headcpp.hpp"
21 #include <assert.h>
22 #include "point.hpp"
23 #include "utilities.hpp"
24 namespace Kadath {
25 
26 Point::Point (FILE* fd) : ndim{}, coord{} {
27  fread_be (&ndim, sizeof(int), 1, fd) ;
28  coord.resize(ndim) ;
29  fread_be (coord.set_data(), sizeof(double), ndim, fd) ;
30 }
31 
32 
33 void Point::save (FILE* fd) const {
34  fwrite_be (&ndim, sizeof(int), 1, fd) ;
35  fwrite_be (coord.get_data(), sizeof(double), ndim, fd) ;
36 }
37 
38 ostream& operator<< (ostream& o, const Point& so) {
39 
40  o << "(" ;
41  for (int i=0 ; i<so.ndim-1 ; i++)
42  o << so.coord[i] << ", " ;
43  o << so.coord[so.ndim-1] << ")" ;
44  return o ;
45 }}
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
int ndim
Number of dimensions.
Definition: point.hpp:32
void save(FILE *) const
Saving function.
Definition: point.cpp:33
Point(int n)
Standard constructor (the coordinates are not affected).
Definition: point.hpp:40