From 4e313c5d80dd15e1f85bf5af64fd5495a4e60231 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 19 Oct 2017 22:45:57 +0200 Subject: [PATCH] wip on raw io --- alib2raw/src/RawApi.cpp | 15 --- alib2raw/src/RawApi.hpp | 25 ---- .../src/abstraction/RawReaderAbstraction.hpp | 31 +++++ .../src/abstraction/RawReaderRegistry.cpp | 25 ++++ .../src/abstraction/RawReaderRegistry.hpp | 68 ++++++++++ .../src/abstraction/RawWriterAbstraction.hpp | 30 +++++ .../src/abstraction/RawWriterRegistry.cpp | 20 +++ .../src/abstraction/RawWriterRegistry.hpp | 71 ++++++++++ alib2raw/src/core/rawApi.hpp | 18 +++ alib2raw/src/factory/RawDataFactory.hpp | 124 ++++++++++++++++++ alib2raw/src/registration/RawRegistration.hpp | 54 ++++++++ alib2raw/src/string/StringFromRawParser.cpp | 33 ----- alib2raw/src/string/StringFromRawParser.h | 28 ---- alib2raw/src/string/StringToRawComposer.cpp | 29 ---- alib2raw/src/string/StringToRawComposer.h | 35 ----- alib2raw/src/string/raw/LinearString.cpp | 17 +++ alib2raw/src/string/raw/LinearString.h | 44 +++++++ alib2raw/src/tree/TreeFromRawParser.cpp | 68 ---------- alib2raw/src/tree/TreeFromRawParser.h | 36 ----- alib2raw/src/tree/TreeToRawComposer.cpp | 51 ------- alib2raw/src/tree/TreeToRawComposer.h | 119 ----------------- alib2raw/src/tree/raw/UnrankedTree.cpp | 17 +++ alib2raw/src/tree/raw/UnrankedTree.h | 77 +++++++++++ araw2/makefile.conf | 6 +- araw2/src/araw.cpp | 95 ++++++-------- 25 files changed, 640 insertions(+), 496 deletions(-) delete mode 100644 alib2raw/src/RawApi.cpp delete mode 100644 alib2raw/src/RawApi.hpp create mode 100644 alib2raw/src/abstraction/RawReaderAbstraction.hpp create mode 100644 alib2raw/src/abstraction/RawReaderRegistry.cpp create mode 100644 alib2raw/src/abstraction/RawReaderRegistry.hpp create mode 100644 alib2raw/src/abstraction/RawWriterAbstraction.hpp create mode 100644 alib2raw/src/abstraction/RawWriterRegistry.cpp create mode 100644 alib2raw/src/abstraction/RawWriterRegistry.hpp create mode 100644 alib2raw/src/core/rawApi.hpp create mode 100644 alib2raw/src/factory/RawDataFactory.hpp create mode 100644 alib2raw/src/registration/RawRegistration.hpp delete mode 100644 alib2raw/src/string/StringFromRawParser.cpp delete mode 100644 alib2raw/src/string/StringFromRawParser.h delete mode 100644 alib2raw/src/string/StringToRawComposer.cpp delete mode 100644 alib2raw/src/string/StringToRawComposer.h create mode 100644 alib2raw/src/string/raw/LinearString.cpp create mode 100644 alib2raw/src/string/raw/LinearString.h delete mode 100644 alib2raw/src/tree/TreeFromRawParser.cpp delete mode 100644 alib2raw/src/tree/TreeFromRawParser.h delete mode 100644 alib2raw/src/tree/TreeToRawComposer.cpp delete mode 100644 alib2raw/src/tree/TreeToRawComposer.h create mode 100644 alib2raw/src/tree/raw/UnrankedTree.cpp create mode 100644 alib2raw/src/tree/raw/UnrankedTree.h diff --git a/alib2raw/src/RawApi.cpp b/alib2raw/src/RawApi.cpp deleted file mode 100644 index b6b6aaae88..0000000000 --- a/alib2raw/src/RawApi.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * RawApi.cpp - * - * Created on: Apr 1, 2013 - * Author: Jan Travnicek - */ - -#include "RawApi.hpp" - -namespace alib { - -const tree::TreeFromRawParser FromRawParsers::treeParser; -const string::StringFromRawParser FromRawParsers::stringParser; - -} /* namespace alib */ diff --git a/alib2raw/src/RawApi.hpp b/alib2raw/src/RawApi.hpp deleted file mode 100644 index b5389dc9f8..0000000000 --- a/alib2raw/src/RawApi.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * RawApi.hpp - * - * Created on: Dec 27, 2014 - * Author: Jan Travnicek - */ - -#ifndef RAW_API_HPP_ -#define RAW_API_HPP_ - -#include "tree/TreeFromRawParser.h" -#include "string/StringFromRawParser.h" - -namespace alib { - -class FromRawParsers { -public: - static const tree::TreeFromRawParser treeParser; - static const string::StringFromRawParser stringParser; - -}; - -} /* namespace alib */ - -#endif /* RAW_API_HPP_ */ diff --git a/alib2raw/src/abstraction/RawReaderAbstraction.hpp b/alib2raw/src/abstraction/RawReaderAbstraction.hpp new file mode 100644 index 0000000000..d7c726a27d --- /dev/null +++ b/alib2raw/src/abstraction/RawReaderAbstraction.hpp @@ -0,0 +1,31 @@ +/* + * RawReaderAbstraction.hpp + * + * Created on: 11. 7. 2017 + * Author: Jan Travnicek + */ + +#ifndef _RAW_READER_ABSTRACTION_HPP_ +#define _RAW_READER_ABSTRACTION_HPP_ + +#include <abstraction/BinaryOperationAbstraction.hpp> +#include <factory/RawDataFactory.hpp> + +namespace abstraction { + +template < class ReturnType > +class RawReaderAbstraction : public BinaryOperationAbstraction < ReturnType, const std::string &, std::string && > { +public: + virtual bool run ( ) override { + if ( this->isReady ( ) ) + return true; + + ReturnType res = alib::RawDataFactory::fromString ( std::get < 1 > ( this->m_params )->getRValueReference ( ) ); + this->m_data = std::move ( res ); + return true; + } +}; + +} /* namespace abstraction */ + +#endif /* _RAW_READER_ABSTRACTION_HPP_ */ diff --git a/alib2raw/src/abstraction/RawReaderRegistry.cpp b/alib2raw/src/abstraction/RawReaderRegistry.cpp new file mode 100644 index 0000000000..0463adb288 --- /dev/null +++ b/alib2raw/src/abstraction/RawReaderRegistry.cpp @@ -0,0 +1,25 @@ +/* + * RawReaderRegistry.cpp + * + * Created on: 21. 8. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/RawReaderRegistry.hpp> +#include <algorithm> +#include <typeinfo> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > RawReaderRegistry::getAbstraction ( const std::string & type ) { + for ( const std::pair < const std::string, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { + std::string entryType = ext::erase_template_info ( entry.first ); + if ( entryType == type ) + return entry.second->getAbstraction ( ); + } + + throw exception::CommonException ( "Entry " + type + " not available." ); + +} + +} /* namespace abstraction */ diff --git a/alib2raw/src/abstraction/RawReaderRegistry.hpp b/alib2raw/src/abstraction/RawReaderRegistry.hpp new file mode 100644 index 0000000000..18f3f498bc --- /dev/null +++ b/alib2raw/src/abstraction/RawReaderRegistry.hpp @@ -0,0 +1,68 @@ +/* + * RawReaderRegistry.hpp + * + * Created on: 11. 7. 2017 + * Author: Jan Travnicek + */ + +#ifndef _RAW_READER_REGISTRY_HPP_ +#define _RAW_READER_REGISTRY_HPP_ + +#include <memory> +#include <string> +#include <map> + +#include <exception/CommonException.h> +#include <abstraction/OperationAbstraction.hpp> +#include <factory/RawDataFactory.hpp> + +namespace abstraction { + +class RawReaderRegistry { + class Entry { + public: + virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0; + + }; + + template < class Return > + class EntryImpl : public Entry { + public: + virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override; + + }; + + static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ) { + static ext::map < std::string, std::unique_ptr < Entry > > readers; + return readers; + } + +public: + template < class ReturnType > + static void registerRawReader ( std::string type ) { + getEntries ( ).insert ( std::make_pair ( std::move ( type ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); + } + + template < class ReturnType > + static void registerRawReader ( ) { + std::string type = ext::to_string < ReturnType > ( ); + registerRawReader < ReturnType > ( std::move ( type ) ); + } + + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & group ); +}; + +} /* namespace abstraction */ + +#include <abstraction/RawReaderAbstraction.hpp> + +namespace abstraction { + +template < class Return > +std::shared_ptr < abstraction::OperationAbstraction > RawReaderRegistry::EntryImpl < Return >::getAbstraction ( ) const { + return std::make_shared < abstraction::RawReaderAbstraction < Return > > ( ); +} + +} /* namespace abstraction */ + +#endif /* _RAW_READER_REGISTRY_HPP_ */ diff --git a/alib2raw/src/abstraction/RawWriterAbstraction.hpp b/alib2raw/src/abstraction/RawWriterAbstraction.hpp new file mode 100644 index 0000000000..cbcc035d6e --- /dev/null +++ b/alib2raw/src/abstraction/RawWriterAbstraction.hpp @@ -0,0 +1,30 @@ +/* + * RawWriterAbstraction.hpp + * + * Created on: 11. 7. 2017 + * Author: Jan Travnicek + */ + +#ifndef _RAW_WRITER_ABSTRACTION_HPP_ +#define _RAW_WRITER_ABSTRACTION_HPP_ + +#include <abstraction/UnaryOperationAbstraction.hpp> +#include <factory/RawDataFactory.hpp> + +namespace abstraction { + +template < class ParamType > +class RawWriterAbstraction : public UnaryOperationAbstraction < std::string, const ParamType & > { +public: + virtual bool run ( ) override { + if ( ! this->inputsReady ( ) ) + return false; + + this->m_data = alib::RawDataFactory::toString ( std::get < 0 > ( this->m_params )->getConstValueReference ( ) ); + return true; + } +}; + +} /* namespace abstraction */ + +#endif /* _RAW_WRITER_ABSTRACTION_HPP_ */ diff --git a/alib2raw/src/abstraction/RawWriterRegistry.cpp b/alib2raw/src/abstraction/RawWriterRegistry.cpp new file mode 100644 index 0000000000..24e22033b3 --- /dev/null +++ b/alib2raw/src/abstraction/RawWriterRegistry.cpp @@ -0,0 +1,20 @@ +/* + * RawWriterRegistry.cpp + * + * Created on: 28. 8. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/RawWriterRegistry.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > RawWriterRegistry::getAbstraction ( const std::string & param ) { + auto type = getEntries ( ).find ( param ); + if ( type == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + param + " not available." ); + + return type->second->getAbstraction ( ); +} + +} /* namespace abstraction */ diff --git a/alib2raw/src/abstraction/RawWriterRegistry.hpp b/alib2raw/src/abstraction/RawWriterRegistry.hpp new file mode 100644 index 0000000000..c0904074fa --- /dev/null +++ b/alib2raw/src/abstraction/RawWriterRegistry.hpp @@ -0,0 +1,71 @@ +/* + * RawWriterRegistry.hpp + * + * Created on: 28. 8. 2017 + * Author: Jan Travnicek + */ + +#ifndef _RAW_WRITER_REGISTRY_HPP_ +#define _RAW_WRITER_REGISTRY_HPP_ + +#include <memory> +#include <string> +#include <set> +#include <map> + +#include <exception/CommonException.h> +#include <abstraction/OperationAbstraction.hpp> + +namespace abstraction { + +class RawWriterRegistry { + class Entry { + public: + virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0; + + }; + + template < class Param > + class EntryImpl : public Entry { + public: + EntryImpl ( ) { + } + + virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override; + }; + + static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ) { + static ext::map < std::string, std::unique_ptr < Entry > > writers; + return writers; + } + +public: + template < class ParamType > + static void registerRawWriter ( std::string param ) { + getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); + } + + template < class ParamType > + static void registerRawWriter ( ) { + std::string param = ext::to_string < ParamType > ( ); + registerRawWriter < ParamType > ( std::move ( param ) ); + } + + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param ); +}; + +} /* namespace abstraction */ + +#include <abstraction/RawWriterAbstraction.hpp> + +namespace abstraction { + +template < class Param > +std::shared_ptr < abstraction::OperationAbstraction > RawWriterRegistry::EntryImpl < Param >::getAbstraction ( ) const { + return std::make_shared < abstraction::RawWriterAbstraction < const Param & > > ( ); +} + + +} /* namespace abstraction */ + +#endif /* _RAW_WRITER_REGISTRY_HPP_ */ diff --git a/alib2raw/src/core/rawApi.hpp b/alib2raw/src/core/rawApi.hpp new file mode 100644 index 0000000000..a62992b97c --- /dev/null +++ b/alib2raw/src/core/rawApi.hpp @@ -0,0 +1,18 @@ +/* + * RawApi.hpp + * + * Created on: Apr 1, 2013 + * Author: Jan Travnicek + */ + +#ifndef RAW_API_HPP_ +#define RAW_API_HPP_ + +namespace alib { + +template < typename T, typename Enable = void > +struct rawApi { }; + +} /* namespace alib */ + +#endif /* RAW_API_HPP_ */ diff --git a/alib2raw/src/factory/RawDataFactory.hpp b/alib2raw/src/factory/RawDataFactory.hpp new file mode 100644 index 0000000000..a2e38cfdcf --- /dev/null +++ b/alib2raw/src/factory/RawDataFactory.hpp @@ -0,0 +1,124 @@ +/* + * RawDataFactory.h + * + * Created on: Nov 23, 2013 + * Author: Jan Travnicek + */ + +#ifndef RAW_DATA_FACTORY +#define RAW_DATA_FACTORY + +#include <set> +#include "exception/CommonException.h" +#include <core/rawApi.hpp> +#include <fstream> +#include <sstream> + +namespace alib { + +class RawDataFactory { +public: + class fromFile { + const std::string & filename; + + public: + fromFile ( const std::string & file ) : filename ( file ) { + } + + template < class T > + operator T ( ) { + std::ifstream fileStream ( filename ); + + return fromStream ( fileStream ); + } + }; + + class fromRaw { + const std::string & string; + + public: + fromRaw ( const std::string & str ) : string ( str ) { + } + + template < class T > + operator T ( ) { + std::stringstream stringStream ( string ); + + return fromStream ( stringStream ); + } + }; + + class fromString { + const std::string & string; + + public: + fromString ( const std::string & str ) : string ( str ) { + } + + template < class T > + operator T ( ) { + std::stringstream stringStream ( string ); + + return fromStream ( stringStream ); + } + }; + + class fromStdin { + public: + template < class T > + operator T ( ) { + return fromStream ( std::cin ); + } + }; + + class fromStream { + std::istream & in; + + public: + fromStream ( std::istream & i ) : in ( i ) { + } + + template < class T > + operator T ( ) { + if ( in.peek ( ) == EOF ) + throw exception::CommonException ( "Empty stream" ); + + T res = alib::rawApi < T >::parse ( in ); + + while ( isspace ( in.peek ( ) ) ) + in.get ( ); + + if ( in.peek ( ) != EOF ) + throw exception::CommonException ( "Unexpected characters at the end of the stream" ); + + return res; + } + }; + + template < class T > + static void toFile ( const T & data, const std::string & filename) { + std::ofstream fileStream ( filename ); + toStream < T > ( data, fileStream ); + } + + template < class T > + static std::string toString ( const T & data ) { + std::stringstream stringStream; + toStream < T > ( data, stringStream ); + return stringStream.str ( ); + } + + template < class T > + static void toStdout ( const T & data ) { + toStream < T > ( data, std::cout ); + } + + template < class T > + static void toStream ( const T & data, std::ostream & out ) { + alib::rawApi < T >::compose ( out, data ); + } +}; + +} /* namespace alib */ + +#endif /* RAW_DATA_FACTORY */ diff --git a/alib2raw/src/registration/RawRegistration.hpp b/alib2raw/src/registration/RawRegistration.hpp new file mode 100644 index 0000000000..e895065a34 --- /dev/null +++ b/alib2raw/src/registration/RawRegistration.hpp @@ -0,0 +1,54 @@ +#ifndef _RAW_REGISTRATION_HPP_ +#define _RAW_REGISTRATION_HPP_ + +#include <core/xmlApi.hpp> + +#include <abstraction/RawReaderRegistry.hpp> +#include <abstraction/RawWriterRegistry.hpp> + +#include <abstraction/AlgorithmRegistry.hpp> + +namespace raw { + +class Parse { +public: + static std::shared_ptr < abstraction::OperationAbstraction > abstractionFromString ( const std::string & type, const std::string & ) { + return abstraction::RawReaderRegistry::getAbstraction ( type ); + } + +}; + +class Compose { +public: + template < class Type > + static std::shared_ptr < abstraction::OperationAbstraction > abstractionFromType ( const Type & ) { + return abstraction::RawWriterRegistry::getAbstraction ( ext::to_string < Type > ( ) ); + } + +}; + +} /* namespace raw */ + +namespace registration { + +template < class Type > +class RawReaderRegister { +public: + RawReaderRegister ( ) { + abstraction::RawReaderRegistry::registerRawReader < Type > ( ); + abstraction::AlgorithmRegistry::registerWrapper < raw::Parse, const std::string &, const std::string & > ( raw::Parse::abstractionFromString, std::array < std::string, 2 > { } ); + } +}; + +template < class Type > +class RawWriterRegister { +public: + RawWriterRegister ( ) { + abstraction::RawWriterRegistry::registerRawWriter < Type > ( ); + abstraction::AlgorithmRegistry::registerWrapper < raw::Compose, const Type & > ( raw::Compose::abstractionFromType, std::array < std::string, 1 > { } ); + } +}; + +} /* namespace registration */ + +#endif // _RAW_REGISTRATION_HPP_ diff --git a/alib2raw/src/string/StringFromRawParser.cpp b/alib2raw/src/string/StringFromRawParser.cpp deleted file mode 100644 index 79378443be..0000000000 --- a/alib2raw/src/string/StringFromRawParser.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * StringFromRawParser.cpp - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#include <exception/CommonException.h> -#include <string/String.h> -#include <string/StringClasses.h> -#include <alphabet/Symbol.h> -#include <sax/FromXMLParserHelper.h> -#include "StringFromRawParser.h" - -namespace string { - -String StringFromRawParser::parseString(std::istream_iterator<char>& input) const { - return parseString(input, ext::set<FEATURES>({FEATURES::LINEAR})); -} - -String StringFromRawParser::parseString(std::istream_iterator<char>& input, const ext::set<FEATURES>& features) const { - ext::vector<alphabet::Symbol> data; - for(;input != std::istream_iterator<char>(); input++) { - data.push_back(alphabet::Symbol(*input)); - } - LinearString < alphabet::Symbol > string { data }; - - if(features.count(FEATURES::LINEAR)) return String{string}; - - throw exception::CommonException("Invalid input"); -} - -} /* namespace string */ diff --git a/alib2raw/src/string/StringFromRawParser.h b/alib2raw/src/string/StringFromRawParser.h deleted file mode 100644 index 86f73f0143..0000000000 --- a/alib2raw/src/string/StringFromRawParser.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * StringFromRawParser.h - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#ifndef STRING_FROM_RAW_PARSER -#define STRING_FROM_RAW_PARSER - -#include <iterator> -#include <set> -#include <string/StringFeatures.h> - -namespace string { - -class StringFromRawParser { -public: - StringFromRawParser() {} - - String parseString(std::istream_iterator<char>& input) const; - String parseString(std::istream_iterator<char>& input, const ext::set<FEATURES>& features) const; - -}; - -} /* namespace string */ - -#endif /* STRING_FROM_RAW_PARSER */ diff --git a/alib2raw/src/string/StringToRawComposer.cpp b/alib2raw/src/string/StringToRawComposer.cpp deleted file mode 100644 index df55d4e72f..0000000000 --- a/alib2raw/src/string/StringToRawComposer.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * StringToRawComposer.cpp - * - * Created on: Nov 16, 2014 - * Author: Jan Travnicek - */ - -#include <string/StringClasses.h> -#include "StringToRawComposer.h" - -#include <registration/AlgoRegistration.hpp> - -namespace string { - -void StringToRawComposer::compose(std::ostream& out, const String& string) { - dispatch(out, string.getData()); -} - -template < class SymbolType > -void StringToRawComposer::compose(std::ostream& out, const LinearString < SymbolType > & string) { - for(const SymbolType & symbol : string.getContent()) { - out << ext::to_string ( symbol ); - } -} - -auto StringToRawComposerLinearString = registration::OverloadRegister < StringToRawComposer, void, LinearString < > >(StringToRawComposer::compose); - -} /* namespace automaton */ - diff --git a/alib2raw/src/string/StringToRawComposer.h b/alib2raw/src/string/StringToRawComposer.h deleted file mode 100644 index 55620be04a..0000000000 --- a/alib2raw/src/string/StringToRawComposer.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * StringToRawComposer.h - * - * Created on: Nov 16, 2014 - * Author: Jan Travnicek - */ - -#ifndef STRING_TO_RAW_COMPOSER_H_ -#define STRING_TO_RAW_COMPOSER_H_ - -#include <deque> -#include <vector> -#include <core/multipleDispatch.hpp> -#include <string/String.h> -#include <string/StringFeatures.h> -#include <alphabet/SymbolFeatures.h> - -namespace string { - -/** - * This class contains methods to print XML representation of string to the output stream. - */ -class StringToRawComposer : public alib::SingleDispatchFirstStaticParam<StringToRawComposer, void, std::ostream&, const StringBase &> { -public: - static void compose(std::ostream& out, const String& string); - - template < class SymbolType > - static void compose(std::ostream& out, const LinearString < SymbolType > & string); - -}; - -} /* namespace string */ - -#endif /* STRING_TO_RAW_COMPOSER_H_ */ - diff --git a/alib2raw/src/string/raw/LinearString.cpp b/alib2raw/src/string/raw/LinearString.cpp new file mode 100644 index 0000000000..43cbe28762 --- /dev/null +++ b/alib2raw/src/string/raw/LinearString.cpp @@ -0,0 +1,17 @@ +/* + * LinearString.cpp + * + * Created on: Sep 27, 2017 + * Author: Jan Travnicek + */ + +#include "LinearString.h" + +#include <registration/RawRegistration.hpp> + +namespace { + +static auto stringWrite = registration::RawWriterRegister < string::LinearString < > > ( ); +static auto stringReader = registration::RawReaderRegister < string::LinearString < > > ( ); + +} /* namespace */ diff --git a/alib2raw/src/string/raw/LinearString.h b/alib2raw/src/string/raw/LinearString.h new file mode 100644 index 0000000000..e23d1a56f9 --- /dev/null +++ b/alib2raw/src/string/raw/LinearString.h @@ -0,0 +1,44 @@ +/* + * LinearString.h + * + * Created on: Sep 27, 2017 + * Author: Jan Travnicek + */ + +#ifndef _RAW_LINEAR_RAW_H_ +#define _RAW_LINEAR_RAW_H_ + +#include <string/LinearString.h> +#include <core/rawApi.hpp> + +namespace alib { + +template < class SymbolType > +struct rawApi < string::LinearString < SymbolType > > { + static string::LinearString < SymbolType > parse ( std::istream & input ); + static void compose ( std::ostream & output, const string::LinearString < SymbolType > & string ); +}; + +template < class SymbolType > +string::LinearString < SymbolType > rawApi < string::LinearString < SymbolType > >::parse ( std::istream & input_stream ) { + ext::vector < SymbolType > data; + + std::istream_iterator < char > input ( input_stream ); + input_stream >> std::noskipws; + + for ( ; input != std::istream_iterator < char > ( ); ++ input ) { + data.push_back ( SymbolType ( * input ) ); + } + return string::LinearString < SymbolType > { data }; +} + +template < class SymbolType > +void rawApi < string::LinearString < SymbolType > >::compose ( std::ostream & output, const string::LinearString < SymbolType > & string ) { + for(const SymbolType & symbol : string.getContent()) { + output << ext::to_string ( symbol ); + } +} + +} /* namespace alib */ + +#endif /* _RAW_LINEAR_RAW_H_ */ diff --git a/alib2raw/src/tree/TreeFromRawParser.cpp b/alib2raw/src/tree/TreeFromRawParser.cpp deleted file mode 100644 index 84da2ecc53..0000000000 --- a/alib2raw/src/tree/TreeFromRawParser.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * TreeFromRawParser.cpp - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#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> -#include "TreeFromRawParser.h" - -namespace tree { - -Tree TreeFromRawParser::parseTree(ext::deque<sax::Token>::iterator& input) const { - return parseTree(input, ext::set<FEATURES>({FEATURES::RANKED_TREE, FEATURES::PREFIX_RANKED_TREE, FEATURES::PREFIX_RANKED_BAR_TREE, FEATURES::UNRANKED_TREE})); -} - -Tree TreeFromRawParser::parseTree(ext::deque<sax::Token>::iterator& input, const ext::set<FEATURES>& features) const { - UnrankedTree < alphabet::Symbol > tree(this->parseContent(input)); - - if(features.count(FEATURES::UNRANKED_TREE)) return Tree{tree}; - - if(features.count(FEATURES::PREFIX_RANKED_TREE)) return Tree{PrefixRankedTree < alphabet::Symbol, primitive::Unsigned > {RankedTree < alphabet::Symbol, primitive::Unsigned > {tree}}}; - - if(features.count(FEATURES::PREFIX_RANKED_BAR_TREE)) return Tree{PrefixRankedBarTree < alphabet::Symbol, primitive::Unsigned > {alphabet::Symbol{alphabet::BarSymbol{}}, RankedTree < alphabet::Symbol, primitive::Unsigned > {tree}}}; - - if(features.count(FEATURES::RANKED_TREE)) return Tree{RankedTree < alphabet::Symbol, primitive::Unsigned > {tree}}; - - throw exception::CommonException("Invalid input"); -} - -RankedTreeWrapper TreeFromRawParser::parseRankedTree(ext::deque<sax::Token>::iterator& input) const { - return parseRankedTree(input, ext::set<FEATURES>({FEATURES::RANKED_TREE, FEATURES::PREFIX_RANKED_TREE, FEATURES::PREFIX_RANKED_BAR_TREE})); -} - -RankedTreeWrapper TreeFromRawParser::parseRankedTree(ext::deque<sax::Token>::iterator& input, const ext::set<FEATURES>& features) const { - UnrankedTree < alphabet::Symbol > tree(this->parseContent(input)); - - if(features.count(FEATURES::RANKED_TREE)) return RankedTreeWrapper{RankedTree < alphabet::Symbol, primitive::Unsigned > {tree}}; - - 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}}}; - - throw exception::CommonException("Invalid input"); -} - -ext::tree < alphabet::Symbol > TreeFromRawParser::parseContent(ext::deque<sax::Token>::iterator& input) const { - if (sax::FromXMLParserHelper::isTokenType(input, sax::Token::TokenType::START_ELEMENT)) { - ext::tree < alphabet::Symbol > node ( alphabet::Symbol(sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::START_ELEMENT)), {}); - while (sax::FromXMLParserHelper::isTokenType(input, sax::Token::TokenType::START_ELEMENT) || sax::FromXMLParserHelper::isTokenType(input, sax::Token::TokenType::CHARACTER)) { - node.push_back(node.root( ), this->parseContent(input)); - } - sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::END_ELEMENT); - return node; - } else if(sax::FromXMLParserHelper::isTokenType(input, sax::Token::TokenType::CHARACTER)) { - return ext::tree < alphabet::Symbol > (alphabet::Symbol(sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER)), {}); - } else { - throw exception::CommonException("Invalid token stream"); - } -} - -} /* namespace tree */ diff --git a/alib2raw/src/tree/TreeFromRawParser.h b/alib2raw/src/tree/TreeFromRawParser.h deleted file mode 100644 index 5d60c40f91..0000000000 --- a/alib2raw/src/tree/TreeFromRawParser.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * TreeFromRawParser.h - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#ifndef TREE_FROM_RAW_PARSER -#define TREE_FROM_RAW_PARSER - -#include <set> -#include <deque> -#include <tree> -#include <sax/Token.h> -#include <tree/TreeFeatures.h> -#include <alphabet/Symbol.h> - -namespace tree { - -class TreeFromRawParser { -public: - TreeFromRawParser() {} - - Tree parseTree(ext::deque<sax::Token>::iterator& input) const; - Tree parseTree(ext::deque<sax::Token>::iterator& input, const ext::set<FEATURES>& features) const; - - RankedTreeWrapper parseRankedTree(ext::deque<sax::Token>::iterator& input) const; - RankedTreeWrapper parseRankedTree(ext::deque<sax::Token>::iterator& input, const ext::set<FEATURES>& features) const; - -private: - ext::tree < alphabet::Symbol > parseContent(ext::deque<sax::Token>::iterator& input) const; -}; - -} /* namespace tree */ - -#endif /* TREE_FROM_RAW_PARSER */ diff --git a/alib2raw/src/tree/TreeToRawComposer.cpp b/alib2raw/src/tree/TreeToRawComposer.cpp deleted file mode 100644 index 3cdb0e8cc3..0000000000 --- a/alib2raw/src/tree/TreeToRawComposer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * TreeToRawComposer.cpp - * - * Created on: Nov 16, 2014 - * Author: Jan Travnicek - */ - -#include <tree/TreeException.h> -#include <tree/TreeClasses.h> -#include "TreeToRawComposer.h" - -#include <registration/AlgoRegistration.hpp> - -namespace tree { - -void TreeToRawComposer::compose(ext::deque<sax::Token>& out, const Tree& tree) { - dispatch(out, tree.getData()); -} - -template < class SymbolType, class RankType > -void TreeToRawComposer::compose(ext::deque<sax::Token>& out, const RankedTree < SymbolType, RankType > & tree) { - composeNode(out, tree.getContent()); -} - -auto TreeToRawComposerRankedTree = registration::OverloadRegister < TreeToRawComposer, void, RankedTree < > >(TreeToRawComposer::compose); - -template < class SymbolType, class RankType > -void TreeToRawComposer::compose(ext::deque<sax::Token>& out, const PrefixRankedTree < SymbolType, RankType > & tree) { - unsigned i = 0; - composePrefixRankedNotation(out, i, tree.getContent()); -} - -auto TreeToRawComposerPrefixRankedTree = registration::OverloadRegister < TreeToRawComposer, void, PrefixRankedTree < > >(TreeToRawComposer::compose); - -template < class SymbolType > -void TreeToRawComposer::compose(ext::deque<sax::Token>& out, const PrefixRankedBarTree < SymbolType > & tree) { - unsigned i = 0; - composePrefixRankedBarNotation(out, i, tree.getContent()); -} - -auto TreeToRawComposerPrefixRankedBarTree = registration::OverloadRegister < TreeToRawComposer, void, PrefixRankedBarTree < > >(TreeToRawComposer::compose); - -template < class SymbolType > -void TreeToRawComposer::compose(ext::deque<sax::Token>& out, const UnrankedTree < SymbolType > & tree) { - composeNode(out, tree.getContent()); -} - -auto TreeToRawComposerUnrankedTree = registration::OverloadRegister < TreeToRawComposer, void, UnrankedTree < > >(TreeToRawComposer::compose); - -} /* namespace automaton */ - diff --git a/alib2raw/src/tree/TreeToRawComposer.h b/alib2raw/src/tree/TreeToRawComposer.h deleted file mode 100644 index 7dd2072851..0000000000 --- a/alib2raw/src/tree/TreeToRawComposer.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * TreeToRawComposer.h - * - * Created on: Nov 16, 2014 - * Author: Jan Travnicek - */ - -#ifndef TREE_TO_RAW_COMPOSER_H_ -#define TREE_TO_RAW_COMPOSER_H_ - -#include <deque> -#include <vector> -#include <core/multipleDispatch.hpp> -#include <tree/Tree.h> -#include <tree/TreeFeatures.h> -#include <alphabet/SymbolFeatures.h> -#include <sax/Token.h> -#include <common/ranked_symbol.hpp> - -namespace tree { - -/** - * This class contains methods to print XML representation of tree to the output stream. - */ -class TreeToRawComposer : public alib::SingleDispatchFirstStaticParam<TreeToRawComposer, void, ext::deque<sax::Token>&, const TreeBase &> { -public: - static void compose(ext::deque<sax::Token>& out, const Tree& tree); - - template < class SymbolType, class RankType > - static void compose(ext::deque<sax::Token>& out, const RankedTree < SymbolType, RankType > & tree); - template < class SymbolType, class RankType > - static void compose(ext::deque<sax::Token>& out, const PrefixRankedTree < SymbolType, RankType > & tree); - template < class SymbolType > - static void compose(ext::deque<sax::Token>& out, const PrefixRankedBarTree < SymbolType > & tree); - template < class SymbolType > - static void compose(ext::deque<sax::Token>& out, const UnrankedTree < SymbolType > & tree); - -private: - template < class SymbolType, class RankType > - static void composeNode(ext::deque<sax::Token>& out, const ext::tree < common::ranked_symbol < SymbolType, RankType > > & node); - template < class SymbolType, class RankType > - static void composePrefixRankedNotation(ext::deque<sax::Token>& out, unsigned& index, const ext::vector<common::ranked_symbol < SymbolType, RankType > >& notation); - template < class SymbolType, class RankType > - static void composePrefixRankedBarNotation(ext::deque<sax::Token>& out, unsigned& index, const ext::vector<common::ranked_symbol < SymbolType, RankType > >& notation); - template < class SymbolType > - static void composeNode(ext::deque<sax::Token>& out, const ext::tree < SymbolType > & node); -}; - -template < class SymbolType, class RankType > -void TreeToRawComposer::composeNode(ext::deque<sax::Token>& out, const ext::tree < common::ranked_symbol < SymbolType, RankType > > & node) { - if(node.getChildren().size() == 0) { - out.emplace_back(sax::Token(ext::to_string ( node.getData ( ) ), sax::Token::TokenType::CHARACTER)); - } else { - out.emplace_back(sax::Token( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::START_ELEMENT)); - for(const ext::tree < common::ranked_symbol < SymbolType, RankType > > & child : node.getChildren()) { - composeNode(out, child); - } - - out.emplace_back(sax::Token( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::END_ELEMENT)); - } -} - -template < class SymbolType, class RankType > -void TreeToRawComposer::composePrefixRankedNotation(ext::deque<sax::Token>& out, unsigned& index, const ext::vector<common::ranked_symbol < SymbolType, RankType > > & notation) { - unsigned size = ( unsigned ) notation[index].getRank(); - unsigned root = index; - if(size == 0) { - out.emplace_back(sax::Token( ext::to_string ( notation[root] ), sax::Token::TokenType::CHARACTER)); - index += 1; - } else { - out.emplace_back(sax::Token( ext::to_string ( notation[root] ), sax::Token::TokenType::START_ELEMENT)); - - index += 1; - for(unsigned i = 0; i < size; ++i) { - composePrefixRankedNotation(out, index, notation); - } - - out.emplace_back(sax::Token( ext::to_string ( notation[root] ), sax::Token::TokenType::END_ELEMENT)); - } -} - -template < class SymbolType, class RankType > -void TreeToRawComposer::composePrefixRankedBarNotation(ext::deque<sax::Token>& out, unsigned& index, const ext::vector<common::ranked_symbol < SymbolType, RankType > > & notation) { - unsigned size = ( unsigned ) notation[index].getRank(); - unsigned root = index; - if(size == 0) { - out.emplace_back(sax::Token( ext::to_string ( notation[root] ), sax::Token::TokenType::CHARACTER)); - index += 2; - } else { - out.emplace_back(sax::Token( ext::to_string ( notation[root] ), sax::Token::TokenType::START_ELEMENT)); - - index += 1; - for(unsigned i = 0; i < size; i++) { - composePrefixRankedBarNotation(out, index, notation); - } - index += 1; - - out.emplace_back(sax::Token(ext::to_string ( notation[root] ), sax::Token::TokenType::END_ELEMENT)); - } -} - -template < class SymbolType > -void TreeToRawComposer::composeNode(ext::deque<sax::Token>& out, const ext::tree < SymbolType > & node) { - if(node.getChildren().size() == 0) { - - } else { - out.emplace_back(sax::Token( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::START_ELEMENT)); - for(const ext::tree < SymbolType > & child : node.getChildren()) { - composeNode(out, child); - } - - out.emplace_back(sax::Token(ext::to_string ( node.getData ( ) ), sax::Token::TokenType::END_ELEMENT)); - } -} - -} /* namespace tree */ - -#endif /* TREE_TO_RAW_COMPOSER_H_ */ - diff --git a/alib2raw/src/tree/raw/UnrankedTree.cpp b/alib2raw/src/tree/raw/UnrankedTree.cpp new file mode 100644 index 0000000000..b5a2d2492d --- /dev/null +++ b/alib2raw/src/tree/raw/UnrankedTree.cpp @@ -0,0 +1,17 @@ +/* + * UnrankedTree.cpp + * + * Created on: Sep 27, 2017 + * Author: Jan Travnicek + */ + +#include "UnrankedTree.h" + +#include <registration/RawRegistration.hpp> + +namespace { + +static auto treeWrite = registration::RawWriterRegister < tree::UnrankedTree < > > ( ); +static auto treeReader = registration::RawReaderRegister < tree::UnrankedTree < > > ( ); + +} /* namespace */ diff --git a/alib2raw/src/tree/raw/UnrankedTree.h b/alib2raw/src/tree/raw/UnrankedTree.h new file mode 100644 index 0000000000..5f39ad8c79 --- /dev/null +++ b/alib2raw/src/tree/raw/UnrankedTree.h @@ -0,0 +1,77 @@ +/* + * UnrankedTree.h + * + * Created on: Sep 27, 2017 + * Author: Jan Travnicek + */ + +#ifndef _RAW_UNRANKED_TREE_H_ +#define _RAW_UNRANKED_TREE_H_ + +#include <tree/unranked/UnrankedTree.h> +#include <sax/SaxParseInterface.h> +#include <sax/SaxComposeInterface.h> +#include <core/rawApi.hpp> + +namespace alib { + +template < class SymbolType > +struct rawApi < tree::UnrankedTree < SymbolType > > { +private: + static ext::tree < SymbolType > parseContent ( ext::deque < sax::Token >::iterator & input ); + static void composeContent ( ext::deque < sax::Token > & out, const ext::tree < SymbolType > & node ); + +public: + static tree::UnrankedTree < SymbolType > parse ( std::istream & input ); + static void compose ( std::ostream & output, const tree::UnrankedTree < SymbolType > & tree ); +}; + +template < class SymbolType > +tree::UnrankedTree < SymbolType > rawApi < tree::UnrankedTree < SymbolType > >::parse ( std::istream & input ) { + ext::deque < sax::Token > tokens; + sax::SaxParseInterface::parseStream ( input, tokens ); + ext::deque < sax::Token >::iterator iter = tokens.begin ( ); + return tree::UnrankedTree < SymbolType > ( parseContent ( iter ) ); +} + +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 ); +} + +template < class SymbolType > +ext::tree < SymbolType > rawApi < tree::UnrankedTree < SymbolType > >::parseContent ( ext::deque < sax::Token >::iterator & input ) { + if ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) { + ext::tree < SymbolType > node ( SymbolType ( sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::START_ELEMENT ) ), { } ); + while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) || sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::CHARACTER ) ) { + node.push_back(node.root( ), parseContent ( input ) ); + } + sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::END_ELEMENT ); + return node; + } else if ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::CHARACTER ) ) { + return ext::tree < SymbolType > ( SymbolType ( sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ) ), { } ); + } else { + throw exception::CommonException ( "Invalid token stream" ); + } +} + +template < class SymbolType > +void rawApi < tree::UnrankedTree < SymbolType > >::composeContent ( ext::deque < sax::Token > & out, const ext::tree < SymbolType > & node ) { + if ( node.getChildren ( ).size ( ) == 0 ) { + out.emplace_back ( sax::Token ( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::CHARACTER ) ); + } else { + out.emplace_back ( sax::Token ( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::START_ELEMENT ) ); + + for ( const ext::tree < SymbolType > & child : node.getChildren ( ) ) { + composeContent ( out, child ); + } + + out.emplace_back ( sax::Token ( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::END_ELEMENT ) ); + } +} + +} /* namespace alib */ + +#endif /* _RAW_UNRANKED_TREE_H_ */ diff --git a/araw2/makefile.conf b/araw2/makefile.conf index 4015c357ed..b268f9e5d7 100644 --- a/araw2/makefile.conf +++ b/araw2/makefile.conf @@ -1,4 +1,4 @@ EXECUTABLE:=araw2 -LINK_PATHS=../alib2raw/ ../alib2data/ ../alib2xml/ ../alib2measure/ ../alib2common/ ../alib2std/ -LINK_LIBRARIES=alib2raw alib2data alib2xml alib2measure alib2common alib2std xml2 -INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2raw/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2xml/src/ \$$(SOURCES_BASE_DIR)/../../alib2measure/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ +LINK_PATHS=../alib2cli/ ../alib2raw/ ../alib2data/ ../alib2xml/ ../alib2measure/ ../alib2common/ ../alib2std/ +LINK_LIBRARIES=alib2cli alib2raw alib2data alib2xml alib2measure alib2common alib2std xml2 +INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2cli/src/ \$$(SOURCES_BASE_DIR)/../../alib2xml/src/ \$$(SOURCES_BASE_DIR)/../../alib2measure/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ diff --git a/araw2/src/araw.cpp b/araw2/src/araw.cpp index ac9900a2c4..60f3ae9850 100644 --- a/araw2/src/araw.cpp +++ b/araw2/src/araw.cpp @@ -8,18 +8,12 @@ #include <tclap/CmdLine.h> #include <global/GlobalData.h> #include <measure> -#include <string> -#include <sax/FromXMLParserHelper.h> -#include <fstream> + #include <exception/CommonException.h> -#include <RawApi.hpp> +#include <lexer/Lexer.h> +#include <parser/Parser.h> + #include <factory/XmlDataFactory.hpp> -#include <sax/SaxParseInterface.h> -#include <sax/ParserException.h> -#include <tree/Tree.h> -#include <tree/TreeToRawComposer.h> -#include <string/String.h> -#include <string/StringToRawComposer.h> int main(int argc, char** argv) { try { @@ -62,65 +56,58 @@ int main(int argc, char** argv) { if(measure.isSet()) common::GlobalData::measure = true; - measurements::start("Overal", measurements::Type::OVERALL); - measurements::start("Input read", measurements::Type::AUXILIARY); - - if(tree_from_raw.getValue()) { - ext::deque<sax::Token> tokens = sax::FromXMLParserHelper::parseInput(input); + cli::Environment environment; + environment.setBinding ( "stdin", input.getValue ( ) ); + environment.setBinding ( "stdout", "-" ); - ext::deque<sax::Token>::iterator iter = tokens.begin(); - tree::Tree tree = alib::FromRawParsers::treeParser.parseTree(iter); + measurements::start ( "Overal", measurements::Type::OVERALL ); + measurements::start ( "Input read", measurements::Type::AUXILIARY ); - measurements::end(); - measurements::start("Output write", measurements::Type::AUXILIARY); + std::string inputCli; + if ( tree_from_raw.getValue ( ) || string_from_raw.getValue ( ) ) + inputCli = "execute cli::builtin::ReadFile #stdin > $input"; + else if ( tree_to_raw.getValue ( ) || string_to_raw.getValue ( ) ) + inputCli = "execute <#stdin > $input"; - alib::XmlDataFactory::toStdout(tree); - } else if(tree_to_raw.getValue()) { - tree::Tree tree = alib::XmlDataFactory::fromTokens (sax::FromXMLParserHelper::parseInput(input)); + cli::Parser parser = cli::Parser ( cli::Lexer ( inputCli ) ); + parser.parse ( )->run ( environment ); - measurements::end(); - measurements::start("Output write", measurements::Type::AUXILIARY); + measurements::end ( ); + measurements::start ( "Algorithm", measurements::Type::MAIN ); - ext::deque<sax::Token> tokens2; - tree::TreeToRawComposer::compose(tokens2, tree); - sax::SaxComposeInterface::printStdout(tokens2); + if(tree_from_raw.getValue()) { + parser = cli::Parser ( cli::Lexer ( "execute raw::Parse tree::UnrankedTree $input > $output" ) ); + } else if(tree_to_raw.getValue()) { + parser = cli::Parser ( cli::Lexer ( "execute raw::Compose $input > $output" ) ); } else if(string_from_raw.getValue()) { - std::ifstream inFile; - std::istream_iterator<char> iter; - if(input.isSet()) { - if(input.getValue() == "-") { - iter = std::cin; - } else { - inFile.open(input.getValue()); - iter = inFile; - } - } else { - iter = std::cin; - } - - string::String string = alib::FromRawParsers::stringParser.parseString(iter); - - measurements::end(); - measurements::start("Output write", measurements::Type::AUXILIARY); - - alib::XmlDataFactory::toStdout(string); + parser = cli::Parser ( cli::Lexer ( "execute raw::Parse string::LinearString $input > $output" ) ); } else if(string_to_raw.getValue()) { - string::String string = alib::XmlDataFactory::fromTokens (sax::FromXMLParserHelper::parseInput(input)); - - measurements::end(); - measurements::start("Output write", measurements::Type::AUXILIARY); - - string::StringToRawComposer::compose(std::cout, string); + parser = cli::Parser ( cli::Lexer ( "execute raw::Compose $input > $output" ) ); } else { - throw exception::CommonException("Invalid format specified"); + throw exception::CommonException("Invalid format specified."); } + parser.parse ( )->run ( environment ); + + measurements::end(); + measurements::start("Output write", measurements::Type::AUXILIARY); + + std::string outputCli; + if ( tree_from_raw.getValue ( ) || string_from_raw.getValue ( ) ) + outputCli = "execute $output >#stdout"; + else if ( tree_to_raw.getValue ( ) || string_to_raw.getValue ( ) ) + outputCli = "execute cli::builtin::WriteFile #stdout $output"; + + parser = cli::Parser ( cli::Lexer ( outputCli ) ); + parser.parse ( )->run ( environment ); + measurements::end(); measurements::end(); - if(measure.getValue()) common::Streams::measure << measurements::results() << std::endl; + if ( measure.getValue ( ) ) common::Streams::measure << measurements::results ( ) << std::endl; return 0; + } catch(const exception::CommonException& exception) { alib::XmlDataFactory::toStdout(exception); return 1; -- GitLab