Cell.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 CELL_HPP_
00029 #define CELL_HPP_
00030 
00031 #include <boost/utility.hpp>
00032 #include <boost/shared_ptr.hpp>
00033 #include <boost/enable_shared_from_this.hpp>
00034 
00035 #include "ChasteSerialization.hpp"
00036 #include <boost/serialization/shared_ptr.hpp>
00037 
00038 #include "CellProliferativeTypes.hpp"
00039 #include "AbstractCellMutationState.hpp"
00040 #include "CellLabel.hpp"
00041 #include "ApoptoticCellProperty.hpp"
00042 #include "AbstractCellCycleModel.hpp"
00043 #include "SimulationTime.hpp"
00044 #include "CellPropertyRegistry.hpp"
00045 #include "CellPropertyCollection.hpp"
00046 
00047 class AbstractCellCycleModel; // Circular definition (cells need to know about cycle models and vice-versa).
00048 
00049 class Cell;
00050 
00052 typedef boost::shared_ptr<Cell> CellPtr;
00053 
00061 class Cell : boost::noncopyable, public boost::enable_shared_from_this<Cell>
00062 {
00063 private:
00064 
00066     bool mCanDivide;
00067 
00069     friend class boost::serialization::access;
00076     template<class Archive>
00077     void serialize(Archive & archive, const unsigned int version)
00078     {
00079         // If Archive is an output archive, then '&' resolves to '<<'
00080         // If Archive is an input archive, then '&' resolves to '>>'
00081         // These first four are also dealt with by {load,save}_construct_data
00082         archive & mCanDivide;
00083         archive & mpCellCycleModel;
00084         archive & mUndergoingApoptosis;
00085         archive & mDeathTime;
00086         archive & mStartOfApoptosisTime;
00087         archive & mApoptosisTime;
00088         archive & mIsDead;
00089         archive & mIsLogged;
00090         archive & mAncestor;
00091         archive & mCellId;
00092         archive & mMaxCellId;
00093     }
00094 
00095 protected:
00096 
00098     CellPropertyCollection mCellPropertyCollection;
00099 
00101     AbstractCellCycleModel* mpCellCycleModel;
00102 
00104     unsigned mAncestor;
00105 
00107     unsigned mCellId;
00108 
00110     static unsigned mMaxCellId;
00111 
00113     double mDeathTime;
00114 
00116     double mStartOfApoptosisTime;
00117 
00119     double mApoptosisTime;
00120 
00122     bool mUndergoingApoptosis;
00123 
00128     bool mIsDead;
00129 
00131     bool mIsLogged;
00132 
00133 public:
00134 
00144     Cell(boost::shared_ptr<AbstractCellProperty> pMutationState,
00145                AbstractCellCycleModel* pCellCycleModel,
00146                bool archiving=false,
00147                CellPropertyCollection cellPropertyCollection=CellPropertyCollection());
00148 
00152     ~Cell();
00153 
00159     void SetBirthTime(double birthTime);
00160 
00166     void SetCellCycleModel(AbstractCellCycleModel* pCellCycleModel);
00167 
00171     AbstractCellCycleModel* GetCellCycleModel() const;
00172 
00176     void InitialiseCellCycleModel();
00177 
00181     double GetAge() const;
00182 
00186     double GetBirthTime() const;
00187 
00191     double GetStartOfApoptosisTime() const;
00192 
00196     double GetApoptosisTime() const;
00197 
00203     void SetApoptosisTime(double apoptosisTime);
00204 
00208     boost::shared_ptr<AbstractCellMutationState> GetMutationState() const;
00209 
00215     void SetMutationState(boost::shared_ptr<AbstractCellProperty> pMutationState);
00216 
00220     CellPropertyCollection& rGetCellPropertyCollection();
00221 
00225     const CellPropertyCollection& rGetCellPropertyCollection() const;
00226 
00235     void AddCellProperty(const boost::shared_ptr<AbstractCellProperty>& rProperty);
00236 
00244     template<typename CLASS>
00245     void RemoveCellProperty()
00246     {
00247         bool cell_has_property = false;
00248 
00249         for (std::set<boost::shared_ptr<AbstractCellProperty> >::iterator property_iter = mCellPropertyCollection.Begin();
00250              property_iter != mCellPropertyCollection.End();
00251              ++property_iter)
00252         {
00253             if ((*property_iter)->IsType<CLASS>())
00254             {
00255                 cell_has_property = true;
00256                 (*property_iter)->DecrementCellCount();
00257                 break;
00258             }
00259         }
00260 
00261         if (cell_has_property)
00262         {
00263             mCellPropertyCollection.RemoveProperty<CLASS>();
00264         }
00265     }
00266 
00271     template<typename CLASS>
00272     bool HasCellProperty() const
00273     {
00274         return mCellPropertyCollection.HasProperty<CLASS>();
00275     }
00276 
00281     bool ReadyToDivide();
00282 
00289     CellPtr Divide();
00290 
00297     void StartApoptosis(bool setDeathTime=true);
00298 
00303     void Kill();
00304 
00308     bool HasApoptosisBegun() const;
00309 
00313     double GetTimeUntilDeath() const;
00314 
00318     bool IsDead();
00319 
00323     void SetLogged();
00324 
00328     bool IsLogged();
00329 
00335     void SetAncestor(unsigned ancestorIndex);
00336 
00341     unsigned GetAncestor() const;
00342 
00346     unsigned GetCellId() const;
00347 
00351     static void ResetMaxCellId();
00352 };
00353 
00354 
00355 #include "SerializationExportWrapper.hpp"
00356 CHASTE_CLASS_EXPORT(Cell)
00357 
00358 namespace boost
00359 {
00360 namespace serialization
00361 {
00365 template<class Archive>
00366 inline void save_construct_data(
00367     Archive & ar, const Cell * t, const BOOST_PFTO unsigned int file_version)
00368 {
00369     // Save data required to construct instance
00370     const boost::shared_ptr<AbstractCellMutationState> p_mutation_state = t->GetMutationState();
00371     ar & p_mutation_state;
00372 
00373     const AbstractCellCycleModel* const p_cell_cycle_model = t->GetCellCycleModel();
00374     ar & p_cell_cycle_model;
00375 
00376     const CellPropertyCollection& r_cell_property_collection = t->rGetCellPropertyCollection();
00377     ar & r_cell_property_collection;
00378 }
00379 
00383 template<class Archive>
00384 inline void load_construct_data(
00385     Archive & ar, Cell * t, const unsigned int file_version)
00386 {
00387     // Retrieve data from archive required to construct new instance
00388     boost::shared_ptr<AbstractCellMutationState> p_mutation_state;
00389     ar & p_mutation_state;
00390 
00391     AbstractCellCycleModel* p_cell_cycle_model;
00392     ar & p_cell_cycle_model;
00393 
00394     bool archiving = true;
00395 
00396     CellPropertyCollection cell_property_collection;
00397     ar & cell_property_collection;
00398 
00399     // Invoke inplace constructor to initialize instance
00400     ::new(t)Cell(p_mutation_state, p_cell_cycle_model, archiving, cell_property_collection);
00401 }
00402 }
00403 } // namespace ...
00404 
00405 #endif /*CELL_HPP_*/

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