diff options
author | Kenneth Heafield <github@kheafield.com> | 2012-10-18 21:54:38 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2012-10-18 21:54:38 +0400 |
commit | 39664ac8f48c44fa4a81ff63de7ff2d31a956b5e (patch) | |
tree | f0928f6ff3f63bb1f68ca0b08009173a9968d85d /search/header.hh | |
parent | 05e91def21d90d848b5f804f2fc9bd974bc496df (diff) |
Support arbitrary arity
Also, some windows fixes in util.
Diffstat (limited to 'search/header.hh')
-rw-r--r-- | search/header.hh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/search/header.hh b/search/header.hh new file mode 100644 index 000000000..25550dbed --- /dev/null +++ b/search/header.hh @@ -0,0 +1,57 @@ +#ifndef SEARCH_HEADER__ +#define SEARCH_HEADER__ + +// Header consisting of Score, Arity, and Note + +#include "search/note.hh" +#include "search/types.hh" + +#include <stdint.h> + +namespace search { + +// Copying is shallow. +class Header { + public: + bool Valid() const { return base_; } + + Score GetScore() const { + return *reinterpret_cast<const float*>(base_); + } + void SetScore(Score to) { + *reinterpret_cast<float*>(base_) = to; + } + bool operator<(const Header &other) const { + return GetScore() < other.GetScore(); + } + + Arity GetArity() const { + return *reinterpret_cast<const Arity*>(base_ + sizeof(Score)); + } + + Note GetNote() const { + return *reinterpret_cast<const Note*>(base_ + sizeof(Score) + sizeof(Arity)); + } + void SetNote(Note to) { + *reinterpret_cast<Note*>(base_ + sizeof(Score) + sizeof(Arity)) = to; + } + + protected: + Header() : base_(NULL) {} + + Header(void *base, Arity arity) : base_(static_cast<uint8_t*>(base)) { + *reinterpret_cast<Arity*>(base_ + sizeof(Score)) = arity; + } + + static const std::size_t kHeaderSize = sizeof(Score) + sizeof(Arity) + sizeof(Note); + + uint8_t *After() { return base_ + kHeaderSize; } + const uint8_t *After() const { return base_ + kHeaderSize; } + + private: + uint8_t *base_; +}; + +} // namespace search + +#endif // SEARCH_HEADER__ |