Skip to content
Snippets Groups Projects
Commit c338ad39 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

simplifications in xml and string abstractions

parent c04f2038
No related branches found
No related tags found
No related merge requests found
...@@ -8,26 +8,21 @@ ...@@ -8,26 +8,21 @@
#ifndef _STRING_READER_ABSTRACTION_HPP_ #ifndef _STRING_READER_ABSTRACTION_HPP_
#define _STRING_READER_ABSTRACTION_HPP_ #define _STRING_READER_ABSTRACTION_HPP_
   
#include <abstraction/NullaryOperationAbstraction.hpp> #include <abstraction/UnaryOperationAbstraction.hpp>
#include <tuple>
#include <exception/CommonException.h>
#include <factory/StringDataFactory.hpp> #include <factory/StringDataFactory.hpp>
   
namespace abstraction { namespace abstraction {
   
template < class ReturnType > template < class ReturnType >
class StringReaderAbstraction : public NullaryOperationAbstraction < ReturnType > { class StringReaderAbstraction : public UnaryOperationAbstraction < ReturnType, std::string && > {
std::string m_string; std::string m_string;
   
public: public:
StringReaderAbstraction ( std::string str ) : m_string ( std::move ( str ) ) {
}
virtual bool run ( ) override { virtual bool run ( ) override {
if ( this->isReady ( ) ) if ( this->isReady ( ) )
return true; return true;
   
ReturnType res = alib::StringDataFactory::fromString ( std::move ( m_string ) ); ReturnType res = alib::StringDataFactory::fromString ( std::get < 0 > ( this->m_params )->getRValueReference ( ) );
this->m_data = std::move ( res ); this->m_data = std::move ( res );
return true; return true;
} }
......
...@@ -9,9 +9,10 @@ ...@@ -9,9 +9,10 @@
   
namespace abstraction { namespace abstraction {
   
std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getAbstraction ( std::string str ) { std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getAbstraction ( const std::string & str ) {
std::stringstream ss ( str );
auto lambda = [ & ] ( const std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > & entry ) { auto lambda = [ & ] ( const std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > & entry ) {
std::stringstream ss ( str );
return entry.first ( ss ); return entry.first ( ss );
}; };
   
...@@ -19,7 +20,7 @@ std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getA ...@@ -19,7 +20,7 @@ std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getA
if ( callback == getEntries ( ).end ( ) ) if ( callback == getEntries ( ).end ( ) )
throw exception::CommonException ( "Entry not available." ); throw exception::CommonException ( "Entry not available." );
   
return callback->second->getAbstraction ( std::move ( str ) ); return callback->second->getAbstraction ( );
} }
   
} /* namespace abstraction */ } /* namespace abstraction */
...@@ -21,7 +21,7 @@ namespace abstraction { ...@@ -21,7 +21,7 @@ namespace abstraction {
class StringReaderRegistry { class StringReaderRegistry {
class Entry { class Entry {
public: public:
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( std::string data ) const = 0; virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0;
   
}; };
   
...@@ -31,7 +31,7 @@ class StringReaderRegistry { ...@@ -31,7 +31,7 @@ class StringReaderRegistry {
EntryImpl ( ) { EntryImpl ( ) {
} }
   
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( std::string data ) const override; virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override;
}; };
   
static ext::deque < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > & getEntries ( ) { static ext::deque < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > & getEntries ( ) {
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
getEntries ( ).push_back ( std::make_pair ( alib::stringApi < ReturnType >::first, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); getEntries ( ).push_back ( std::make_pair ( alib::stringApi < ReturnType >::first, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) );
} }
   
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( std::string data ); static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & data );
}; };
   
} /* namespace abstraction */ } /* namespace abstraction */
...@@ -55,8 +55,8 @@ public: ...@@ -55,8 +55,8 @@ public:
namespace abstraction { namespace abstraction {
   
template < class Return > template < class Return >
std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::EntryImpl < Return >::getAbstraction ( std::string data ) const { std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::EntryImpl < Return >::getAbstraction ( ) const {
return std::make_shared < abstraction::StringReaderAbstraction < Return > > ( std::move ( data ) ); return std::make_shared < abstraction::StringReaderAbstraction < Return > > ( );
} }
   
} /* namespace abstraction */ } /* namespace abstraction */
......
...@@ -9,13 +9,12 @@ ...@@ -9,13 +9,12 @@
#define _STRING_WRITER_ABSTRACTION_HPP_ #define _STRING_WRITER_ABSTRACTION_HPP_
   
#include <abstraction/UnaryOperationAbstraction.hpp> #include <abstraction/UnaryOperationAbstraction.hpp>
#include <tuple>
#include <factory/StringDataFactory.hpp> #include <factory/StringDataFactory.hpp>
   
namespace abstraction { namespace abstraction {
   
template < class ParamType > template < class ParamType >
class StringWriterAbstraction : public UnaryOperationAbstraction < std::string, ParamType > { class StringWriterAbstraction : public UnaryOperationAbstraction < std::string, const ParamType & > {
public: public:
virtual bool run ( ) override { virtual bool run ( ) override {
if ( ! this->inputsReady ( ) ) if ( ! this->inputsReady ( ) )
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
namespace abstraction { namespace abstraction {
   
template < class ParamType > template < class ParamType >
class XmlComposerAbstraction : public UnaryOperationAbstraction < ext::deque < sax::Token >, ParamType > { class XmlComposerAbstraction : public UnaryOperationAbstraction < ext::deque < sax::Token >, const ParamType & > {
public: public:
virtual bool run ( ) override { virtual bool run ( ) override {
if ( ! this->inputsReady ( ) ) if ( ! this->inputsReady ( ) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment