Chaste  Release::2017.1
CellPropertyCollection.hpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 #ifndef CELLPROPERTYCOLLECTION_HPP_
37 #define CELLPROPERTYCOLLECTION_HPP_
38 
39 #include <set>
40 #include <boost/shared_ptr.hpp>
41 
42 #include "ChasteSerialization.hpp"
43 #include <boost/serialization/shared_ptr.hpp>
44 #include <boost/serialization/set.hpp>
45 
46 #include "AbstractCellProperty.hpp"
47 #include "CellPropertyRegistry.hpp"
48 #include "Exception.hpp"
49 
56 {
57 private:
59  typedef std::set<boost::shared_ptr<AbstractCellProperty> > CollectionType;
60 
62  typedef CollectionType::const_iterator ConstIteratorType;
63 
65  typedef CollectionType::iterator IteratorType;
66 
68  CollectionType mProperties;
69 
72 
81  template<class Archive>
82  void serialize(Archive & archive, const unsigned int version)
83  {
84  archive & mProperties;
85  // archive & mpCellPropertyRegistry; Not required as archived by the CellPopulation.
86  }
87 
88 public:
93 
99  void AddProperty(const boost::shared_ptr<AbstractCellProperty>& rProp);
100 
105 
112 
118  bool HasProperty(const boost::shared_ptr<AbstractCellProperty>& rProp) const;
119 
126  template<typename CLASS>
127  bool HasProperty() const
128  {
129  for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
130  {
131  if ((*it)->IsType<CLASS>())
132  {
133  return true;
134  }
135  }
136  return false;
137  }
138 
145  template<typename BASECLASS>
146  bool HasPropertyType() const
147  {
148  for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
149  {
150  if ((*it)->IsSubType<BASECLASS>())
151  {
152  return true;
153  }
154  }
155  return false;
156  }
157 
161  template<typename CLASS>
163  {
164  for (IteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
165  {
166  if ((*it)->IsType<CLASS>())
167  {
168  mProperties.erase(it);
169  return;
170  }
171  }
172  EXCEPTION("Collection does not contain the given property type.");
173  }
174 
180  void RemoveProperty(const boost::shared_ptr<AbstractCellProperty>& rProp);
181 
185  unsigned GetSize() const;
186 
191  typedef CollectionType::iterator Iterator;
192 
196  Iterator Begin();
197 
201  Iterator End();
202 
207  boost::shared_ptr<AbstractCellProperty> GetProperty() const;
208 
213  template<typename CLASS>
215  {
216  CellPropertyCollection result;
217  for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
218  {
219  if ((*it)->IsType<CLASS>())
220  {
221  result.AddProperty(*it);
222  }
223  }
224  return result;
225  }
226 
231  template<typename BASECLASS>
233  {
234  CellPropertyCollection result;
235  for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
236  {
237  if ((*it)->IsSubType<BASECLASS>())
238  {
239  result.AddProperty(*it);
240  }
241  }
242  return result;
243  }
244 };
245 
246 #endif /* CELLPROPERTYCOLLECTION_HPP_ */
friend class boost::serialization::access
CollectionType::iterator IteratorType
CollectionType::iterator Iterator
std::set< boost::shared_ptr< AbstractCellProperty > > CollectionType
boost::shared_ptr< AbstractCellProperty > GetProperty() const
#define EXCEPTION(message)
Definition: Exception.hpp:143
CellPropertyRegistry * mpCellPropertyRegistry
CellPropertyCollection GetPropertiesType() const
CellPropertyCollection GetProperties() const
CollectionType::const_iterator ConstIteratorType
void SetCellPropertyRegistry(CellPropertyRegistry *pRegistry)
void AddProperty(const boost::shared_ptr< AbstractCellProperty > &rProp)
CellPropertyRegistry * GetCellPropertyRegistry()
void serialize(Archive &archive, const unsigned int version)