Chaste Commit::8b5d759ac2eb95e67ae57699734101efccb0a0a9
CellPropertyCollection.hpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
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{
57private:
59 typedef std::set<boost::shared_ptr<AbstractCellProperty> > CollectionType;
60
62 typedef CollectionType::const_iterator ConstIteratorType;
63
65 typedef CollectionType::iterator IteratorType;
66
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
88public:
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 {
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 {
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_ */
#define EXCEPTION(message)
CollectionType::const_iterator ConstIteratorType
void serialize(Archive &archive, const unsigned int version)
boost::shared_ptr< AbstractCellProperty > GetProperty() const
CellPropertyCollection GetProperties() const
CollectionType::iterator Iterator
CollectionType::iterator IteratorType
CellPropertyCollection GetPropertiesType() const
std::set< boost::shared_ptr< AbstractCellProperty > > CollectionType
CellPropertyRegistry * mpCellPropertyRegistry
void AddProperty(const boost::shared_ptr< AbstractCellProperty > &rProp)
friend class boost::serialization::access
void SetCellPropertyRegistry(CellPropertyRegistry *pRegistry)
CellPropertyRegistry * GetCellPropertyRegistry()