From fb6645c2d1a9455c9c5686e964beafec60c1b8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl> Date: Tue, 26 Apr 2011 12:58:12 +0200 Subject: [PATCH] longest() and oneof() operator takes boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > > --- libwccl/ops/match/conditions/longest.cpp | 10 +++++----- libwccl/ops/match/conditions/longest.h | 4 ++-- libwccl/ops/match/conditions/oneof.cpp | 10 +++++----- libwccl/ops/match/conditions/oneof.h | 4 ++-- libwccl/parser/grammar.g | 14 ++++++-------- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/libwccl/ops/match/conditions/longest.cpp b/libwccl/ops/match/conditions/longest.cpp index ce8b9aa..82a3653 100644 --- a/libwccl/ops/match/conditions/longest.cpp +++ b/libwccl/ops/match/conditions/longest.cpp @@ -5,7 +5,7 @@ namespace Wccl { -Longest::Longest(const boost::shared_ptr<std::vector<ConjConditions> >& variants) +Longest::Longest(const boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > >& variants) : _variants(variants) { BOOST_ASSERT(_variants); @@ -18,8 +18,8 @@ MatchResult Longest::apply(const ActionExecContext& context) const int longest_pos = orig_pos; MatchResult longest; - foreach(const ConjConditions& variant, *_variants) { - MatchResult res = variant.apply(context); + foreach(const boost::shared_ptr<ConjConditions>& variant, *_variants) { + MatchResult res = variant->apply(context); int cur_pos = context.sentence_context().get_position(); if (res.matched() && longest_pos < cur_pos) { longest_pos = cur_pos; @@ -40,7 +40,7 @@ std::string Longest::to_string(const Corpus2::Tagset& tagset) const if (i != 0) { ostream << ", "; } - ostream << "variant" << _variants->at(i).to_string(tagset); + ostream << "variant" << _variants->at(i)->to_string(tagset); } ostream << ")"; return ostream.str(); @@ -53,7 +53,7 @@ std::ostream& Longest::write_to(std::ostream& ostream) const if (i != 0) { ostream << ", "; } - ostream << "variant" << _variants->at(i); + ostream << "variant" << *(_variants->at(i)); } return ostream << ")"; } diff --git a/libwccl/ops/match/conditions/longest.h b/libwccl/ops/match/conditions/longest.h index 2aed55b..008b507 100644 --- a/libwccl/ops/match/conditions/longest.h +++ b/libwccl/ops/match/conditions/longest.h @@ -11,7 +11,7 @@ namespace Wccl { class Longest : public MatchCondition { public: - Longest(const boost::shared_ptr<std::vector<ConjConditions> >& variants); + Longest(const boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > >& variants); /** * @returns Name of the condition. @@ -45,7 +45,7 @@ protected: */ std::ostream& write_to(std::ostream& ostream) const; private: - const boost::shared_ptr<std::vector<ConjConditions> > _variants; + const boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > > _variants; }; } /* end ns Wccl */ diff --git a/libwccl/ops/match/conditions/oneof.cpp b/libwccl/ops/match/conditions/oneof.cpp index 78c3544..068b04a 100644 --- a/libwccl/ops/match/conditions/oneof.cpp +++ b/libwccl/ops/match/conditions/oneof.cpp @@ -5,7 +5,7 @@ namespace Wccl { -OneOf::OneOf(const boost::shared_ptr<std::vector<ConjConditions> >& variants) +OneOf::OneOf(const boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > >& variants) : _variants(variants) { BOOST_ASSERT(_variants); @@ -15,8 +15,8 @@ OneOf::OneOf(const boost::shared_ptr<std::vector<ConjConditions> >& variants) MatchResult OneOf::apply(const ActionExecContext& context) const { int orig_pos = context.sentence_context().get_position(); - foreach(const ConjConditions& variant, *_variants) { - MatchResult res = variant.apply(context); + foreach(const boost::shared_ptr<ConjConditions>& variant, *_variants) { + MatchResult res = variant->apply(context); if (res.matched()) { return res; } @@ -33,7 +33,7 @@ std::string OneOf::to_string(const Corpus2::Tagset& tagset) const if (i != 0) { ostream << ", "; } - ostream << "variant" << _variants->at(i).to_string(tagset); + ostream << "variant" << _variants->at(i)->to_string(tagset); } ostream << ")"; return ostream.str(); @@ -46,7 +46,7 @@ std::ostream& OneOf::write_to(std::ostream& ostream) const if (i != 0) { ostream << ", "; } - ostream << "variant" << _variants->at(i); + ostream << "variant" << *(_variants->at(i)); } return ostream << ")"; } diff --git a/libwccl/ops/match/conditions/oneof.h b/libwccl/ops/match/conditions/oneof.h index 0aba476..a0d649a 100644 --- a/libwccl/ops/match/conditions/oneof.h +++ b/libwccl/ops/match/conditions/oneof.h @@ -11,7 +11,7 @@ namespace Wccl { class OneOf : public MatchCondition { public: - OneOf(const boost::shared_ptr<std::vector<ConjConditions> >& variants); + OneOf(const boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > >& variants); /** * @returns Name of the condition. @@ -44,7 +44,7 @@ protected: */ std::ostream& write_to(std::ostream& ostream) const; private: - const boost::shared_ptr<std::vector<ConjConditions> > _variants; + const boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > > _variants; }; } /* end ns Wccl */ diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index 7d445e1..f534a84 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -2111,20 +2111,18 @@ match_condition_in // Retutns boost::shared_ptr<std::vector<ConjConditions> > match_variants [ParsingScope& scope] - returns [boost::shared_ptr<std::vector<ConjConditions> > variants] + returns [boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > > variants] { - variants.reset(new std::vector<ConjConditions>()); + variants.reset(new std::vector<boost::shared_ptr<ConjConditions> >()); boost::shared_ptr<ConjConditions> variant; } : "variant" LPAREN variant = match_condition [scope] RPAREN { - // TODO - // variants->push_back(variant); + variants->push_back(variant); } ( COMMA "variant" LPAREN variant = match_condition [scope] RPAREN { - // TODO - // variants->push_back(variant); + variants->push_back(variant); } )* ; @@ -2207,7 +2205,7 @@ match_cond_oneof [ParsingScope& scope] returns [boost::shared_ptr<OneOf> onf] { - boost::shared_ptr<std::vector<ConjConditions> > variants; + boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > > variants; } : "oneof" LPAREN variants = match_variants [scope] RPAREN { onf.reset(new OneOf(variants)); @@ -2220,7 +2218,7 @@ match_cond_longest [ParsingScope& scope] returns [boost::shared_ptr<Longest> lng] { - boost::shared_ptr<std::vector<ConjConditions> > variants; + boost::shared_ptr<std::vector<boost::shared_ptr<ConjConditions> > > variants; } : "longest" LPAREN variants = match_variants [scope] RPAREN { lng.reset(new Longest(variants)); -- GitLab