Newer
Older
#ifndef LIBWCCL_VALUES_POSITION_H
#define LIBWCCL_VALUES_POSITION_H
#include <boost/integer_traits.hpp>
class SentenceContext;
class Position : public Value
{
public:
WCCL_VALUE_PREAMBLE
explicit Position(int v = 0)
: val_(v)
{
}
static const int Nowhere = boost::integer_traits<int>::const_min;
static const int Begin = boost::integer_traits<int>::const_min + 1;
static const int End = boost::integer_traits<int>::const_max;
int get_value() const {
return val_;
}
void set_value(int v) {
val_ = v;
}
/// Value override
std::string to_raw_string() const;
/**
* @returns True if Position is within bounds of a sentence, false otherwise.
*/
bool is_inside(const SentenceContext& context) const;
/**
* @returns True if Position is outside of bounds of a sentence, false otherwise.
*/
bool is_outside(const SentenceContext& context) const {
return !is_inside(context);
}
/**
* @returns True if underlying position values are equal, false otherwise.
* @note This version does not take into account sentence context, only
* the raw value of position.
*/
bool equals(const Position& other) const {
return val_ == other.val_;
}
/**
* @returns True if positions are equal in context of a sentence, false otherwise.
* @note This version determines if position values point outside of a sentence,
* and if both of them do, they are considered to be equal as well (both "nowhere").
*/
bool equals(const Position& other, const SentenceContext& context) const
{
return equals(other) || (is_outside(context) && other.is_outside(context));