From 857b81fb77b604213b04a8ec876f97aaa2ed5149 Mon Sep 17 00:00:00 2001 From: ilor <kailoran@gmail.com> Date: Wed, 22 Sep 2010 15:43:58 +0200 Subject: [PATCH] add require_matching_tagsets convenience function --- libcorpus2/tagset.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/libcorpus2/tagset.h b/libcorpus2/tagset.h index 1a845d8..1ec350e 100644 --- a/libcorpus2/tagset.h +++ b/libcorpus2/tagset.h @@ -59,6 +59,22 @@ public: tagset_idx_t expected_id, actual_id; }; +/** + * Convenience function to check if tagsets match and throw if not, with the + * given "where" circumstance string + */ +void require_matching_tagsets(const Tagset& expected, const Tagset& actual, + const std::string& where); + +/** + * Convenience function that calls the non-template require_matching_tagsets + * but can be called with something that has a tagset() method or a tagset + * object. + */ +template<class T> +void require_matching_tagsets(const T& expected, const T& actual, + const std::string& where); + class TagsetParser; class Token; @@ -373,6 +389,38 @@ private: std::vector< std::vector<bool> > pos_required_attributes_; }; +/* implementation */ + +template<class T, class U> inline +void require_matching_tagsets(const T& expected, const U& actual, + const std::string& where) +{ + require_matching_tagsets(expected.tagset(), actual.tagset(), where); +} + +template<class T> inline +void require_matching_tagsets(const T& expected, const Tagset& actual, + const std::string& where) +{ + require_matching_tagsets(expected.tagset(), actual, where); +} + +template<class T> inline +void require_matching_tagsets(const Tagset& expected, const T& actual, + const std::string& where) +{ + require_matching_tagsets(expected, actual.tagset(), where); +} + +inline +void require_matching_tagsets(const Tagset& expected, const Tagset& actual, + const std::string& where) +{ + if (actual.id() != expected.id()) { + throw TagsetMismatch(where, expected, actual); + } +} + } /* end ns Corpus2 */ #endif // LIBCORPUS2_TAGSET_H -- GitLab