From 2b48b679f7d24ae9d1087df04ddad32970d77388 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 23 May 2017 15:27:23 +0200 Subject: [PATCH] raw parse ranked tree types --- alib2raw/src/tree/TreeFromRawParser.cpp | 17 +++++++++++++++++ alib2raw/src/tree/TreeFromRawParser.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/alib2raw/src/tree/TreeFromRawParser.cpp b/alib2raw/src/tree/TreeFromRawParser.cpp index d375f36d35..96ab094461 100644 --- a/alib2raw/src/tree/TreeFromRawParser.cpp +++ b/alib2raw/src/tree/TreeFromRawParser.cpp @@ -8,6 +8,7 @@ #include <sax/FromXMLParserHelper.h> #include <exception/CommonException.h> #include <tree/Tree.h> +#include <tree/RankedTreeWrapper.h> #include <tree/TreeClasses.h> #include <alphabet/Symbol.h> #include <alphabet/BarSymbol.h> @@ -33,6 +34,22 @@ Tree TreeFromRawParser::parseTree(std::deque<sax::Token>::iterator& input, const throw exception::CommonException("Invalid input"); } +RankedTreeWrapper TreeFromRawParser::parseRankedTree(std::deque<sax::Token>::iterator& input) const { + return parseRankedTree(input, std::set<FEATURES>({FEATURES::RANKED_TREE, FEATURES::PREFIX_RANKED_TREE, FEATURES::PREFIX_RANKED_BAR_TREE})); +} + +RankedTreeWrapper TreeFromRawParser::parseRankedTree(std::deque<sax::Token>::iterator& input, const std::set<FEATURES>& features) const { + UnrankedTree < alphabet::Symbol > tree(this->parseContent(input)); + + if(features.count(FEATURES::PREFIX_RANKED_TREE)) return RankedTreeWrapper{PrefixRankedTree < alphabet::Symbol, primitive::Unsigned > {RankedTree < alphabet::Symbol, primitive::Unsigned > {tree}}}; + + if(features.count(FEATURES::PREFIX_RANKED_BAR_TREE)) return RankedTreeWrapper{PrefixRankedBarTree < alphabet::Symbol, primitive::Unsigned > {alphabet::Symbol{alphabet::BarSymbol{}}, RankedTree < alphabet::Symbol, primitive::Unsigned > {tree}}}; + + if(features.count(FEATURES::RANKED_TREE)) return RankedTreeWrapper{RankedTree < alphabet::Symbol, primitive::Unsigned > {tree}}; + + throw exception::CommonException("Invalid input"); +} + std::tree < alphabet::Symbol > TreeFromRawParser::parseContent(std::deque<sax::Token>::iterator& input) const { if (sax::FromXMLParserHelper::isTokenType(input, sax::Token::TokenType::START_ELEMENT)) { std::tree < alphabet::Symbol > node ( alphabet::Symbol(sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::START_ELEMENT)), {}); diff --git a/alib2raw/src/tree/TreeFromRawParser.h b/alib2raw/src/tree/TreeFromRawParser.h index e4501fe06e..ef73bff86a 100644 --- a/alib2raw/src/tree/TreeFromRawParser.h +++ b/alib2raw/src/tree/TreeFromRawParser.h @@ -24,6 +24,9 @@ public: Tree parseTree(std::deque<sax::Token>::iterator& input) const; Tree parseTree(std::deque<sax::Token>::iterator& input, const std::set<FEATURES>& features) const; + RankedTreeWrapper parseRankedTree(std::deque<sax::Token>::iterator& input) const; + RankedTreeWrapper parseRankedTree(std::deque<sax::Token>::iterator& input, const std::set<FEATURES>& features) const; + private: std::tree < alphabet::Symbol > parseContent(std::deque<sax::Token>::iterator& input) const; }; -- GitLab