/* * LinkedCell_Model_LinkedCellArrayCache.hpp * * Created on: Dec 20, 2011 * Author: heber */ #ifndef LINKEDCELL_MODEL_LINKEDCELLARRAYCACHE_HPP_ #define LINKEDCELL_MODEL_LINKEDCELLARRAYCACHE_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include "CodePatterns/Cacheable.hpp" #include "LinkedCell_Model.hpp" #include "types.hpp" namespace LinkedCell { /** This class is used to separate reading from writing access. * * Write operations are stored and perform first (lazily) when the next read * operation requires a fully update instance. * */ class LinkedCell_Model::LinkedCellArrayCache { //!> grant LinkedCell_Model access to N for its write operations. friend class LinkedCell_Model; //!> grant access to model's unit test (to externally allow for update before checking internals) friend class ::LinkedCell_ModelTest; public: LinkedCellArrayCache( Observable *_observable, boost::function _updatefunction, const std::string _name); ~LinkedCellArrayCache(); const LinkedCellArray &getN() const; /** Internal update function for Cacheable UpToDate. * * @return true after updatefunction was called. */ bool updateMe() { updatefunction(); return true; } private: LinkedCellArray &setN(); //!> update function boost::function updatefunction; /** Pseudo variable to use the Cacheable pattern. * * We cannot use a complex variable for this due the cost of the cstor * involved as the update always returns the updated structure */ Cacheable UpToDate; //!> Linked cell array cache LinkedCellArray N; }; } // namespace LinkedCell #endif /* LINKEDCELL_MODEL_LINKEDCELLARRAYCACHE_HPP_ */