Cell.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 
00262         if (cell_has_property)
00263         {
00264             mCellPropertyCollection.RemoveProperty<CLASS>();
00265         }
00266     }
00267 
00272     template<typename CLASS>
00273     bool HasCellProperty() const
00274     {
00275         return mCellPropertyCollection.HasProperty<CLASS>();
00276     }
00277 
00282     bool ReadyToDivide();
00283 
00290     CellPtr Divide();
00291 
00298     void StartApoptosis(bool setDeathTime=true);
00299 
00304     void Kill();
00305 
00309     bool HasApoptosisBegun() const;
00310 
00314     double GetTimeUntilDeath() const;
00315 
00319     bool IsDead();
00320 
00324     void SetLogged();
00325 
00329     bool IsLogged();
00330 
00336     void SetAncestor(unsigned ancestorIndex);
00337 
00342     unsigned GetAncestor() const;
00343 
00347     unsigned GetCellId() const;
00348 
00352     static void ResetMaxCellId();
00353 };
00354 
00355 
00356 #include "SerializationExportWrapper.hpp"
00357 CHASTE_CLASS_EXPORT(Cell)
00358 
00359 namespace boost
00360 {
00361 namespace serialization
00362 {
00366 template<class Archive>
00367 inline void save_construct_data(
00368     Archive & ar, const Cell * t, const BOOST_PFTO unsigned int file_version)
00369 {
00370     // Save data required to construct instance
00371     const boost::shared_ptr<AbstractCellMutationState> p_mutation_state = t->GetMutationState();
00372     ar & p_mutation_state;
00373 
00374     const AbstractCellCycleModel* const p_cell_cycle_model = t->GetCellCycleModel();
00375     ar & p_cell_cycle_model;
00376 
00377     const CellPropertyCollection& r_cell_property_collection = t->rGetCellPropertyCollection();
00378     ar & r_cell_property_collection;
00379 }
00380 
00384 template<class Archive>
00385 inline void load_construct_data(
00386     Archive & ar, Cell * t, const unsigned int file_version)
00387 {
00388     // Retrieve data from archive required to construct new instance
00389     boost::shared_ptr<AbstractCellMutationState> p_mutation_state;
00390     ar & p_mutation_state;
00391 
00392     AbstractCellCycleModel* p_cell_cycle_model;
00393     ar & p_cell_cycle_model;
00394 
00395     bool archiving = true;
00396 
00397     CellPropertyCollection cell_property_collection;
00398     ar & cell_property_collection;
00399 
00400     // Invoke inplace constructor to initialize instance
00401     ::new(t)Cell(p_mutation_state, p_cell_cycle_model, archiving, cell_property_collection);
00402 }
00403 }
00404 } // namespace ...
00405 
00406 #endif /*CELL_HPP_*/

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5