/usr/include/dawgdic/guide.h is in libdawgdic-dev 0.4.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | #ifndef DAWGDIC_GUIDE_H
#define DAWGDIC_GUIDE_H
#include "dictionary.h"
#include "guide-unit.h"
#include <iostream>
#include <vector>
namespace dawgdic {
class Guide {
public:
Guide() : units_(NULL), size_(0), units_buf_() {}
const GuideUnit *units() const {
return units_;
}
SizeType size() const {
return size_;
}
SizeType total_size() const {
return sizeof(GuideUnit) * size_;
}
SizeType file_size() const {
return sizeof(BaseType) + total_size();
}
// The root index.
BaseType root() const {
return 0;
}
UCharType child(BaseType index) const {
return units_[index].child();
}
UCharType sibling(BaseType index) const {
return units_[index].sibling();
}
// Reads a dictionary from an input stream.
bool Read(std::istream *input) {
BaseType base_size;
if (!input->read(reinterpret_cast<char *>(&base_size), sizeof(BaseType))) {
return false;
}
SizeType size = static_cast<SizeType>(base_size);
std::vector<GuideUnit> units_buf(size);
if (!input->read(reinterpret_cast<char *>(&units_buf[0]),
sizeof(GuideUnit) * size)) {
return false;
}
SwapUnitsBuf(&units_buf);
return true;
}
// Writes a dictionry to an output stream.
bool Write(std::ostream *output) const {
BaseType base_size = static_cast<BaseType>(size_);
if (!output->write(reinterpret_cast<const char *>(&base_size),
sizeof(BaseType))) {
return false;
}
if (!output->write(reinterpret_cast<const char *>(units_),
sizeof(GuideUnit) * size_)) {
return false;
}
return true;
}
// Maps memory with its size.
void Map(const void *address) {
Clear();
units_ = reinterpret_cast<const GuideUnit *>(
static_cast<const BaseType *>(address) + 1);
size_ = *static_cast<const BaseType *>(address);
}
void Map(const void *address, SizeType size) {
Clear();
units_ = static_cast<const GuideUnit *>(address);
size_ = size;
}
// Swaps Guides.
void Swap(Guide *guide) {
std::swap(units_, guide->units_);
std::swap(size_, guide->size_);
units_buf_.swap(guide->units_buf_);
}
// Initializes a Guide.
void Clear() {
units_ = NULL;
size_ = 0;
std::vector<GuideUnit>(0).swap(units_buf_);
}
public:
// Following member function is called from DawgBuilder.
// Swaps buffers for units.
void SwapUnitsBuf(std::vector<GuideUnit> *units_buf) {
units_ = &(*units_buf)[0];
size_ = static_cast<BaseType>(units_buf->size());
units_buf_.swap(*units_buf);
}
private:
const GuideUnit *units_;
SizeType size_;
std::vector<GuideUnit> units_buf_;
// Disables copies.
Guide(const Guide &);
Guide &operator=(const Guide &);
};
} // namespace dawgdic
#endif // DAWGDIC_GUIDE_H
|