]> git.treefish.org Git - phys/latlib.git/blobdiff - configcache.cpp
added support for using excluded config-files for equilibration.
[phys/latlib.git] / configcache.cpp
index d45e4d661552340960c5cbb09d9cae4fcd7f23a8..6cd46a179a2772792ba5bc2caf202ec1fb5dbe98 100644 (file)
@@ -186,28 +186,17 @@ int configcache::readConfig(vector<unsigned long> *excludeFileHashes)
 
   while(true)
     {
-      if( (!inFile.is_open()) && inFiles.size() == 0 ) return nequileft;
+      vector<infiledesc>::iterator inFileIt = getNextInfile(excludeFileHashes);
 
-      while( (!inFile.is_open()) && inFiles.size() > 0 ) {
-       bool excludethisfile=false;
+      if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return nequileft;
 
-       openFileDesc = inFiles.back();
+      while( (!inFile.is_open()) && inFiles.size() > 0 ) {
+       openFileDesc = *inFileIt;
 
-       if (excludeFileHashes != NULL)
-         for (vector<unsigned long>::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit)
-           if ( *exit == hash(inFiles.back().filename) ) {
-             excludethisfile = true;
-             break;
-           }
-             
-       if ( ! excludethisfile ) {
-         if(log) *log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush;
-         inFile.open( (DATADIR + "/" + inFiles.back().filename).c_str(), std::ios::binary );
-       }
-       else
-         if(log) *log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush;
+       if(log) *log << "CCACHE: Opening dat-file: " << inFileIt->filename << endl << flush;
+       inFile.open( (DATADIR + "/" + inFileIt->filename).c_str(), std::ios::binary );
        
-       inFiles.pop_back();
+       inFiles.erase(inFileIt);
        
        if( !inFile.is_open() ) continue;
 
@@ -382,3 +371,22 @@ void configcache::deleteHeaderStore()
     headerStore.pop_back();
   }
 }
+
+vector<infiledesc>::iterator configcache::getNextInfile(vector<unsigned long> *excludeFileHashes) {
+  for (vector<infiledesc>::iterator init = inFiles.begin(); init != inFiles.end(); ++init) {
+    if (excludeFileHashes != NULL) {
+      bool excludethisfile = false;
+
+      for (vector<unsigned long>::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit)
+       if ( *exit == hash(init->filename) ) {
+         excludethisfile = true;
+         break;
+       }
+
+      if (excludethisfile)
+       continue;
+    }
+    return init;
+  }
+  return inFiles.end();
+}