ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/brains/BlockSnapshotManager.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/brains/BlockSnapshotManager.cpp (file contents):
Revision 2007 by tim, Sun Feb 13 15:56:10 2005 UTC vs.
Revision 2031 by tim, Tue Feb 15 17:11:35 2005 UTC

# Line 41 | Line 41
41   #include <algorithm>
42   #include "brains/BlockSnapshotManager.hpp"
43   #include "utils/physmem.h"
44 + #include "utils/Algorithm.hpp"
45   #include "brains/SimInfo.hpp"
46   #include "io/DumpReader.hpp"
47  
48   namespace oopse {
49 < BlockSnapshotMananger::BlockSnapshotMananger(SimInfo* info, const std::string& filename,
49 > BlockSnapshotManager::BlockSnapshotManager(SimInfo* info, const std::string& filename,
50      int storageLayout, int blockCapacity)
51      : SnapshotManager(storageLayout), info_(info), blockCapacity_(blockCapacity), activeBlocks_(blockCapacity_, -1) {
52  
# Line 71 | Line 72 | BlockSnapshotMananger::BlockSnapshotMananger(SimInfo*
72      }  
73      
74      for (int i = 0; i < nblocks; ++i) {
75 <        blocks_.push_back(SnapshotBlock(i, (i+1)*nSnapshotPerBlock_);    
75 >        blocks_.push_back(SnapshotBlock(i*nSnapshotPerBlock_, (i+1)*nSnapshotPerBlock_));    
76      }
77      //the last block may not have nSnapshotPerBlock frames, we need to consider this special situation
78 <    blocks_.back.second = nframes_;
78 >    blocks_.back().second = nframes_;
79  
80 <    snapshots_.insert(snapshots_.begin(), nframes_, NULL);  
80 >    snapshots_.insert(snapshots_.begin(), nframes_, static_cast<Snapshot*>(NULL));  
81      
82   }
83  
84  
85 < BlockSnapshotMananger::~BlockSnapshotMananger() {
85 > BlockSnapshotManager::~BlockSnapshotManager() {
86      currentSnapshot_ = NULL;
87      previousSnapshot_ = NULL;
88      
89      delete reader_;
90 <    std::for_each(activeBlocks_.begin(), activeBlocks_.end(), unloadBlock);
90 >
91 >    std::vector<int>::iterator i;
92 >    for (i = activeBlocks_.begin(); i != activeBlocks_.end(); ++i) {
93 >        if (*i != -1) {
94 >            unloadBlock(*i);
95 >        }
96 >    }
97   }
98  
99   int BlockSnapshotManager::getNActiveBlocks() {
100 <    return std::count_if(activeBlocks_.begin(), activeBlocks_.end(), std::not);
100 > #ifdef __RWSTD  
101 >    int count = 0;
102 >    std::count_if(activeBlocks_.begin(), activeBlocks_.end(), std::bind2nd(std::not_equal_to<int>(), -1), count);
103 >    return count;
104 > #else
105 >    return std::count_if(activeBlocks_.begin(), activeBlocks_.end(), std::bind2nd(std::not_equal_to<int>(), -1));
106 > #endif
107   }
108  
109   bool BlockSnapshotManager::isBlockActive(int block) {
# Line 132 | Line 145 | bool BlockSnapshotManager::unloadBlock(int block) {
145          j = std::find(activeBlocks_.begin(), activeBlocks_.end(), block);
146          assert(j != activeBlocks_.end());
147          *j = -1;
148 +        unloadSuccess = true;
149      }
150 +
151 +    return unloadSuccess;
152   }
153  
154   std::vector<int> BlockSnapshotManager::getActiveBlocks() {
155      std::vector<int> result;
156 <    std::copy_if(activeBlocks_.begin(), activeBlocks_.end());
156 >    oopse::copy_if(activeBlocks_.begin(), activeBlocks_.end(), std::back_inserter(result),
157 >        std::bind2nd(std::not_equal_to<int>(), -1));
158 >    return result;    
159   }
160  
161   Snapshot* BlockSnapshotManager::loadFrame(int frame){
162      Snapshot* snapshot = new Snapshot(nAtoms_, nRigidBodies_, getStorageLayout());
163      snapshot->setID(frame);
164 <    setCurrentSnapshot(snapshot);   /** @todo fixed me */
164 >    
165 >    /** @todo fixed me */
166 >    Snapshot* oldSnapshot = currentSnapshot_;
167 >    currentSnapshot_ = snapshot;  
168      reader_->readFrame(frame);
169 +    currentSnapshot_ = oldSnapshot;
170      return snapshot;
171   }
172  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines