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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#ifndef GENERS_STRINGARCHIVE_HH_
#define GENERS_STRINGARCHIVE_HH_
#include "Alignment/Geners/interface/AbsArchive.hh"
#include "Alignment/Geners/interface/CharBuffer.hh"
#include "Alignment/Geners/interface/ContiguousCatalog.hh"
namespace gs {
class StringArchive : public AbsArchive {
public:
inline StringArchive(const char *name = nullptr) : AbsArchive(name) {}
~StringArchive() override {}
inline bool isOpen() const override { return true; }
inline std::string error() const override { return std::string(""); }
inline bool isReadable() const override { return true; }
inline bool isWritable() const override { return true; }
inline unsigned long long size() const override { return catalog_.size(); }
inline unsigned long long smallestId() const override { return catalog_.smallestId(); }
inline unsigned long long largestId() const override { return catalog_.largestId(); }
inline bool idsAreContiguous() const override { return catalog_.isContiguous(); }
inline bool itemExists(const unsigned long long id) const override { return catalog_.itemExists(id); }
inline void itemSearch(const SearchSpecifier &namePattern,
const SearchSpecifier &categoryPattern,
std::vector<unsigned long long> *idsFound) const override {
catalog_.search(namePattern, categoryPattern, idsFound);
}
inline std::shared_ptr<const CatalogEntry> catalogEntry(const unsigned long long id) override {
return catalog_.retrieveEntry(id);
}
inline void flush() override { stream_.flush(); }
inline std::string str() const { return static_cast<const std::stringbuf *>(stream_.rdbuf())->str(); }
// The following operation is equivalent to but much more efficient
// than calling str() and finding out the size of the obtained string
inline unsigned long dataSize() const { return stream_.size(); }
// Methods related to I/O
inline ClassId classId() const { return ClassId(*this); }
bool write(std::ostream &of) const;
static inline const char *classname() { return "gs::StringArchive"; }
static inline unsigned version() { return 1; }
// Can't have "restore" function: no default constructor.
// Note that lastItemId() and lastItemLength() methods
// of the parent class will return 0 when the archive is
// read back from a stream and nothing has been inserted
// into it yet.
static StringArchive *read(const ClassId &id, std::istream &in);
protected:
bool isEqual(const AbsArchive &) const override;
private:
void search(AbsReference &reference) override;
std::istream &inputStream(unsigned long long id, long long *sz) override;
inline std::ostream &outputStream() override {
lastpos_ = stream_.tellp();
return stream_;
}
inline unsigned long long addToCatalog(const AbsRecord &record,
const unsigned compressCode,
const unsigned long long itemLength) override {
return catalog_.makeEntry(record, compressCode, itemLength, ItemLocation(lastpos_, nullptr));
}
CharBuffer stream_;
std::streampos lastpos_;
ContiguousCatalog catalog_;
};
} // namespace gs
#endif // GENERS_STRINGARCHIVE_HH_
|