mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
73 lines
1.9 KiB
C++
73 lines
1.9 KiB
C++
#ifndef SEARCH_HEADER__
|
|
#define SEARCH_HEADER__
|
|
|
|
// Header consisting of Score, Arity, Note and Range
|
|
|
|
#include "search/types.hh"
|
|
#include "moses/Range.h"
|
|
|
|
#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();
|
|
}
|
|
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;
|
|
}
|
|
|
|
Moses::Range GetRange() const {
|
|
return *reinterpret_cast<const Moses::Range*>(base_ + sizeof(Score) + sizeof(Arity) + sizeof(Note));
|
|
}
|
|
void SetRange(Moses::Range to) {
|
|
*reinterpret_cast<Moses::Range*>(base_ + sizeof(Score) + sizeof(Arity) + sizeof(Note)) = to;
|
|
}
|
|
|
|
uint8_t *Base() { return base_; }
|
|
const uint8_t *Base() const { return base_; }
|
|
|
|
protected:
|
|
Header() : base_(NULL) {}
|
|
|
|
explicit Header(void *base) : base_(static_cast<uint8_t*>(base)) {}
|
|
|
|
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) + sizeof(Moses::Range);
|
|
|
|
uint8_t *After() { return base_ + kHeaderSize; }
|
|
const uint8_t *After() const { return base_ + kHeaderSize; }
|
|
|
|
private:
|
|
uint8_t *base_;
|
|
};
|
|
|
|
} // namespace search
|
|
|
|
#endif // SEARCH_HEADER__
|