project(latlib)
add_library(lat_configcache configcache.cpp)
-target_link_libraries(lat_configcache boost_iostreams)
+target_link_libraries(lat_configcache boost_iostreams lat_writeout)
add_library(lat_neigh neigh.cpp)
#include <time.h>
#include <dirent.h>
-configcache::configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode){
+configcache::configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode,
+ writeout *out_a){
+ out = out_a;
+
NEQUI = nequi;
NSKIP = nskip;
DATADIR = datadir;
while( (!inFile.is_open()) && inFiles.size() > 0 )
{
+ if(out) *out->log << "Opening dat-file: " << inFiles.back() << endl;
+
inFile.open( (DATADIR + "/" + inFiles.back()).c_str(), std::ios::binary );
inFiles.pop_back();
if( inFile.is_open() )
{
- if( boost::iostreams::read(*inBuffer, tmpConfig, configSize) == configSize )
+ int readturn = -1;
+ try { readturn = boost::iostreams::read(*inBuffer, tmpConfig, configSize); }
+ catch (std::exception const& ex) {
+ if(out) *out->log << "Caught exception: " << ex.what() << endl;
+ inFile.close();
+ }
+
+ if( readturn == configSize && inFile.is_open() )
{
memcpy(configMem, tmpConfig, configSize);
return true;
}
- else inFile.close();
+ else inFile.close();
}
}
}
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/copy.hpp>
+#include "writeout.h"
+
#define CACHE_MODE_DISABLED 0
#define CACHE_MODE_READ 1
#define CACHE_MODE_FULL 2
class configcache{
public:
~configcache();
- configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize, const int& cachemode=CACHE_MODE_FULL);
+ configcache(const string& cacheid, const int& nequi, const int& nskip, const string& datadir, char **configmem, const int& configMemSize,
+ const int& cachemode=CACHE_MODE_FULL, writeout *out_a=NULL);
bool readConfig();
void writeConfig();
void addPara(const string& parid, const double& val=0);
ofstream outFile;
ifstream inFile;
+ writeout *out;
+
stringstream outFileName;
int readnum;