Skip to content
Snippets Groups Projects
Commit e5557334 authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Some checks for Position operating on sentence context.

Checks wether Position is_inside, is_outside, or equals to other Position given the SentenceContext.
parent 7194a124
Branches
No related merge requests found
#include <libwccl/values/position.h> #include <libwccl/values/position.h>
#include <libwccl/sentencecontext.h>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
namespace Wccl { namespace Wccl {
const char* Position::type_name = "Position"; const char* Position::type_name = "Position";
...@@ -25,4 +27,10 @@ std::string Position::var_repr(const std::string &var_name) ...@@ -25,4 +27,10 @@ std::string Position::var_repr(const std::string &var_name)
return ss.str(); return ss.str();
} }
bool Position::is_inside(const SentenceContext& context) const
{
int abs_position = context.get_abs_position(*this);
return context.is_inside(abs_position);
}
} /* end ns Wccl */ } /* end ns Wccl */
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Wccl { namespace Wccl {
class SentenceContext;
class Position : public Value class Position : public Value
{ {
public: public:
...@@ -32,10 +34,36 @@ public: ...@@ -32,10 +34,36 @@ public:
/// Value override /// Value override
std::string to_raw_string() const; std::string to_raw_string() const;
bool equals(const Position& other) { /**
* @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_; 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);
}
private: private:
int val_; int val_;
}; };
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment