Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • algorithms-library-toolkit/automata-library
  • fortmare/automata-library
  • wijnhjan/automata-library
  • zelenm14/automata-library
  • gregofi1/automata-library
  • slavim17/automata-library
6 results
Show changes
Commits on Source (9)
Showing
with 347 additions and 40 deletions
......@@ -27,7 +27,7 @@ private:
if ( input == nullptr )
return false;
 
if ( checkInput && ! abstraction::CheckInput < ValueProvider < ParamType > >::checkInput ( input->getProxyAbstraction ( ), 0 /* Note: yes index zero */ ) )
if ( checkInput && ! abstraction::CheckInput < ValueProvider < ParamType > >::checkInput ( input, 0 /* Note: yes index zero */ ) )
return false;
 
if ( m_params.size ( ) < index + 1 )
......
......@@ -31,7 +31,7 @@ private:
if ( input == nullptr )
return false;
 
if ( checkInput && ! abstraction::CheckInput < ValueProvider < ParamTypes > ... >::checkInput ( input->getProxyAbstraction ( ), index ) )
if ( checkInput && ! abstraction::CheckInput < ValueProvider < ParamTypes > ... >::checkInput ( input, index ) )
return false;
 
m_params [ index ].first = input;
......
......@@ -25,6 +25,70 @@ class UnspecifiedType {
template < class ReturnType >
class ValueOperationAbstraction : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > {
protected:
virtual bool isConst ( ) const override {
return false;
}
virtual bool isRvalueRef ( ) const override {
return false;
}
virtual bool isLvalueRef ( ) const override {
return false;
}
virtual ReturnType & getData ( ) const override {
return m_data.value ( );
}
virtual const ReturnType & getConstData ( ) const override {
return m_data.value ( );
}
mutable std::optional < ReturnType > m_data;
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! cached ( ) )
m_data = abstraction::apply < ParamTypes ... > ( callback, inputs );
}
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( ReturnType ) );
}
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( cached ( ) )
return ext::type_index ( typeid ( getData ( ) ) );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
}
virtual bool cached ( ) const override {
return ( bool ) m_data;
}
virtual void reset ( ) override {
m_data.reset ( );
}
};
template < class ReturnType >
class ValueOperationAbstraction < const ReturnType > : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < const ReturnType & >, public ValueProvider < const ReturnType && > {
protected:
virtual bool isConst ( ) const override {
return true;
}
virtual bool isRvalueRef ( ) const override {
return false;
}
virtual bool isLvalueRef ( ) const override {
return false;
}
virtual ReturnType & getData ( ) const override {
return m_data.value ( );
}
......@@ -63,8 +127,20 @@ public:
};
 
