From e079ae700ce23b64fefd4971741b58b3827fe85a Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Fri, 27 Apr 2018 15:42:58 +0200 Subject: [PATCH] redesign xml to tokens api --- aintrospection2/src/aintrospection.cpp | 2 +- alib2data/test-src/alphabet/SymbolTest.cpp | 6 +- .../automaton/AutomatonTemplatesTest.cpp | 6 +- .../test-src/automaton/AutomatonTest.cpp | 12 ++-- .../test-src/common/SparseBoolVectorTest.cpp | 6 +- alib2data/test-src/grammar/GrammarTest.cpp | 66 +++++++------------ alib2data/test-src/label/LabelTest.cpp | 6 +- alib2data/test-src/regexp/RegExpTest.cpp | 6 +- alib2data/test-src/rte/RTETest.cpp | 6 +- alib2data/test-src/string/StringTest.cpp | 6 +- alib2data/test-src/tree/PatternTest.cpp | 24 +++---- alib2data/test-src/tree/TreeTest.cpp | 18 ++--- alib2raw/src/tree/raw/UnrankedTree.h | 2 +- .../XmlTokensComposerAbstraction.hpp | 2 +- .../XmlTokensParserAbstraction.hpp | 4 +- alib2xml/src/factory/XmlDataFactory.hpp | 30 +++------ alib2xml/src/registry/XmlRegistry.cpp | 1 + alib2xml/src/sax/SaxComposeInterface.cpp | 24 ++++--- alib2xml/src/sax/SaxComposeInterface.h | 52 +++++++++------ alib2xml/src/sax/SaxParseInterface.cpp | 22 +++++++ alib2xml/src/sax/SaxParseInterface.h | 49 +++++++++++--- alib2xml/test-src/primitive/PrimitiveTest.cpp | 6 +- alib2xml/test-src/sax/SaxTest.cpp | 2 +- 23 files changed, 179 insertions(+), 179 deletions(-) diff --git a/aintrospection2/src/aintrospection.cpp b/aintrospection2/src/aintrospection.cpp index 88ce96e61b..b84e9f41c6 100644 --- a/aintrospection2/src/aintrospection.cpp +++ b/aintrospection2/src/aintrospection.cpp @@ -172,7 +172,7 @@ int main ( int argc, char * argv[] ) { tokens.emplace_back("Algorithms", sax::Token::TokenType::END_ELEMENT); tokens.emplace_back("Summary", sax::Token::TokenType::END_ELEMENT); - sax::SaxComposeInterface::printStdout ( tokens ); + sax::SaxComposeInterface::composeStdout ( tokens ); } measurements::end ( ); diff --git a/alib2data/test-src/alphabet/SymbolTest.cpp b/alib2data/test-src/alphabet/SymbolTest.cpp index 2fabec4851..ddd126aa22 100644 --- a/alib2data/test-src/alphabet/SymbolTest.cpp +++ b/alib2data/test-src/alphabet/SymbolTest.cpp @@ -43,11 +43,9 @@ void SymbolTest::testXMLParser ( ) { { ext::deque < sax::Token > tokens = factory::XmlDataFactory::toTokens ( symbol ); - std::string tmp; - sax::SaxComposeInterface::printMemory ( tmp, tokens ); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque < sax::Token > tokens2; - sax::SaxParseInterface::parseMemory ( tmp, tokens2 ); + ext::deque < sax::Token > tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); alphabet::Symbol symbol2 = factory::XmlDataFactory::fromTokens ( std::move( tokens2 ) ); CPPUNIT_ASSERT ( symbol == symbol2 ); diff --git a/alib2data/test-src/automaton/AutomatonTemplatesTest.cpp b/alib2data/test-src/automaton/AutomatonTemplatesTest.cpp index 4df14a0c5b..d047f916cd 100644 --- a/alib2data/test-src/automaton/AutomatonTemplatesTest.cpp +++ b/alib2data/test-src/automaton/AutomatonTemplatesTest.cpp @@ -41,8 +41,7 @@ void AutomatonTemplatesTest::testDFAParser ( ) { CPPUNIT_ASSERT ( automaton == automaton ); { ext::deque < sax::Token > tokens = factory::XmlDataFactory::toTokens ( automaton ); - std::string tmp; - sax::SaxComposeInterface::printMemory ( tmp, tokens ); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); ext::deque < sax::Token > tokens2; sax::SaxParseInterface::parseMemory ( tmp, tokens2 ); @@ -52,8 +51,7 @@ void AutomatonTemplatesTest::testDFAParser ( ) { } { ext::deque < sax::Token > tokens = factory::XmlDataFactory::toTokens ( automaton ); - std::string tmp; - sax::SaxComposeInterface::printMemory ( tmp, tokens ); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); ext::deque < sax::Token > tokens2; sax::SaxParseInterface::parseMemory ( tmp, tokens2 ); diff --git a/alib2data/test-src/automaton/AutomatonTest.cpp b/alib2data/test-src/automaton/AutomatonTest.cpp index 772953b34e..74a0eb1c79 100644 --- a/alib2data/test-src/automaton/AutomatonTest.cpp +++ b/alib2data/test-src/automaton/AutomatonTest.cpp @@ -55,11 +55,9 @@ void AutomatonTest::testDFAParser() { CPPUNIT_ASSERT( automaton == automaton ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(automaton); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); automaton::DFA < char, int > automaton2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( automaton == automaton2 ); @@ -302,12 +300,10 @@ void AutomatonTest::testNFTAParser() { CPPUNIT_ASSERT( automaton == automaton ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(automaton); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); std::cout << tmp << std::endl; - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); automaton::NFTA < char, unsigned, int > automaton2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( automaton == automaton2 ); diff --git a/alib2data/test-src/common/SparseBoolVectorTest.cpp b/alib2data/test-src/common/SparseBoolVectorTest.cpp index 60af87c9d4..5a4b2c3b7a 100644 --- a/alib2data/test-src/common/SparseBoolVectorTest.cpp +++ b/alib2data/test-src/common/SparseBoolVectorTest.cpp @@ -295,12 +295,10 @@ void SparseBoolVectorTest::testXmlApi() { common::SparseBoolVector data ( ref ); ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens( data ); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); // std::cout << tmp << std::endl; - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); common::SparseBoolVector data2 = factory::XmlDataFactory::fromTokens ( std::move ( tokens2 ) ); /* std::cout << data.data ( ) << std::endl; diff --git a/alib2data/test-src/grammar/GrammarTest.cpp b/alib2data/test-src/grammar/GrammarTest.cpp index fc63210487..574dd79d28 100644 --- a/alib2data/test-src/grammar/GrammarTest.cpp +++ b/alib2data/test-src/grammar/GrammarTest.cpp @@ -53,11 +53,9 @@ void GrammarTest::testUnrestrictedParser() { CPPUNIT_ASSERT( grammar == grammar ); ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::UnrestrictedGrammar < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -80,11 +78,9 @@ void GrammarTest::testUnrestrictedParser() { CPPUNIT_ASSERT( grammar == grammar ); ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::ContextPreservingUnrestrictedGrammar < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -107,11 +103,9 @@ void GrammarTest::testRegularParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::RightRG < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -135,13 +129,11 @@ void GrammarTest::testRegularParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); std::cout << tmp << std::endl; - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::RightLG < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -167,11 +159,9 @@ void GrammarTest::testContextFreeParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::LG < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -195,11 +185,9 @@ void GrammarTest::testContextFreeParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::EpsilonFreeCFG < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -223,11 +211,9 @@ void GrammarTest::testContextFreeParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::CFG < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -251,11 +237,9 @@ void GrammarTest::testContextFreeParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::CNF < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -279,11 +263,9 @@ void GrammarTest::testContextFreeParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::GNF < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -309,11 +291,9 @@ void GrammarTest::testContextSensitiveParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::CSG < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); @@ -336,11 +316,9 @@ void GrammarTest::testContextSensitiveParser() { CPPUNIT_ASSERT( grammar == grammar ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(grammar); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); grammar::NonContractingGrammar < > grammar2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( grammar == grammar2 ); diff --git a/alib2data/test-src/label/LabelTest.cpp b/alib2data/test-src/label/LabelTest.cpp index 4d6f7d21a9..52d72a983b 100644 --- a/alib2data/test-src/label/LabelTest.cpp +++ b/alib2data/test-src/label/LabelTest.cpp @@ -42,11 +42,9 @@ void LabelTest::testXMLParser() { { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(label); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); label::Label label2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( label == label2 ); diff --git a/alib2data/test-src/regexp/RegExpTest.cpp b/alib2data/test-src/regexp/RegExpTest.cpp index 20072199cb..b1ebe4e92b 100644 --- a/alib2data/test-src/regexp/RegExpTest.cpp +++ b/alib2data/test-src/regexp/RegExpTest.cpp @@ -107,11 +107,9 @@ void RegExpTest::testXMLParser() { { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(regexp); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); regexp::RegExp regexp2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( regexp == regexp2 ); diff --git a/alib2data/test-src/rte/RTETest.cpp b/alib2data/test-src/rte/RTETest.cpp index ae4283cb92..adb51870b0 100644 --- a/alib2data/test-src/rte/RTETest.cpp +++ b/alib2data/test-src/rte/RTETest.cpp @@ -123,11 +123,9 @@ void RTETest::testXMLParser ( ) { factory::XmlDataFactory::toStdout ( rte ); { ext::deque < sax::Token > tokens = factory::XmlDataFactory::toTokens ( rte ); - std::string tmp; - sax::SaxComposeInterface::printMemory ( tmp, tokens ); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque < sax::Token > tokens2; - sax::SaxParseInterface::parseMemory ( tmp, tokens2 ); + ext::deque < sax::Token > tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); rte::RTE rte2 = factory::XmlDataFactory::fromTokens ( std::move ( tokens2 ) ); CPPUNIT_ASSERT ( rte == rte2 ); diff --git a/alib2data/test-src/string/StringTest.cpp b/alib2data/test-src/string/StringTest.cpp index f7a8646d45..9c75e3c6f8 100644 --- a/alib2data/test-src/string/StringTest.cpp +++ b/alib2data/test-src/string/StringTest.cpp @@ -58,13 +58,11 @@ void StringTest::testXMLParser ( ) { string::String string ( linearString ); { ext::deque < sax::Token > tokens = factory::XmlDataFactory::toTokens ( string ); - std::string tmp; - sax::SaxComposeInterface::printMemory ( tmp, tokens ); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); std::cout << tmp << std::endl; - ext::deque < sax::Token > tokens2; - sax::SaxParseInterface::parseMemory ( tmp, tokens2 ); + ext::deque < sax::Token > tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); string::String string2 = factory::XmlDataFactory::fromTokens ( std::move( tokens2 ) ); CPPUNIT_ASSERT ( string == string2 ); diff --git a/alib2data/test-src/tree/PatternTest.cpp b/alib2data/test-src/tree/PatternTest.cpp index f5c7ecfdc1..71b5250888 100644 --- a/alib2data/test-src/tree/PatternTest.cpp +++ b/alib2data/test-src/tree/PatternTest.cpp @@ -45,11 +45,9 @@ void PatternTest::testRankedPatternParser() { tree.getContent().nicePrint(std::cout); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(tree); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); tree::RankedPattern < > tree2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( tree == tree2 ); @@ -95,11 +93,9 @@ void PatternTest::testUnrankedPatternParser() { tree.getContent().nicePrint(std::cout); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(tree); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); tree::UnrankedPattern < > tree2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( tree == tree2 ); @@ -145,11 +141,9 @@ void PatternTest::testPrefixRankedPatternParser() { CPPUNIT_ASSERT( pattern2 == pattern2 ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(pattern2); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); tree::PrefixRankedPattern < > pattern3 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( pattern2 == pattern3 ); @@ -176,13 +170,11 @@ void PatternTest::testPrefixRankedBarPatternParser() { CPPUNIT_ASSERT( pattern2 == pattern2 ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(pattern2); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); std::cout << tmp << std::endl << std::endl; - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); tree::PrefixRankedBarPattern < > pattern3 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( pattern2 == pattern3 ); diff --git a/alib2data/test-src/tree/TreeTest.cpp b/alib2data/test-src/tree/TreeTest.cpp index 500599cde4..46d4678e17 100644 --- a/alib2data/test-src/tree/TreeTest.cpp +++ b/alib2data/test-src/tree/TreeTest.cpp @@ -66,11 +66,9 @@ void TreeTest::testRankedTreeParser() { tree.getContent().nicePrint(std::cout); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(tree); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); tree::RankedTree < > tree2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( tree == tree2 ); @@ -190,12 +188,10 @@ void TreeTest::testUnrankedTreeParser() { tree.getContent().nicePrint(std::cout); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(tree); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); std::cout << std::endl << tmp << std::endl << std::endl; - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); tree::UnrankedTree < > tree2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( tree == tree2 ); @@ -296,13 +292,11 @@ void TreeTest::testPrefixRankedBarParser() { CPPUNIT_ASSERT( tree2 == tree2 ); { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(tree2); - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); std::cout << tmp << std::endl << std::endl; - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); tree::PrefixRankedBarTree < > tree3 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( tree2 == tree3 ); diff --git a/alib2raw/src/tree/raw/UnrankedTree.h b/alib2raw/src/tree/raw/UnrankedTree.h index d58ce6b2a0..dbab86aae9 100644 --- a/alib2raw/src/tree/raw/UnrankedTree.h +++ b/alib2raw/src/tree/raw/UnrankedTree.h @@ -38,7 +38,7 @@ template < class SymbolType > void rawApi < tree::UnrankedTree < SymbolType > >::compose ( std::ostream & output, const tree::UnrankedTree < SymbolType > & tree ) { ext::deque < sax::Token > tokens; composeContent ( tokens, tree.getContent ( ) ); - sax::SaxComposeInterface::printStream ( output, tokens ); + sax::SaxComposeInterface::composeStream ( output, tokens ); } template < class SymbolType > diff --git a/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp b/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp index 0a9eb56a68..01e882aded 100644 --- a/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp +++ b/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp @@ -18,7 +18,7 @@ public: if ( ! this->inputsReady ( ) ) return false; - sax::SaxComposeInterface::printFile ( std::get < 1 > ( this->m_params )->getConstValueReference ( ), std::get < 0 > ( this->m_params )->getConstValueReference ( ) ); + sax::SaxComposeInterface::composeFile ( std::get < 1 > ( this->m_params )->getConstValueReference ( ), std::get < 0 > ( this->m_params )->getConstValueReference ( ) ); return true; } }; diff --git a/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp b/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp index 321c555db1..b8dab71dbc 100644 --- a/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp +++ b/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp @@ -18,9 +18,7 @@ public: if ( ! this->inputsReady ( ) ) return false; - ext::deque < sax::Token > tokens; - sax::SaxParseInterface::parseFile ( std::get < 0 > ( this->m_params )->getConstValueReference ( ), tokens ); - this->m_data = tokens; + this->m_data = sax::SaxParseInterface::parseFile ( std::get < 0 > ( this->m_params )->getConstValueReference ( ) ); return true; } }; diff --git a/alib2xml/src/factory/XmlDataFactory.hpp b/alib2xml/src/factory/XmlDataFactory.hpp index b11b29da66..1fe51d47ad 100644 --- a/alib2xml/src/factory/XmlDataFactory.hpp +++ b/alib2xml/src/factory/XmlDataFactory.hpp @@ -41,10 +41,7 @@ public: */ template < class T > operator T ( ) { - ext::deque < sax::Token > tokens; - sax::SaxParseInterface::parseFile ( filename, tokens ); - - return fromTokens ( std::move( tokens ) ); + return fromTokens ( sax::SaxParseInterface::parseFile ( filename ) ); } }; @@ -62,10 +59,7 @@ public: */ template < class T > operator T ( ) { - ext::deque < sax::Token > tokens; - sax::SaxParseInterface::parseMemory ( string, tokens ); - - return fromTokens ( std::move ( tokens ) ); + return fromTokens ( sax::SaxParseInterface::parseMemory ( string ) ); } }; @@ -77,10 +71,7 @@ public: */ template < class T > operator T ( ) { - ext::deque < sax::Token > tokens; - sax::SaxParseInterface::parseStdin ( tokens ); - - return fromTokens ( std::move ( tokens ) ); + return fromTokens ( sax::SaxParseInterface::parseStdin ( ) ); } }; @@ -97,10 +88,8 @@ public: */ template < class T > operator T ( ) { - ext::deque < sax::Token > tokens; - sax::SaxParseInterface::parseStream ( in, tokens ); + return fromTokens ( sax::SaxParseInterface::parseStream ( in ) ); - return fromTokens ( std::move ( tokens ) ); } }; @@ -154,7 +143,7 @@ public: template < class T > static void toFile ( const T & data, const std::string & filename ) { ext::deque < sax::Token > tokens = toTokens < T > ( data ); - sax::SaxComposeInterface::printFile ( filename, tokens ); + sax::SaxComposeInterface::composeFile ( filename, tokens ); } /** @@ -165,10 +154,7 @@ public: template < class T > static std::string toString ( const T & data ) { ext::deque < sax::Token > tokens = toTokens < T > ( data ); - std::string str; - sax::SaxComposeInterface::printMemory ( str, tokens ); - - return str; + return sax::SaxComposeInterface::composeMemory ( tokens ); } /** @@ -178,7 +164,7 @@ public: template < class T > static void toStdout ( const T & data ) { ext::deque < sax::Token > tokens = toTokens < T > ( data ); - sax::SaxComposeInterface::printStdout ( tokens ); + sax::SaxComposeInterface::composeStdout ( tokens ); } /** @@ -188,7 +174,7 @@ public: template < class T > static void toStream ( const T & data, std::ostream & out ) { ext::deque < sax::Token > tokens = toTokens < T > ( data ); - sax::SaxComposeInterface::printStream ( out, tokens ); + sax::SaxComposeInterface::composeStream ( out, tokens ); } /** diff --git a/alib2xml/src/registry/XmlRegistry.cpp b/alib2xml/src/registry/XmlRegistry.cpp index bbf1f4ce01..b6861bfd16 100644 --- a/alib2xml/src/registry/XmlRegistry.cpp +++ b/alib2xml/src/registry/XmlRegistry.cpp @@ -59,4 +59,5 @@ std::shared_ptr < abstraction::BinaryOperationAbstraction < void, const ext::deq return res; } + } /* namespace abstraction */ diff --git a/alib2xml/src/sax/SaxComposeInterface.cpp b/alib2xml/src/sax/SaxComposeInterface.cpp index eda471667b..bce6fb8c5a 100644 --- a/alib2xml/src/sax/SaxComposeInterface.cpp +++ b/alib2xml/src/sax/SaxComposeInterface.cpp @@ -17,41 +17,47 @@ namespace sax { -void SaxComposeInterface::printMemory(std::string& xmlOut, const ext::deque<Token>& in) { +void SaxComposeInterface::composeMemory(std::string& xmlOut, const ext::deque<Token>& in) { xmlBufferPtr buf = xmlBufferCreate(); xmlTextWriterPtr writer = xmlNewTextWriterMemory(buf, 0); - SaxComposeInterface::xmlSAXUserPrint(writer, in); + SaxComposeInterface::xmlSAXUserCompose(writer, in); xmlFreeTextWriter(writer); xmlOut = (const char*) buf->content; xmlBufferFree(buf); } -void SaxComposeInterface::printFile(const std::string& filename, const ext::deque<Token>& in) { +std::string SaxComposeInterface::composeMemory ( const ext::deque < Token > & in ) { + ext::string res; + SaxComposeInterface::composeMemory ( res, in ); + return res; +} + +void SaxComposeInterface::composeFile(const std::string& filename, const ext::deque<Token>& in) { xmlTextWriterPtr writer = xmlNewTextWriterFilename(filename.c_str(), 0); - SaxComposeInterface::xmlSAXUserPrint(writer, in); + SaxComposeInterface::xmlSAXUserCompose(writer, in); xmlFreeTextWriter(writer); } -void SaxComposeInterface::printStdout(const ext::deque<Token>& in) { - SaxComposeInterface::printFile("-", in); +void SaxComposeInterface::composeStdout(const ext::deque<Token>& in) { + SaxComposeInterface::composeFile("-", in); } -void SaxComposeInterface::printStream(std::ostream& out, const ext::deque<Token>& in) { +void SaxComposeInterface::composeStream(std::ostream& out, const ext::deque<Token>& in) { xmlBufferPtr buf = xmlBufferCreate(); xmlTextWriterPtr writer = xmlNewTextWriterMemory(buf, 0); - SaxComposeInterface::xmlSAXUserPrint(writer, in); + SaxComposeInterface::xmlSAXUserCompose(writer, in); xmlFreeTextWriter(writer); out << (const char*) buf->content; xmlBufferFree(buf); } -void SaxComposeInterface::xmlSAXUserPrint(xmlTextWriterPtr writer, const ext::deque<Token>& in) { +void SaxComposeInterface::xmlSAXUserCompose(xmlTextWriterPtr writer, const ext::deque<Token>& in) { measurements::start("Sax Composer", measurements::Type::FINALIZE); xmlTextWriterStartDocument(writer, NULL, NULL, NULL); #ifdef DEBUG diff --git a/alib2xml/src/sax/SaxComposeInterface.h b/alib2xml/src/sax/SaxComposeInterface.h index c894e9ab0d..fe6472733f 100644 --- a/alib2xml/src/sax/SaxComposeInterface.h +++ b/alib2xml/src/sax/SaxComposeInterface.h @@ -15,40 +15,50 @@ namespace sax { /** - * This class performs parsing of file or string containing XML. Contains callback - * methods for libxml SAX parser. + * This class performs composing of XML Tokens to file, string, or stream. Contains callback + * method for libxml SAX composer. */ class SaxComposeInterface { - static void xmlSAXUserPrint(xmlTextWriterPtr writer, const ext::deque<Token>& in); + static void xmlSAXUserCompose(xmlTextWriterPtr writer, const ext::deque<Token>& in); public: /** - * Parses the string containing XML. - * @param xmlIn input XML - * @param out list of tokens that are returned - * @throws CommonException when an error occurs (e.g. XML is not valid) + * Composes the XML to a string. + * @param xmlOut resulting XML + * @param in list of xml tokens + * @throws CommonException when an error occurs (e.g. xml tokens incorrectly nested) */ - static void printMemory(std::string& xmlOut, const ext::deque<Token>& in); + static void composeMemory(std::string& xmlOut, const ext::deque<Token>& in); /** - * Parses the file containing XML. - * @param filename input XML - * @param out list of tokens that are returned - * @throws CommonException when an error occurs (e.g. file doesn't exist, XML is not valid) + * Composes the XML to a string. + * @param in list of xml tokens + * @return resulting XML + * @throws CommonException when an error occurs (e.g. xml tokens incorrectly nested) */ - static void printFile(const std::string& filename, const ext::deque<Token>& in); - + static std::string composeMemory ( const ext::deque < Token > & in ); + + /** + * Composes the XML to a file. + * @param filename resulting XML file destination + * @param in list of xml tokens + * @throws CommonException when an error occurs (e.g. xml tokens incorrectly nested) + */ + static void composeFile(const std::string& filename, const ext::deque<Token>& in); + /** - * Parses the XML from stdin. - * @param out list of tokens that are returned + * Composes the XML to a stdout. + * @param in list of xml tokens + * @throws CommonException when an error occurs (e.g. xml tokens incorrectly nested) */ - static void printStdout(const ext::deque<Token>& in); + static void composeStdout(const ext::deque<Token>& in); /** - * Parses the XML from stream. - * @param in input XML - * @param out list of tokens that are returned + * Composes the XML to a stream. + * @param out resulting XML stream destination + * @param in list of xml tokens + * @throws CommonException when an error occurs (e.g. xml tokens incorrectly nested) */ - static void printStream(std::ostream& out, const ext::deque<Token>& in); + static void composeStream(std::ostream& out, const ext::deque<Token>& in); }; } /* namespace sax */ diff --git a/alib2xml/src/sax/SaxParseInterface.cpp b/alib2xml/src/sax/SaxParseInterface.cpp index 204fade129..cccb9c45a3 100644 --- a/alib2xml/src/sax/SaxParseInterface.cpp +++ b/alib2xml/src/sax/SaxParseInterface.cpp @@ -33,6 +33,12 @@ void SaxParseInterface::parseMemory(const std::string& xmlIn, ext::deque<Token>& } } +ext::deque < Token > SaxParseInterface::parseMemory ( const std::string& xmlIn ) { + ext::deque < Token > tokens; + SaxParseInterface::parseMemory ( xmlIn, tokens ); + return tokens; +} + void SaxParseInterface::parseFile(const std::string& filename, ext::deque<Token>& out) { xmlTextReaderPtr reader = xmlNewTextReaderFilename(filename.c_str()); @@ -47,15 +53,31 @@ void SaxParseInterface::parseFile(const std::string& filename, ext::deque<Token> } } +ext::deque < Token > SaxParseInterface::parseFile ( const std::string & filename ) { + ext::deque < Token > tokens; + SaxParseInterface::parseFile ( filename, tokens ); + return tokens; +} + void SaxParseInterface::parseStdin(ext::deque<Token>& out) { SaxParseInterface::parseFile("-", out); } +ext::deque < Token > SaxParseInterface::parseStdin ( ) { + return SaxParseInterface::parseFile ( "-" ); +} + void SaxParseInterface::parseStream(std::istream& in, ext::deque<Token>& out) { std::string input(std::istreambuf_iterator<char>(in), (std::istreambuf_iterator<char>())); SaxParseInterface::parseMemory(input, out); } +ext::deque < Token > SaxParseInterface::parseStream ( std::istream & in ) { + ext::deque < Token > tokens; + SaxParseInterface::parseStream ( in, tokens ); + return tokens; +} + int SaxParseInterface::xmlSAXUserParse(xmlTextReaderPtr reader, ext::deque<Token>& out) { int ret = xmlTextReaderRead(reader); measurements::start("Sax Parser", measurements::Type::INIT); diff --git a/alib2xml/src/sax/SaxParseInterface.h b/alib2xml/src/sax/SaxParseInterface.h index d844330fd3..8a0f886ad5 100644 --- a/alib2xml/src/sax/SaxParseInterface.h +++ b/alib2xml/src/sax/SaxParseInterface.h @@ -15,8 +15,8 @@ namespace sax { /** - * This class performs parsing of file or string containing XML. Contains callback - * methods for libxml SAX parser. + * This class performs token parsing of file, string, or stream containing XML. Contains callback + * method for libxml SAX parser. */ class SaxParseInterface { static int xmlSAXUserParse(xmlTextReaderPtr writer, ext::deque<Token>& out); @@ -24,31 +24,64 @@ public: /** * Parses the string containing XML. * @param xmlIn input XML - * @param out list of tokens that are returned + * @param out parsed list of xml tokens * @throws CommonException when an error occurs (e.g. XML is not valid) */ static void parseMemory(const std::string& xmlIn, ext::deque<Token>& out); + /** + * Parses the string containing XML. + * @param xmlIn input XML + * @return parsed list of xml tokens + * @throws CommonException when an error occurs (e.g. XML is not valid) + */ + static ext::deque < Token > parseMemory ( const std::string & xmlIn ); + /** * Parses the file containing XML. * @param filename input XML - * @param out list of tokens that are returned + * @param out parsed list of xml tokens * @throws CommonException when an error occurs (e.g. file doesn't exist, XML is not valid) */ static void parseFile(const std::string& filename, ext::deque<Token>& out); - + + /** + * Parses the file containing XML. + * @param filename input XML + * @return parsed list of xml tokens + * @throws CommonException when an error occurs (e.g. file doesn't exist, XML is not valid) + */ + static ext::deque < Token > parseFile ( const std::string& filename ); + /** * Parses the XML from stdin. - * @param out list of tokens that are returned + * @param out parsed list of xml tokens + * @throws CommonException when an error occurs (e.g. XML is not valid) */ static void parseStdin(ext::deque<Token>& out); - + + /** + * Parses the XML from stdin. + * @return parsed list of xml tokens + * @throws CommonException when an error occurs (e.g. XML is not valid) + */ + static ext::deque < Token > parseStdin ( ); + /** * Parses the XML from stream. * @param in input XML - * @param out list of tokens that are returned + * @param out parsed list of xml tokens + * @throws CommonException when an error occurs (e.g. XML is not valid) */ static void parseStream(std::istream& in, ext::deque<Token>& out); + + /** + * Parses the XML from stream. + * @param in input XML + * @return parsed list of xml tokens + * @throws CommonException when an error occurs (e.g. XML is not valid) + */ + static ext::deque < Token > parseStream ( std::istream & in ); }; } /* namespace sax */ diff --git a/alib2xml/test-src/primitive/PrimitiveTest.cpp b/alib2xml/test-src/primitive/PrimitiveTest.cpp index ca2efbb4d1..8b1cd2a21e 100644 --- a/alib2xml/test-src/primitive/PrimitiveTest.cpp +++ b/alib2xml/test-src/primitive/PrimitiveTest.cpp @@ -24,11 +24,9 @@ void PrimitiveTest::testXMLParser() { { ext::deque<sax::Token> tokens = factory::XmlDataFactory::toTokens(primitive); std::cout << tokens << std::endl; - std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + std::string tmp = sax::SaxComposeInterface::composeMemory ( tokens ); - ext::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); + ext::deque<sax::Token> tokens2 = sax::SaxParseInterface::parseMemory ( tmp ); primitive::Primitive primitive2 = factory::XmlDataFactory::fromTokens (std::move(tokens2)); CPPUNIT_ASSERT( primitive == primitive2 ); diff --git a/alib2xml/test-src/sax/SaxTest.cpp b/alib2xml/test-src/sax/SaxTest.cpp index e3532c4236..983fd15b88 100644 --- a/alib2xml/test-src/sax/SaxTest.cpp +++ b/alib2xml/test-src/sax/SaxTest.cpp @@ -23,7 +23,7 @@ void SaxTest::testSax ( ) { std::cout << tokens << std::endl; std::string tmp2; - sax::SaxComposeInterface::printMemory ( tmp2, tokens ); + sax::SaxComposeInterface::composeMemory ( tmp2, tokens ); CPPUNIT_ASSERT ( tmp == tmp2 ); -- GitLab