CellPropertyCollection.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 #ifndef CELLPROPERTYCOLLECTION_HPP_
00029 #define CELLPROPERTYCOLLECTION_HPP_
00030 
00031 #include <set>
00032 #include <boost/shared_ptr.hpp>
00033 
00034 #include "ChasteSerialization.hpp"
00035 #include <boost/serialization/shared_ptr.hpp>
00036 #include <boost/serialization/set.hpp>
00037 
00038 #include "AbstractCellProperty.hpp"
00039 #include "CellPropertyRegistry.hpp"
00040 #include "Exception.hpp"
00041 
00047 class CellPropertyCollection
00048 {
00049 private:
00051     typedef std::set<boost::shared_ptr<AbstractCellProperty> > CollectionType;
00052 
00054     typedef CollectionType::const_iterator ConstIteratorType;
00055 
00057     typedef CollectionType::iterator IteratorType;
00058 
00060     CollectionType mProperties;
00061 
00063     CellPropertyRegistry* mpCellPropertyRegistry;
00064 
00066     friend class boost::serialization::access;
00073     template<class Archive>
00074     void serialize(Archive & archive, const unsigned int version)
00075     {
00076         // If Archive is an output archive, then '&' resolves to '<<'
00077         // If Archive is an input archive, then '&' resolves to '>>'
00078         archive & mProperties;
00079         // archive & mpCellPropertyRegistry; Not required as archived by the CellPopulation.
00080     }
00081 
00082 public:
00086     CellPropertyCollection();
00087 
00093     void AddProperty(const boost::shared_ptr<AbstractCellProperty>& rProp);
00094 
00098     CellPropertyRegistry* GetCellPropertyRegistry();
00099 
00105     void SetCellPropertyRegistry(CellPropertyRegistry* pRegistry);
00106 
00112     bool HasProperty(const boost::shared_ptr<AbstractCellProperty>& rProp) const;
00113 
00120     template<typename CLASS>
00121     bool HasProperty() const
00122     {
00123         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00124         {
00125             if ((*it)->IsType<CLASS>())
00126             {
00127                 return true;
00128             }
00129         }
00130         return false;
00131     }
00132 
00139     template<typename BASECLASS>
00140     bool HasPropertyType() const
00141     {
00142         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00143         {
00144             if ((*it)->IsSubType<BASECLASS>())
00145             {
00146                 return true;
00147             }
00148         }
00149         return false;
00150     }
00151 
00155     template<typename CLASS>
00156     void RemoveProperty()
00157     {
00158         for (IteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00159         {
00160             if ((*it)->IsType<CLASS>())
00161             {
00162                 mProperties.erase(it);
00163                 return;
00164             }
00165         }
00166         EXCEPTION("Collection does not contain the given property type.");
00167     }
00168 
00174     void RemoveProperty(const boost::shared_ptr<AbstractCellProperty>& rProp);
00175     
00179     unsigned GetSize() const;
00180     
00185     typedef CollectionType::iterator Iterator;
00186     
00190     Iterator Begin();
00191     
00195     Iterator End();
00196     
00201     boost::shared_ptr<AbstractCellProperty> GetProperty() const;
00202     
00207     template<typename CLASS>
00208     CellPropertyCollection GetProperties() const
00209     {
00210         CellPropertyCollection result;
00211         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00212         {
00213             if ((*it)->IsType<CLASS>())
00214             {
00215                 result.AddProperty(*it);
00216             }
00217         }
00218         return result;
00219     }
00220     
00225     template<typename BASECLASS>
00226     CellPropertyCollection GetPropertiesType() const
00227     {
00228         CellPropertyCollection result;
00229         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00230         {
00231             if ((*it)->IsSubType<BASECLASS>())
00232             {
00233                 result.AddProperty(*it);
00234             }
00235         }
00236         return result;
00237     }
00238 };
00239 
00240 #endif /* CELLPROPERTYCOLLECTION_HPP_ */

Generated on Tue May 31 14:31:40 2011 for Chaste by  doxygen 1.5.5