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 @@
#ifndef _STRING_READER_ABSTRACTION_HPP_
#define _STRING_READER_ABSTRACTION_HPP_
 
#include <abstraction/NullaryOperationAbstraction.hpp>
#include <tuple>
#include <exception/CommonException.h>
#include <abstraction/UnaryOperationAbstraction.hpp>
#include <factory/StringDataFactory.hpp>
 
namespace abstraction {
 
template < class ReturnType >
class StringReaderAbstraction : public NullaryOperationAbstraction < ReturnType > {
class StringReaderAbstraction : public UnaryOperationAbstraction < ReturnType, std::string && > {
std::string m_string;
 
public:
StringReaderAbstraction ( std::string str ) : m_string ( std::move ( str ) ) {
}
virtual bool run ( ) override {
if ( this->isReady ( ) )
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 );
return true;
}
......
......@@ -9,9 +9,10 @@
 
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 ) {
std::stringstream ss ( str );
return entry.first ( ss );
};
 
......@@ -19,7 +20,7 @@ std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getA
if ( callback == getEntries ( ).end ( ) )
throw exception::CommonException ( "Entry not available." );
 
return callback->second->getAbstraction ( std::move ( str ) );
return callback->second->getAbstraction ( );
}
 
} /* namespace abstraction */
......@@ -21,7 +21,7 @@ namespace abstraction {
class StringReaderRegistry {
class Entry {
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 {
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 ( ) {
......@@ -45,7 +45,7 @@ public:
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 */
......@@ -55,8 +55,8 @@ public:
namespace abstraction {
 
template < class Return >
std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::EntryImpl < Return >::getAbstraction ( std::string data ) const {
return std::make_shared < abstraction::StringReaderAbstraction < Return > > ( std::move ( data ) );
std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::EntryImpl < Return >::getAbstraction ( ) const {
return std::make_shared < abstraction::StringReaderAbstraction < Return > > ( );
}
 
} /* namespace abstraction */
......
......@@ -9,13 +9,12 @@
#define _STRING_WRITER_ABSTRACTION_HPP_
 
#include <abstraction/UnaryOperationAbstraction.hpp>
#include <tuple>
#include <factory/StringDataFactory.hpp>
 
namespace abstraction {
 
template < class ParamType >
class StringWriterAbstraction : public UnaryOperationAbstraction < std::string, ParamType > {
class StringWriterAbstraction : public UnaryOperationAbstraction < std::string, const ParamType & > {
public:
virtual bool run ( ) override {
if ( ! this->inputsReady ( ) )
......
......@@ -14,7 +14,7 @@
namespace abstraction {
 
template < class ParamType >
class XmlComposerAbstraction : public UnaryOperationAbstraction < ext::deque < sax::Token >, ParamType > {
class XmlComposerAbstraction : public UnaryOperationAbstraction < ext::deque < sax::Token >, const ParamType & > {
public:
virtual bool run ( ) override {
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