CellPropertyRegistry.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 CELLPROPERTYREGISTRY_HPP_
00030 #define CELLPROPERTYREGISTRY_HPP_
00031 
00032 #include <boost/shared_ptr.hpp>
00033 #include <vector>
00034 
00035 #include "AbstractCellProperty.hpp"
00036 #include "Exception.hpp"
00037 
00038 #include "ChasteSerialization.hpp"
00039 #include <boost/serialization/shared_ptr.hpp>
00040 #include <boost/serialization/vector.hpp>
00041 
00045 class CellPropertyRegistry
00046 {
00047 public:
00054     template<class SUBCLASS>
00055     boost::shared_ptr<AbstractCellProperty> Get();
00056 
00060     static CellPropertyRegistry* Instance();
00061 
00065     const std::vector<boost::shared_ptr<AbstractCellProperty> >& rGetAllCellProperties();
00066 
00070     void Clear();
00071 
00080     CellPropertyRegistry* TakeOwnership();
00081 
00090     void SpecifyOrdering(const std::vector<boost::shared_ptr<AbstractCellProperty> >& rOrdering);
00091 
00095     bool HasOrderingBeenSpecified();
00096 
00097 private:
00098 
00102     CellPropertyRegistry();
00103 
00107     CellPropertyRegistry(const CellPropertyRegistry&);
00108 
00112     CellPropertyRegistry& operator= (const CellPropertyRegistry&);
00113 
00117     static CellPropertyRegistry* mpInstance;
00118 
00122     std::vector<boost::shared_ptr<AbstractCellProperty> > mCellProperties;
00123 
00125     bool mOrderingHasBeenSpecified;
00126 
00128     friend class boost::serialization::access;
00135     template<class Archive>
00136     void serialize(Archive & archive, const unsigned int version)
00137     {
00138         archive & mCellProperties;
00139         archive & mOrderingHasBeenSpecified;
00140     }
00141 };
00142 
00143 template<class SUBCLASS>
00144 boost::shared_ptr<AbstractCellProperty> CellPropertyRegistry::Get()
00145 {
00146     boost::shared_ptr<AbstractCellProperty> p_property;
00147     for (unsigned i=0; i<mCellProperties.size(); i++)
00148     {
00149         if (mCellProperties[i]->IsType<SUBCLASS>())
00150         {
00151             p_property = mCellProperties[i];
00152             break;
00153         }
00154     }
00155     if (!p_property)
00156     {
00157         // Create a new cell property
00158         p_property.reset(new SUBCLASS);
00159         mCellProperties.push_back(p_property);
00160     }
00161     return p_property;
00162 }
00163 
00164 #endif /* CELLPROPERTYREGISTRY_HPP_ */

Generated on Mon Apr 18 11:35:27 2011 for Chaste by  doxygen 1.5.5