--- trunk/OOPSE-4/src/brains/BlockSnapshotManager.hpp 2005/02/13 08:05:33 2006 +++ trunk/OOPSE-4/src/brains/BlockSnapshotManager.hpp 2005/04/15 22:04:00 2204 @@ -40,72 +40,86 @@ */ #ifndef BRAINS_BLOCKSNAPSHOTMANAGER_HPP #define BRAINS_BLOCKSNAPSHOTMANAGER_HPP +#include #include "brains/SnapshotManager.hpp" namespace oopse { -class SimInfo; -class DumpReader; + class SimInfo; + class DumpReader; -typedef std::pair SnapshotBlock; + typedef std::pair SnapshotBlock; -/** - * @class BlockSnapshotManager - * @todo document - */ -class BlockSnapshotMananger : public SnapshotManager{ + /** + * @class BlockSnapshotManager + * @todo document + */ + class BlockSnapshotManager : public SnapshotManager{ - public: - BlockSnapshotMananger(SimInfo* info, const std::string& filename, int storageLayout, int blockCapacity = 2); - ~BlockSnapshotMananger(); + public: + BlockSnapshotManager(SimInfo* info, const std::string& filename, int storageLayout, int blockCapacity = 2); + ~BlockSnapshotManager(); - virtual Snapshot* getSnapshot(int id); + virtual Snapshot* getSnapshot(int id) { return snapshots_[id]; } - /** Returns number of snapshot blocks in this BlockSnapshotManager*/ - int getNBlocks() { - return blocks_.size(); - } + /** Returns number of snapshot blocks in this BlockSnapshotManager*/ + int getNBlocks() { + return blocks_.size(); + } - SnapshotBlock getSnapshotBlock(int block) { - return blocks_.at(block); - } + SnapshotBlock getSnapshotBlock(int block) { + return blocks_.at(block); + } - int getNActiveBlocks(); + int getNActiveBlocks(); - bool isBlockActive(int block); + + bool isBlockActive(int block) { + return findActiveBlock(block) != activeBlocks_.end() ? true : false; + } + + bool loadBlock(int block); - bool loadBlock(int block); - - bool unloadBlock(int block); + bool unloadBlock(int block); - std::vector getActiveBlocks(); + std::vector getActiveBlocks(); - int getBlockCapacity() { - return blockCapacity_; - } + int getBlockCapacity() { + return blockCapacity_; + } - int getNFrames(); + int getNFrames(); - private: + private: - Snapshot* loadFrame(int frame); + std::vector::iterator findActiveBlock(int block) { + return std::find(activeBlocks_.begin(), activeBlocks_.end(), block); + } + + bool hasZeroRefBlock(); + + int getFirstZeroRefBlock(); + + void internalLoad(int block); + void internalUnload(int block); + Snapshot* loadFrame(int frame); - SimInfo* info_; - int storageLayout_; - int blockCapacity_; + SimInfo* info_; + int blockCapacity_; - std::vector snapshots_; - std::vector blocks_; - std::vector activeBlocks_; + std::vector snapshots_; + std::vector blocks_; + std::vector activeBlocks_; + std::vector activeRefCount_; - int nAtoms_; - int nRigidBodies_; + int nAtoms_; + int nRigidBodies_; - DumpReader* reader_; - int nframes_; - int nSnapshotPerBlock_; + DumpReader* reader_; + int nframes_; + int nSnapshotPerBlock_; -}; + }; }