File: ContextSet.cpp

package info (click to toggle)
pbseqlib 5.3.1%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,136 kB
  • sloc: cpp: 77,246; python: 570; makefile: 312; sh: 111; ansic: 9
file content (34 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (4)
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;
}