Chaste Release::3.1
|
00001 /* 00002 00003 Copyright (c) 2005-2012, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 */ 00035 00036 #ifndef CELLPROPERTYCOLLECTION_HPP_ 00037 #define CELLPROPERTYCOLLECTION_HPP_ 00038 00039 #include <set> 00040 #include <boost/shared_ptr.hpp> 00041 00042 #include "ChasteSerialization.hpp" 00043 #include <boost/serialization/shared_ptr.hpp> 00044 #include <boost/serialization/set.hpp> 00045 00046 #include "AbstractCellProperty.hpp" 00047 #include "CellPropertyRegistry.hpp" 00048 #include "Exception.hpp" 00049 00055 class CellPropertyCollection 00056 { 00057 private: 00059 typedef std::set<boost::shared_ptr<AbstractCellProperty> > CollectionType; 00060 00062 typedef CollectionType::const_iterator ConstIteratorType; 00063 00065 typedef CollectionType::iterator IteratorType; 00066 00068 CollectionType mProperties; 00069 00071 CellPropertyRegistry* mpCellPropertyRegistry; 00072 00074 friend class boost::serialization::access; 00081 template<class Archive> 00082 void serialize(Archive & archive, const unsigned int version) 00083 { 00084 archive & mProperties; 00085 // archive & mpCellPropertyRegistry; Not required as archived by the CellPopulation. 00086 } 00087 00088 public: 00092 CellPropertyCollection(); 00093 00099 void AddProperty(const boost::shared_ptr<AbstractCellProperty>& rProp); 00100 00104 CellPropertyRegistry* GetCellPropertyRegistry(); 00105 00111 void SetCellPropertyRegistry(CellPropertyRegistry* pRegistry); 00112 00118 bool HasProperty(const boost::shared_ptr<AbstractCellProperty>& rProp) const; 00119 00126 template<typename CLASS> 00127 bool HasProperty() const 00128 { 00129 for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it) 00130 { 00131 if ((*it)->IsType<CLASS>()) 00132 { 00133 return true; 00134 } 00135 } 00136 return false; 00137 } 00138 00145 template<typename BASECLASS> 00146 bool HasPropertyType() const 00147 { 00148 for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it) 00149 { 00150 if ((*it)->IsSubType<BASECLASS>()) 00151 { 00152 return true; 00153 } 00154 } 00155 return false; 00156 } 00157 00161 template<typename CLASS> 00162 void RemoveProperty() 00163 { 00164 for (IteratorType it = mProperties.begin(); it != mProperties.end(); ++it) 00165 { 00166 if ((*it)->IsType<CLASS>()) 00167 { 00168 mProperties.erase(it); 00169 return; 00170 } 00171 } 00172 EXCEPTION("Collection does not contain the given property type."); 00173 } 00174 00180 void RemoveProperty(const boost::shared_ptr<AbstractCellProperty>& rProp); 00181 00185 unsigned GetSize() const; 00186 00191 typedef CollectionType::iterator Iterator; 00192 00196 Iterator Begin(); 00197 00201 Iterator End(); 00202 00207 boost::shared_ptr<AbstractCellProperty> GetProperty() const; 00208 00213 template<typename CLASS> 00214 CellPropertyCollection GetProperties() const 00215 { 00216 CellPropertyCollection result; 00217 for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it) 00218 { 00219 if ((*it)->IsType<CLASS>()) 00220 { 00221 result.AddProperty(*it); 00222 } 00223 } 00224 return result; 00225 } 00226 00231 template<typename BASECLASS> 00232 CellPropertyCollection GetPropertiesType() const 00233 { 00234 CellPropertyCollection result; 00235 for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it) 00236 { 00237 if ((*it)->IsSubType<BASECLASS>()) 00238 { 00239 result.AddProperty(*it); 00240 } 00241 } 00242 return result; 00243 } 00244 }; 00245 00246 #endif /* CELLPROPERTYCOLLECTION_HPP_ */