2012-10-18 21:54:38 +04:00
|
|
|
#ifndef SEARCH_HEADER__
|
|
|
|
#define SEARCH_HEADER__
|
|
|
|
|
2014-04-04 18:54:48 +04:00
|
|
|
// Header consisting of Score, Arity, Note and WordsRange
|
2012-10-18 21:54:38 +04:00
|
|
|
|
|
|
|
#include "search/types.hh"
|
2014-04-04 18:54:48 +04:00
|
|
|
#include "moses/WordsRange.h"
|
2012-10-18 21:54:38 +04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
namespace search {
|
|
|
|
|
2015-04-30 08:05:11 +03:00
|
|
|
// Copying is shallow.
|
2012-10-18 21:54:38 +04:00
|
|
|
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();
|
|
|
|
}
|
2012-11-15 22:04:07 +04:00
|
|
|
bool operator>(const Header &other) const {
|
|
|
|
return GetScore() > other.GetScore();
|
|
|
|
}
|
2012-10-18 21:54:38 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-04-04 18:54:48 +04:00
|
|
|
Moses::WordsRange GetRange() const {
|
|
|
|
return *reinterpret_cast<const Moses::WordsRange*>(base_ + sizeof(Score) + sizeof(Arity) + sizeof(Note));
|
|
|
|
}
|
|
|
|
void SetRange(Moses::WordsRange to) {
|
|
|
|
*reinterpret_cast<Moses::WordsRange*>(base_ + sizeof(Score) + sizeof(Arity) + sizeof(Note)) = to;
|
|
|
|
}
|
|
|
|
|
2012-11-15 22:04:07 +04:00
|
|
|
uint8_t *Base() { return base_; }
|
|
|
|
const uint8_t *Base() const { return base_; }
|
|
|
|
|
2012-10-18 21:54:38 +04:00
|
|
|
protected:
|
|
|
|
Header() : base_(NULL) {}
|
|
|
|
|
2012-11-15 22:04:07 +04:00
|
|
|
explicit Header(void *base) : base_(static_cast<uint8_t*>(base)) {}
|
|
|
|
|
2012-10-18 21:54:38 +04:00
|
|
|
Header(void *base, Arity arity) : base_(static_cast<uint8_t*>(base)) {
|
|
|
|
*reinterpret_cast<Arity*>(base_ + sizeof(Score)) = arity;
|
|
|
|
}
|
|
|
|
|
2014-04-04 18:54:48 +04:00
|
|
|
static const std::size_t kHeaderSize = sizeof(Score) + sizeof(Arity) + sizeof(Note) + sizeof(Moses::WordsRange);
|
2012-10-18 21:54:38 +04:00
|
|
|
|
|
|
|
uint8_t *After() { return base_ + kHeaderSize; }
|
|
|
|
const uint8_t *After() const { return base_ + kHeaderSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t *base_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace search
|
|
|
|
|
|
|
|
#endif // SEARCH_HEADER__
|