Chaste  Release::2018.1
ChastePoint.hpp
1 /*
2 
3 Copyright (c) 2005-2018, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 
37 #ifndef _CHASTEPOINT_HPP_
38 #define _CHASTEPOINT_HPP_
39 
40 #include "ChasteSerialization.hpp"
41 #include "UblasVectorInclude.hpp"
42 #include <vector>
43 
44 
48 template<unsigned DIM>
50 {
52  friend class boost::serialization::access;
59  template<class Archive>
60  void serialize(Archive & archive, const unsigned int version)
61  {
62  //archive & mLocation; //earlier versions of boost are unable to do this. See #1709
63  }
64 
65 private:
66 
68  c_vector<double, DIM> mLocation;
69 
70 public:
71 
86  ChastePoint(double v1=0, double v2=0, double v3=0);
87 
95  ChastePoint(std::vector<double> coords);
96 
102  ChastePoint(c_vector<double, DIM> location);
103 
107  c_vector<double, DIM>& rGetLocation();
108 
112  const c_vector<double, DIM>& rGetLocation() const;
113 
119  double operator[] (unsigned i) const;
120 
126  double GetWithDefault(unsigned i, double def=0.0) const;
127 
134  void SetCoordinate(unsigned i, double value);
135 
142  bool IsSamePoint(const ChastePoint<DIM>& rPoint) const;
143 };
144 
145 
147 // Declare identifier for the serializer
149 
150 namespace boost
151 {
152 namespace serialization
153 {
154 
155 template<class Archive, unsigned SPACE_DIM>
156 inline void save_construct_data(
157  Archive & ar, const ChastePoint<SPACE_DIM> * t, const unsigned int file_version)
158 {
159  for (unsigned i = 0; i < SPACE_DIM; i ++)
160  {
161  //we archive coordinates of mLocation one by one
162  //this is because earlier version of boost (<1.40, I think) cannot archive c_vectors
163  double coord = t->GetWithDefault(i);
164  ar & coord;
165  }
166 }
167 
172 template<class Archive,unsigned SPACE_DIM>
173 inline void load_construct_data(
174  Archive & ar, ChastePoint<SPACE_DIM> * t, const unsigned int file_version)
175 {
176  std::vector<double> coords;
177  coords.resize(SPACE_DIM);
178  for (unsigned i=0; i<SPACE_DIM; i++)
179  {
180  double coordinate;
181  ar & coordinate;//resume coordinates one by one
182  coords[i] = coordinate;
183  }
184  //use constructor with standard vectors to re-build the object
185  ::new(t)ChastePoint<SPACE_DIM>(coords);
186 }
187 }
188 } // namespace ...
189 
190 
196 template<>
197 class ChastePoint<0>
198 {
199 public:
208  ChastePoint(double v1=0, double v2=0, double v3=0);
209 
216  double operator[] (unsigned i) const;
217 };
218 
219 #endif //_CHASTEPOINT_HPP_
c_vector< double, DIM > & rGetLocation()
Definition: ChastePoint.cpp:76
double GetWithDefault(unsigned i, double def=0.0) const
Definition: ChastePoint.cpp:95
double operator[](unsigned i) const
Definition: ChastePoint.cpp:88
c_vector< double, DIM > mLocation
Definition: ChastePoint.hpp:68
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void SetCoordinate(unsigned i, double value)
ChastePoint(double v1=0, double v2=0, double v3=0)
Definition: ChastePoint.cpp:44
void serialize(Archive &archive, const unsigned int version)
Definition: ChastePoint.hpp:60
gcov doesn't like this file...
bool IsSamePoint(const ChastePoint< DIM > &rPoint) const