1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <alignment/simulator/ContextSet.hpp>
ContextSampleMap::ContextSampleMap() { contextLength = 0; }
void ContextSampleMap::Write(std::ofstream &out)
{
T_ContextSampleMap::iterator mapIt, mapEnd;
int mapSize = this->size();
out.write((char *)&contextLength, sizeof(contextLength));
out.write((char *)&mapSize, sizeof(mapSize));
mapEnd = this->end();
for (mapIt = this->begin(); mapIt != mapEnd; ++mapIt) {
out.write(mapIt->first.c_str(), contextLength);
mapIt->second->Write(out);
}
}
void ContextSampleMap::Read(std::ifstream &in)
{
in.read((char *)&contextLength, sizeof(contextLength));
int numContext;
in.read((char *)&numContext, sizeof(numContext));
int i;
char *context = ProtectedNew<char>(contextLength + 1);
context[contextLength] = '\0';
for (i = 0; i < numContext; i++) {
in.read(context, contextLength);
std::string contextString = context;
// Allocate the context
(*this)[contextString] = ProtectedNew<ContextSample>();
(*this)[contextString]->Read(in);
}
delete[] context;
}
|