template < class ReturnType >
class ValueOperationAbstraction < ReturnType & > : public OperationAbstraction, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > {
class ValueOperationAbstraction < ReturnType & > : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > {
protected:
virtual bool isConst ( ) const override {
return false;
}
virtual bool isRvalueRef ( ) const override {
return true;
}
virtual bool isLvalueRef ( ) const override {
return false;
}
virtual ReturnType & getData ( ) const override {
return m_data->get ( );
}
......@@ -103,8 +179,24 @@ public:
};
 
template < class ReturnType >
class ValueOperationAbstraction < const ReturnType & > : public OperationAbstraction, public ValueProvider < const ReturnType & >, public ValueProvider < const ReturnType && > {
class ValueOperationAbstraction < const ReturnType & > : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < const ReturnType & >, public ValueProvider < const ReturnType && > {
protected:
virtual bool isConst ( ) const override {
return true;
}
virtual bool isRvalueRef ( ) const override {
return true;
}
virtual bool isLvalueRef ( ) const override {
return false;
}
virtual ReturnType & getData ( ) const override {
return const_cast < ReturnType & > ( m_data->get ( ) );
}
virtual const ReturnType & getConstData ( ) const override {
return m_data->get ( );
}
......@@ -139,8 +231,20 @@ public:
};
 
template < class ReturnType >
class ValueOperationAbstraction < ReturnType && > : public OperationAbstraction, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > {
class ValueOperationAbstraction < ReturnType && > : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < const ReturnType & >, public ValueProvider < ReturnType && >, public ValueProvider < const ReturnType && > {
protected:
virtual bool isConst ( ) const override {
return false;
}
virtual bool isRvalueRef ( ) const override {
return false;
}
virtual bool isLvalueRef ( ) const override {
return true;
}
virtual ReturnType & getData ( ) const override {
return m_data->get ( );
}
......@@ -181,8 +285,24 @@ public:
};
 
template < class ReturnType >
class ValueOperationAbstraction < const ReturnType && > : public OperationAbstraction, public ValueProvider < const ReturnType & >, public ValueProvider < const ReturnType && > {
class ValueOperationAbstraction < const ReturnType && > : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < const ReturnType & >, public ValueProvider < const ReturnType && > {
protected:
virtual bool isConst ( ) const override {
return true;
}
virtual bool isRvalueRef ( ) const override {
return false;
}
virtual bool isLvalueRef ( ) const override {
return true;
}
virtual ReturnType & getData ( ) const override {
return const_cast < ReturnType & > ( m_data->get ( ) );
}
virtual const ReturnType & getConstData ( ) const override {
return m_data->get ( );
}
......
......@@ -17,12 +17,15 @@ namespace abstraction {
template < class Type >
class ValueProvider {
protected:
virtual bool isConst ( ) const = 0;
virtual bool isLvalueRef ( ) const = 0;
virtual bool isRvalueRef ( ) const = 0;
virtual Type & getData ( ) const = 0;
 
public:
template < class T = Type >
typename std::enable_if < std::is_copy_constructible < T >::value && std::is_move_constructible < T >::value, T >::type getValue ( bool move ) const {
if ( move )
if ( ! isConst ( ) && move )
return std::move ( getData ( ) );
else
return getData ( );
......@@ -30,7 +33,7 @@ public:
 
template < class T = Type >
typename std::enable_if < std::is_copy_constructible < T >::value && ! std::is_move_constructible < T >::value, T >::type getValue ( bool move ) const {
if ( move )
if ( ! isConst ( ) && move )
throw std::domain_error ( "Value not move constructible" );
else
return getData ( );
......@@ -38,7 +41,7 @@ public:
 
template < class T = Type >
typename std::enable_if < ! std::is_copy_constructible < T >::value && std::is_move_constructible < T >::value, T >::type getValue ( bool move ) const {
if ( move )
if ( ! isConst ( ) && move )
return std::move ( getData ( ) );
else
throw std::domain_error ( "Value not copy constructible" );
......@@ -46,7 +49,7 @@ public:
 
template < class T = Type >
typename std::enable_if < ! std::is_copy_constructible < T >::value && ! std::is_move_constructible < T >::value, T >::type getValue ( bool move ) const {
if ( move )
if ( ! isConst ( ) && move )
throw std::domain_error ( "Value not move constructible" );
else
throw std::domain_error ( "Value not copy constructible" );
......@@ -58,6 +61,9 @@ public:
template < class Type >
class ValueProvider < Type & > {
protected:
virtual bool isConst ( ) const = 0;
virtual bool isLvalueRef ( ) const = 0;
virtual bool isRvalueRef ( ) const = 0;
virtual Type & getData ( ) const = 0;
 
public:
......@@ -75,6 +81,9 @@ public:
template < class Type >
class ValueProvider < const Type & > {
protected:
virtual bool isConst ( ) const = 0;
virtual bool isLvalueRef ( ) const = 0;
virtual bool isRvalueRef ( ) const = 0;
virtual const Type & getConstData ( ) const = 0;
 
public:
......@@ -92,6 +101,9 @@ public:
template < class Type >
class ValueProvider < Type && > {
protected:
virtual bool isConst ( ) const = 0;
virtual bool isLvalueRef ( ) const = 0;
virtual bool isRvalueRef ( ) const = 0;
virtual Type & getData ( ) const = 0;
 
public:
......@@ -112,6 +124,9 @@ public:
template < class Type >
class ValueProvider < const Type && > {
protected:
virtual bool isConst ( ) const = 0;
virtual bool isLvalueRef ( ) const = 0;
virtual bool isRvalueRef ( ) const = 0;
virtual const Type & getConstData ( ) const = 0;
 
public:
......
......@@ -37,7 +37,7 @@ private:
if ( input == nullptr )
return false;
 
if ( checkInput && ! CheckInput < ValueProvider < ParamTypes > ... >::checkInput ( input->getProxyAbstraction ( ), index ) )
if ( checkInput && ! CheckInput < ValueProvider < ParamTypes > ... >::checkInput ( input, index ) )
return false;
 
m_params [ index ].first = input;
......
......@@ -68,7 +68,7 @@ template < class Param, class ... Params >
struct ParamType < Param, Params ... > {
static ext::type_index paramType ( unsigned index ) {
if ( index == 0 )
return ext::type_index ( typeid ( typename std::decay < Param >::type ) );
return ext::type_index ( typeid ( Param ) );
else
return ParamType < Params ... >::paramType ( index - 1);
}
......
......@@ -26,10 +26,33 @@ void AlgorithmRegistry::registerInternal ( std::string algorithm, ext::vector <
auto & group = getEntries ( ) [ ext::make_pair ( std::move ( algorithm ), std::move ( templateParams ) ) ];
 
ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > entryValue = ext::make_pair ( std::move ( result ), std::move ( value ) );
group.push_back ( ext::make_tuple ( category, std::move ( params ), entryValue ) );
group.insert ( group.end ( ), ext::make_tuple ( category, std::move ( params ), entryValue ) );
}
 
ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::vector < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < AlgorithmRegistry::Entry > > > > >::const_iterator AlgorithmRegistry::findAbstractionGroup ( const std::string & name, const ext::vector < std::string > & templateParams ) {
void AlgorithmRegistry::unregisterInternal ( std::string algorithm, ext::vector < std::string > templateParams, AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > > params ) {
auto & group = getEntries ( ) [ ext::make_pair ( std::move ( algorithm ), std::move ( templateParams ) ) ];
auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > & entry ) {
if ( std::get < 0 > ( entry ) != category )
return false;
const ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > > & entryParams = std::get < 1 > ( entry );
if ( entryParams.size ( ) != params.size ( ) )
return false;
for ( unsigned i = 0; i < params.size ( ); ++ i ) {
if ( std::get < 0 > ( params [ i ] ) != std::get < 0 > ( entryParams [ i ] ) )
return false;
if ( std::get < 1 > ( params [ i ] ) != std::get < 1 > ( entryParams [ i ] ) )
return false;
}
return true;
} );
if ( iter != group.end ( ) )
group.erase ( iter );
}
ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::list < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < AlgorithmRegistry::Entry > > > > >::const_iterator AlgorithmRegistry::findAbstractionGroup ( const std::string & name, const ext::vector < std::string > & templateParams ) {
auto group = getEntries ( ).find ( ext::make_pair ( name, templateParams ) );
if ( group == getEntries ( ).end ( ) ) {
for ( auto iter = getEntries ( ).begin ( ); iter != getEntries ( ).end ( ); ++ iter ) {
......@@ -152,7 +175,7 @@ std::shared_ptr < abstraction::OperationAbstraction > AlgorithmRegistry::getAbst
ext::set < ext::pair < std::string, ext::vector < std::string > > > AlgorithmRegistry::listGroup ( const std::string & group ) {
ext::set < ext::pair < std::string, ext::vector < std::string > > > res;
 
for ( const std::pair < const ext::pair < std::string, ext::vector < std::string > >, ext::vector < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > & entry : getEntries ( ) )
for ( const std::pair < const ext::pair < std::string, ext::vector < std::string > >, ext::list < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > & entry : getEntries ( ) )
if ( entry.first.first.find ( group ) == 0 ) //found at the begining
res.insert ( entry.first );
 
......@@ -172,7 +195,7 @@ ext::set < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::pair < std:
ext::set < ext::pair < std::string, ext::vector < std::string > > > AlgorithmRegistry::list ( ) {
ext::set < ext::pair < std::string, ext::vector < std::string > > > res;
 
for ( const std::pair < const ext::pair < std::string, ext::vector < std::string > >, ext::vector < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > & entry : getEntries ( ) )
for ( const std::pair < const ext::pair < std::string, ext::vector < std::string > >, ext::list < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > & entry : getEntries ( ) )
res.insert ( entry.first );
 
return res;
......
......@@ -11,6 +11,7 @@
#include <alib/functional>
#include <alib/memory>
#include <alib/vector>
#include <alib/list>
#include <alib/string>
#include <alib/set>
#include <alib/map>
......@@ -77,8 +78,8 @@ class AlgorithmRegistry {
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override;
};
 
static ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::vector < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > & getEntries ( ) {
static ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::vector < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > algorithmGroups;
static ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::list < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > & getEntries ( ) {
static ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::list < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > > algorithmGroups;
return algorithmGroups;
};
 
......@@ -115,9 +116,34 @@ class AlgorithmRegistry {
 
static void registerInternal ( std::string algorithm, ext::vector < std::string > templateParams, AlgorithmCategories::AlgorithmCategory category, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > > params, std::shared_ptr < Entry > value );
 
static ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::vector < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > >::const_iterator findAbstractionGroup ( const std::string & algorithm, const ext::vector < std::string > & templateParams );
static void unregisterInternal ( std::string algorithm, ext::vector < std::string > templateParams, AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > > params );
static ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::list < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > >, ext::pair < ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, std::shared_ptr < Entry > > > > >::const_iterator findAbstractionGroup ( const std::string & algorithm, const ext::vector < std::string > & templateParams );
 
public:
template < class Algo, class ObjectType, class ... ParamTypes >
static void unregisterMethod ( std::string methodName ) {
AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT;
std::string algorithm = ext::to_string < Algo > ( ) + "::" + methodName;
ext::vector < std::string > templateParams;
ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > > params = convertParamTypes < ParamTypes ... > ( std::array < std::string, sizeof ... ( ParamTypes ) > { } );
params.insert ( params.begin ( ), convertParamType < ObjectType & > ( "object" ) );
unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ) );
}
template < class Algo, class ... ParamTypes >
static void unregisterAlgorithm ( AlgorithmCategories::AlgorithmCategory category ) {
std::string algorithm = ext::to_string < Algo > ( );
ext::vector < std::string > templateParams = ext::get_template_info ( algorithm );
algorithm = ext::erase_template_info ( algorithm );
ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier >, std::string > > params = convertParamTypes < ParamTypes ... > ( std::array < std::string, sizeof ... ( ParamTypes ) > { } );
unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ) );
}
template < class Algo, class ObjectType, class ReturnType, class ... ParamTypes >
static void registerMethod ( ReturnType ( ObjectType:: * callback ) ( ParamTypes ... ), std::string methodName, std::array < std::string, sizeof ... ( ParamTypes ) > paramNames ) {
AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT;
......
......@@ -53,6 +53,18 @@ class CastRegistry {
};
 
public:
static void unregisterCast ( std::string target, std::string param ) {
getEntries ( ).erase ( std::make_pair ( target, param ) );
}
template < class TargetType, class ParamType >
static void unregisterCast ( ) {
std::string target = ext::to_string < TargetType > ( );
std::string param = ext::to_string < ParamType > ( );
unregisterCast ( target, param );
}
template < class TargetType, class ParamType >
static void registerCast ( std::string target, std::string param ) {
if ( ! getEntries ( ).insert ( std::make_pair ( std::make_pair ( target, param ), std::unique_ptr < Entry > ( new DefaultEntryImpl < TargetType, ParamType > ( ) ) ) ).second )
......
......@@ -42,7 +42,7 @@ ext::set < std::string > ContainerRegistry::listOverloads ( const std::string &
ext::set < std::string > ContainerRegistry::list ( ) {
ext::set < std::string > res;
 
for ( const std::pair < const std::string, ext::vector < ext::pair < std::string, std::shared_ptr < Entry > > > > & groups : getEntries ( ) )
for ( const std::pair < const std::string, ext::list < ext::pair < std::string, std::shared_ptr < Entry > > > > & groups : getEntries ( ) )
res.insert ( groups.first );
 
return res;
......
......@@ -10,7 +10,7 @@
 
#include <alib/functional>
#include <alib/memory>
#include <alib/vector>
#include <alib/list>
#include <alib/string>
#include <alib/set>
#include <alib/map>
......@@ -39,12 +39,29 @@ class ContainerRegistry {
}
};
 
static ext::map < std::string, ext::vector < ext::pair < std::string, std::shared_ptr < Entry > > > > & getEntries ( ) {
static ext::map < std::string, ext::vector < ext::pair < std::string, std::shared_ptr < Entry > > > > containerGroups;
static ext::map < std::string, ext::list < ext::pair < std::string, std::shared_ptr < Entry > > > > & getEntries ( ) {
static ext::map < std::string, ext::list < ext::pair < std::string, std::shared_ptr < Entry > > > > containerGroups;
return containerGroups;
};
 
public:
static void unregisterSet ( std::string param ) {
std::string container = "Set";
auto & group = getEntries ( ) [ container ];
auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::pair < std::string, std::shared_ptr < Entry > > & entry ) {
return entry.first == param;
} );
if ( iter != group.end ( ) )
group.erase ( iter );
}
template < class ParamTypes >
static void unregisterSet ( ) {
std::string param = ext::to_string < typename std::decay < ParamTypes >::type > ( );
unregisterSet ( param );
}
template < class ParamTypes >
static void registerSet ( std::string param ) {
std::string container = "Set";
......@@ -55,7 +72,7 @@ public:
throw std::invalid_argument ( "Callback for " + container + " already registered." );
 
std::shared_ptr < Entry > entryValue = std::make_shared < SetEntryImpl < ParamTypes > > ( );
group.push_back ( ext::make_pair ( param, entryValue ) );
group.insert ( group.end ( ), ext::make_pair ( param, entryValue ) );
}
 
template < class ParamTypes >
......
......@@ -45,6 +45,16 @@ class ImmediateRegistry {
}
 
public:
static void unregisterImmediate ( std::string result ) {
getEntries ( ).erase ( result );
}
template < class ResultType >
static void unregisterImmediate ( ) {
std::string result = ext::to_string < ResultType > ( );
unregisterImmediate ( std::move ( result ) );
}
template < class ResultType >
static void registerImmediate ( std::string result ) {
if ( ! getEntries ( ).insert ( std::make_pair ( result, std::unique_ptr < Entry > ( new EntryImpl < ResultType > ( ) ) ) ).second )
......
......@@ -11,15 +11,15 @@ namespace abstraction {
 
std::shared_ptr < abstraction::OperationAbstraction > NormalizeRegistry::getAbstraction ( const std::string & param ) {
auto res = getEntries ( ).find ( param );
if ( res == getEntries ( ).end ( ) )
if ( res == getEntries ( ).end ( ) || res->second.size ( ) == 0 )
throw std::invalid_argument ( "Entry " + param + " not available." );
 
return res->second->getAbstraction ( );
return res->second.front( )->getAbstraction ( );
}
 
bool NormalizeRegistry::hasNormalize ( const std::string & param ) {
auto res = getEntries ( ).find ( param );
return res != getEntries ( ).end ( );
return res != getEntries ( ).end ( ) && res->second.size ( ) > 0;
}
 
} /* namespace abstraction */
......@@ -11,6 +11,7 @@
#include <alib/memory>
#include <alib/string>
#include <alib/map>
#include <alib/list>
#include <alib/typeinfo>
 
#include <abstraction/OperationAbstraction.hpp>
......@@ -41,21 +42,33 @@ class NormalizeRegistry {
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 > > fileWriters;
return fileWriters;
static ext::map < std::string, std::list < std::unique_ptr < Entry > > > & getEntries ( ) {
static ext::map < std::string, std::list < std::unique_ptr < Entry > > > entries;
return entries;
}
 
public:
template < class ParamType >
static void registerNormalize ( std::string param ) {
getEntries ( ).insert ( std::make_pair ( param, std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) );
static void unregisterNormalize ( std::string param, std::list < std::unique_ptr < Entry > >::const_iterator iter ) {
getEntries ( ) [ param ].erase ( iter );
}
 
template < class ParamType >
static void registerNormalize ( ) {
static void unregisterNormalize ( std::list < std::unique_ptr < Entry > >::const_iterator iter ) {
std::string param = ext::to_string < ParamType > ( );
registerNormalize < ParamType > ( std::move ( param ) );
unregisterNormalize < ParamType > ( std::move ( param ), iter );
}
template < class ParamType >
static std::list < std::unique_ptr < Entry > >::const_iterator registerNormalize ( std::string param ) {
auto & entry = getEntries ( ) [ param ];
return entry.insert ( entry.end ( ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) );
}
template < class ParamType >
static std::list < std::unique_ptr < Entry > >::const_iterator registerNormalize ( ) {
std::string param = ext::to_string < ParamType > ( );
return registerNormalize < ParamType > ( std::move ( param ) );
}
 
static bool hasNormalize ( const std::string & param );
......
......@@ -45,6 +45,16 @@ class ValuePrinterRegistry {
}
 
public:
static void unregisterValuePrinter ( std::string param ) {
getEntries ( ).erase ( param );
}
template < class ParamType >
static void unregisterValuePrinter ( ) {
std::string param = ext::to_string < ParamType > ( );
unregisterValuePrinter ( std::move ( param ) );
}
template < class ParamType >
static void registerValuePrinter ( std::string param ) {
if ( ! getEntries ( ).insert ( std::make_pair ( param, std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ).second )
......
......@@ -126,6 +126,11 @@ q0: if ( m_source->isEndOfTransmition ( ) ) {
goto q3;
}
 
if ( m_source->getCharacter ( ) == '\\' ) {
m_source->advance ( true );
goto q3Escape;
}
res.m_type = TokenType::ERROR;
return res;
 
......@@ -160,6 +165,9 @@ q2: if ( m_source->isEndOfSequence ( ) ) {
res.m_value += m_source->getCharacter ( );
m_source->advance ( readNextLine );
goto q3;
} else if ( m_source->getCharacter ( ) == '\\' ) {
m_source->advance ( true );
goto q3Escape;
}
 
res.m_value = "";
......@@ -178,11 +186,25 @@ q3: if ( m_source->isEndOfSequence ( ) ) {
res.m_value += m_source->getCharacter ( );
m_source->advance ( readNextLine );
goto q3;
} else if ( m_source->getCharacter ( ) == '\\' ) {
m_source->advance ( true );
goto q3Escape;
} else {
res.m_type = is_kw ( res.m_value );
return res;
}
 
q3Escape:
if ( m_source->isEndOfSequence ( ) ) {
res.m_type = TokenType::ERROR;
return res;
}
res.m_value += m_source->getCharacter ( );
m_source->advance ( readNextLine );
goto q3;
q4: if ( m_source->isEndOfSequence ( ) ) {
res.m_type = TokenType::ERROR;
return res;
......
......@@ -44,6 +44,14 @@ std::unique_ptr < TypeOption > Parser::type_option ( ) {
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < TypeOption > ( std::move ( value ) );
} else {
throw exception::CommonException ( "Mismatched colon sign while expanding type_option rule." );
}
}
std::unique_ptr < TypeOption > Parser::optional_type_option ( ) {
if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) {
return type_option ( );
} else {
return nullptr;
}
......@@ -92,13 +100,18 @@ std::shared_ptr < Statement > Parser::in_redirect_file ( ) {
match ( cli::Lexer::TokenType::RIGHT_BRACKET );
}
 
std::unique_ptr < TypeOption > type = type_option ( );
std::unique_ptr < TypeOption > type = optional_type_option ( );
ext::vector < std::unique_ptr < cli::Arg > > templateArgs;
while ( check ( cli::Lexer::TokenType::AT_SIGN ) ) {
templateArgs.emplace_back ( template_arg ( ) );
}
 
std::unique_ptr < Arg > file = arg ( );
std::unique_ptr < Arg > file;
if ( check ( cli::Lexer::TokenType::STRING ) )
file = std::make_unique < ImmediateArg > ( matchString ( ) );
else {
file = arg ( );
}
return std::make_shared < FileStatement > ( std::move ( file ), std::move ( fileType ), std::move ( type ), std::move ( templateArgs ) );
}
 
......@@ -223,7 +236,12 @@ void Parser::out_redirect_file ( std::shared_ptr < StatementList > & list ) {
match ( cli::Lexer::TokenType::RIGHT_BRACKET );
}
 
std::unique_ptr < Arg > file = arg ( );
std::unique_ptr < Arg > file;
if ( check ( cli::Lexer::TokenType::STRING ) )
file = std::make_unique < ImmediateArg > ( matchString ( ) );
else {
file = arg ( );
}
list->append ( std::make_unique < ResultFileStatement > ( std::move ( file ), std::move ( fileType ) ) );
}
 
......
......@@ -86,8 +86,11 @@ public:
}
 
std::unique_ptr < CategoryOption > category_option ( );
std::unique_ptr < TypeOption > type_option ( );
 
std::unique_ptr < TypeOption > optional_type_option ( );
std::unique_ptr < Arg > arg ( );
 
std::unique_ptr < Arg > optional_arg ( );
......
......@@ -101,6 +101,13 @@ void CliTest::testCreateUnique ( ) {
parser = cli::Parser ( cli::Lexer ( "execute $res" ) );
parser.parse ( )->run ( environment );
 
parser = cli::Parser ( cli::Lexer ( "execute Divide <(One) <(One)" ) );
CPPUNIT_ASSERT_NO_THROW ( parser.parse ( )->run ( environment ) );
abstraction::AlgorithmRegistry::unregisterAlgorithm < Divide, double, double > ( abstraction::AlgorithmCategories::AlgorithmCategory::DEFAULT );
abstraction::AlgorithmRegistry::unregisterAlgorithm < Divide, int, int > ( abstraction::AlgorithmCategories::AlgorithmCategory::DEFAULT );
CPPUNIT_ASSERT_THROW ( parser.parse ( )->run ( environment ), exception::CommonException );
}
 
class Source {
......@@ -257,10 +264,10 @@ void CliTest::testSetConstruction ( ) {
parser = cli::Parser ( cli::Lexer ( "execute $set | Print -" ) );
parser.parse ( )->run ( environment );
 
parser = cli::Parser ( cli::Lexer ( "execute $set >local/yyy.xml" ) );
parser = cli::Parser ( cli::Lexer ( "execute $set >lo\\cal/yyy.xml" ) );
parser.parse ( )->run ( environment );
 
parser = cli::Parser ( cli::Lexer ( "execute < :set @int local/yyy.xml > $set2" ) );
parser = cli::Parser ( cli::Lexer ( "execute < :set @int \"local/yyy.xml\" > $set2" ) );
parser.parse ( )->run ( environment );
std::cout << environment.getVariable ( "set2" )->getReturnType ( ) << std::endl;
parser = cli::Parser ( cli::Lexer ( "execute $set2 | Print -" ) );
......
......@@ -42,9 +42,20 @@ class RawReaderRegistry {
}
 
public:
static void unregisterRawReader ( std::string type ) {
getEntries ( ).erase ( type );
}
template < class ReturnType >
static void unregisterRawReader ( ) {
std::string type = ext::to_string < ReturnType > ( );
unregisterRawReader ( std::move ( type ) );
}
template < class ReturnType >
static void registerRawReader ( std::string type ) {
getEntries ( ).insert ( std::make_pair ( std::move ( type ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) );
if ( ! getEntries ( ).insert ( std::make_pair ( std::move ( type ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ).second )
throw std::invalid_argument ( "Entry " + type + " already registered." );
}
 
template < class ReturnType >
......