From fa524598938278cd6f9a1519df6b52012b21d8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wardy=C5=84ski?= <no@email> Date: Mon, 8 Nov 2010 14:27:08 +0100 Subject: [PATCH] Adding some methods to values for use by operators, e.g. equals and is_subset_of/intersection. Some are just stubs. --- libwccl/values/bool.h | 4 ++++ libwccl/values/position.h | 4 ++++ libwccl/values/positionref.h | 23 +++++++++++++++++++++++ libwccl/values/strset.h | 19 +++++++++++++++++++ libwccl/values/tset.h | 19 +++++++++++++++++++ 5 files changed, 69 insertions(+) diff --git a/libwccl/values/bool.h b/libwccl/values/bool.h index a668b7d..19b53c9 100644 --- a/libwccl/values/bool.h +++ b/libwccl/values/bool.h @@ -23,6 +23,10 @@ public: val_ = v; } + bool equals(const Bool& other) { + return val_ == other.val_; + } + /// Value override std::string to_raw_string() const { return val_ ? "true" : "false"; diff --git a/libwccl/values/position.h b/libwccl/values/position.h index 0b2148b..a87a8a9 100644 --- a/libwccl/values/position.h +++ b/libwccl/values/position.h @@ -32,6 +32,10 @@ public: /// Value override std::string to_raw_string() const; + bool equals(const Position& other) { + return val_ == other.val_; + } + private: int val_; }; diff --git a/libwccl/values/positionref.h b/libwccl/values/positionref.h index dcb8667..4b0ffb6 100644 --- a/libwccl/values/positionref.h +++ b/libwccl/values/positionref.h @@ -37,6 +37,29 @@ public: offset_ = offset; } + /** + * Returns true if underlying Position is Nowhere, + * or underlying Position is Begin and offset is less than zero, + * or underlying Position is End and offset is greater than zero. + * False otherwise. + * This function does not take into account any actual sentence + * boundaries. + */ + bool points_nowhere() const { + //We probably could allow null dereference (shouldn't logically + //happen so if it does, it's bad) but let's be defensive + //and assume null base is like nowhere. + return (base_.get() == NULL) || + (base_->get_value() == Position::Nowhere) || + (base_->get_value() == Position::Begin && offset_ < 0) || + (base_->get_value() == Position::End && offset_ > 0); + } + + bool equals(const PositionRef& other) { + return points_nowhere() ? other.points_nowhere() + : offset_ == other.offset_ && base_->equals(*other.base_); + } + private: boost::shared_ptr<Position> base_; diff --git a/libwccl/values/strset.h b/libwccl/values/strset.h index a180c47..8786397 100644 --- a/libwccl/values/strset.h +++ b/libwccl/values/strset.h @@ -52,6 +52,25 @@ public: return set_.size(); } + bool empty() const { + return set_.empty(); + } + + bool is_subset_of(const StrSet& /*set*/) const { + //TODO: implement this + return false; + } + + StrSet intersect(const StrSet& /*set*/) const { + //TODO: implement this + return StrSet(set_t()); + } + + bool equals(const StrSet& /*set*/) const { + //TODO: implement this + return false; + } + /// Value override std::string to_raw_string() const; diff --git a/libwccl/values/tset.h b/libwccl/values/tset.h index 5cd25a4..ba5bb5b 100644 --- a/libwccl/values/tset.h +++ b/libwccl/values/tset.h @@ -33,6 +33,25 @@ public: return tag_; } + bool empty() const { + return tag_.is_null(); + } + + bool is_subset_of(const TSet& /*tset*/) const { + //TODO: implement this + return false; + } + + TSet intersect(const TSet& /*tset*/) const { + //TODO: implement this + return TSet(); + } + + bool equals(const TSet& /*tset*/) const { + //TODO: implement this + return false; + } + std::string to_string(const Corpus2::Tagset &) const; std::string to_raw_string() const; -- GitLab