File: ContextSet.cpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (35 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (3)
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
35
#include "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;
}