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 
00029 #ifndef CELLPROPERTYCOLLECTION_HPP_
00030 #define CELLPROPERTYCOLLECTION_HPP_
00031 
00032 #include <set>
00033 #include <boost/shared_ptr.hpp>
00034 
00035 #include "ChasteSerialization.hpp"
00036 #include <boost/serialization/shared_ptr.hpp>
00037 #include <boost/serialization/set.hpp>
00038 
00039 #include "AbstractCellProperty.hpp"
00040 #include "CellPropertyRegistry.hpp"
00041 #include "Exception.hpp"
00042 
00048 class CellPropertyCollection
00049 {
00050 private:
00052     typedef std::set<boost::shared_ptr<AbstractCellProperty> > CollectionType;
00053 
00055     typedef CollectionType::const_iterator ConstIteratorType;
00056 
00058     typedef CollectionType::iterator IteratorType;
00059 
00061     CollectionType mProperties;
00062 
00064     CellPropertyRegistry* mpCellPropertyRegistry;
00065 
00067     friend class boost::serialization::access;
00074     template<class Archive>
00075     void serialize(Archive & archive, const unsigned int version)
00076     {
00077         archive & mProperties;
00078         // archive & mpCellPropertyRegistry; Not required as archived by the CellPopulation.
00079     }
00080 
00081 public:
00085     CellPropertyCollection();
00086 
00092     void AddProperty(const boost::shared_ptr<AbstractCellProperty>& rProp);
00093 
00097     CellPropertyRegistry* GetCellPropertyRegistry();
00098 
00104     void SetCellPropertyRegistry(CellPropertyRegistry* pRegistry);
00105 
00111     bool HasProperty(const boost::shared_ptr<AbstractCellProperty>& rProp) const;
00112 
00119     template<typename CLASS>
00120     bool HasProperty() const
00121     {
00122         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00123         {
00124             if ((*it)->IsType<CLASS>())
00125             {
00126                 return true;
00127             }
00128         }
00129         return false;
00130     }
00131 
00138     template<typename BASECLASS>
00139     bool HasPropertyType() const
00140     {
00141         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00142         {
00143             if ((*it)->IsSubType<BASECLASS>())
00144             {
00145                 return true;
00146             }
00147         }
00148         return false;
00149     }
00150 
00154     template<typename CLASS>
00155     void RemoveProperty()
00156     {
00157         for (IteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00158         {
00159             if ((*it)->IsType<CLASS>())
00160             {
00161                 mProperties.erase(it);
00162                 return;
00163             }
00164         }
00165         EXCEPTION("Collection does not contain the given property type.");
00166     }
00167 
00173     void RemoveProperty(const boost::shared_ptr<AbstractCellProperty>& rProp);
00174 
00178     unsigned GetSize() const;
00179 
00184     typedef CollectionType::iterator Iterator;
00185 
00189     Iterator Begin();
00190 
00194     Iterator End();
00195 
00200     boost::shared_ptr<AbstractCellProperty> GetProperty() const;
00201 
00206     template<typename CLASS>
00207     CellPropertyCollection GetProperties() const
00208     {
00209         CellPropertyCollection result;
00210         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00211         {
00212             if ((*it)->IsType<CLASS>())
00213             {
00214                 result.AddProperty(*it);
00215             }
00216         }
00217         return result;
00218     }
00219 
00224     template<typename BASECLASS>
00225     CellPropertyCollection GetPropertiesType() const
00226     {
00227         CellPropertyCollection result;
00228         for (ConstIteratorType it = mProperties.begin(); it != mProperties.end(); ++it)
00229         {
00230             if ((*it)->IsSubType<BASECLASS>())
00231             {
00232                 result.AddProperty(*it);
00233             }
00234         }
00235         return result;
00236     }
00237 };
00238 
00239 #endif /* CELLPROPERTYCOLLECTION_HPP_ */
Generated on Thu Dec 22 13:00:04 2011 for Chaste by  doxygen 1.6.3