diff --git a/aintrospection2/src/aintrospection.cpp b/aintrospection2/src/aintrospection.cpp index 7d1b1ef7983783a8d6463caa5efe9aa5be7e2b55..a29c8aefa76d796647a8715b52e59e7076300002 100644 --- a/aintrospection2/src/aintrospection.cpp +++ b/aintrospection2/src/aintrospection.cpp @@ -110,17 +110,17 @@ int main ( int argc, char * argv[] ) { } tokens.emplace_back("TemplateParams", sax::Token::TokenType::END_ELEMENT); tokens.emplace_back("Overloads", sax::Token::TokenType::START_ELEMENT); - for ( const ext::tuple < abstraction::AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > & over : abstraction::Registry::listOverloads ( algo.first, algo.second ) ) { + for ( const ext::tuple < abstraction::AlgorithmFullInfo, std::string > & over : abstraction::Registry::listOverloads ( algo.first, algo.second ) ) { tokens.emplace_back("Overload", sax::Token::TokenType::START_ELEMENT); tokens.emplace_back("Category", sax::Token::TokenType::START_ELEMENT); - tokens.emplace_back(abstraction::AlgorithmCategories::toString ( std::get < 0 > ( over ) ), sax::Token::TokenType::CHARACTER); + tokens.emplace_back(abstraction::AlgorithmCategories::toString ( std::get < 0 > ( over ).getCategory ( ) ), sax::Token::TokenType::CHARACTER); tokens.emplace_back("Category", sax::Token::TokenType::END_ELEMENT); tokens.emplace_back("Returns", sax::Token::TokenType::START_ELEMENT); tokens.emplace_back("Type", sax::Token::TokenType::START_ELEMENT); - tokens.emplace_back(std::get < 1 > ( over ).first, sax::Token::TokenType::CHARACTER); + tokens.emplace_back(std::get < 0 > ( over ).getResult ( ).first, sax::Token::TokenType::CHARACTER); tokens.emplace_back("Type", sax::Token::TokenType::END_ELEMENT); tokens.emplace_back("Qualifications", sax::Token::TokenType::START_ELEMENT); - for ( abstraction::ParamQualifiers::ParamQualifier qualifier : std::get < 1 > ( over ).second ) { + for ( abstraction::ParamQualifiers::ParamQualifier qualifier : std::get < 0 > ( over ).getResult ( ).second ) { tokens.emplace_back ( "Qualifier", sax::Token::TokenType::START_ELEMENT); switch ( qualifier ) { case abstraction::ParamQualifiers::ParamQualifier::CONST: @@ -138,9 +138,9 @@ int main ( int argc, char * argv[] ) { tokens.emplace_back("Qualifications", sax::Token::TokenType::END_ELEMENT); tokens.emplace_back("Returns", sax::Token::TokenType::END_ELEMENT); tokens.emplace_back("Params", sax::Token::TokenType::START_ELEMENT); - for ( unsigned i = 0; i < std::get < 2 > ( over ).size ( ); ++ i ) { - const ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & param = std::get < 2 > ( over ) [ i ]; - const std::string & name = std::get < 3 > ( over ) [ i ]; + for ( unsigned i = 0; i < std::get < 0 > ( over ).getParams ( ).size ( ); ++ i ) { + const ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & param = std::get < 0 > ( over ).getParams ( ) [ i ]; + const std::string & name = std::get < 0 > ( over ).getParamNames ( ) [ i ]; tokens.emplace_back("Param", sax::Token::TokenType::START_ELEMENT); tokens.emplace_back("Type", sax::Token::TokenType::START_ELEMENT); diff --git a/alib2abstraction/src/registry/AlgorithmRegistry.cpp b/alib2abstraction/src/registry/AlgorithmRegistry.cpp index 7890020a0cbfae68b248d87b7cc3305242a6c5a7..be6efcdc188174b02d149e25411585e05da0011f 100644 --- a/alib2abstraction/src/registry/AlgorithmRegistry.cpp +++ b/alib2abstraction/src/registry/AlgorithmRegistry.cpp @@ -17,51 +17,51 @@ ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::list < s return algorithmGroups; } -bool AlgorithmRegistry::isRegistered ( const std::string & algorithm, const ext::vector < std::string > & templateParams, AlgorithmCategories::AlgorithmCategory category, const ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > & params ) { +bool AlgorithmRegistry::isRegistered ( const std::string & algorithm, const ext::vector < std::string > & templateParams, const AlgorithmBaseInfo & entryInfo ) { auto & group = getEntries ( ) [ ext::make_pair ( algorithm, templateParams ) ]; for ( const std::shared_ptr < Entry > & entry : group ) - if ( entry->getCategory ( ) == category && entry->getParams ( ) == params ) + if ( entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( ) ) return true; return false; } void AlgorithmRegistry::registerInternal ( std::string algorithm, ext::vector < std::string > templateParams, std::shared_ptr < Entry > value ) { - if ( isRegistered ( algorithm, templateParams, value->getCategory ( ), value->getParams ( ) ) ) - throw std::invalid_argument ( "Callback for " + algorithm + " with params " + ext::to_string ( value->getParams ( ) ) + " already registered." ); + if ( isRegistered ( algorithm, templateParams, value->getEntryInfo ( ) ) ) + throw std::invalid_argument ( "Callback for " + algorithm + " with params " + ext::to_string ( value->getEntryInfo ( ).getParams ( ) ) + " already registered." ); auto & group = getEntries ( ) [ ext::make_pair ( std::move ( algorithm ), std::move ( templateParams ) ) ]; group.insert ( group.end ( ), value ); } -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 > > > params ) { +void AlgorithmRegistry::unregisterInternal ( std::string algorithm, ext::vector < std::string > templateParams, const AlgorithmBaseInfo & entryInfo ) { auto & group = getEntries ( ) [ ext::make_pair ( algorithm, templateParams ) ]; auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const std::shared_ptr < Entry > & entry ) { - return entry->getCategory ( ) == category && entry->getParams ( ) == params; + return entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( ); } ); if ( iter == group.end ( ) ) { if ( templateParams.size ( ) == 0 ) - throw std::invalid_argument ( "Entry " + algorithm + " with parameters " + ext::to_string ( params ) + " not registered." ); + throw std::invalid_argument ( "Entry " + algorithm + " with parameters " + ext::to_string ( entryInfo.getParams ( ) ) + " not registered." ); else - throw std::invalid_argument ( "Templated entry " + algorithm + " < " + ext::to_string ( templateParams ) + " > with parameters " + ext::to_string ( params ) + " not registered." ); + throw std::invalid_argument ( "Templated entry " + algorithm + " < " + ext::to_string ( templateParams ) + " > with parameters " + ext::to_string ( entryInfo.getParams ( ) ) + " not registered." ); } group.erase ( iter ); if ( group.size ( ) == 0 ) getEntries ( ).erase ( ext::make_pair ( algorithm, templateParams ) ); } -void AlgorithmRegistry::setDocumentation ( std::string algorithm, ext::vector < std::string > templateParams, AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params, std::string documentation ) { +void AlgorithmRegistry::setDocumentation ( std::string algorithm, ext::vector < std::string > templateParams, const AlgorithmBaseInfo & entryInfo, std::string documentation ) { auto & group = getEntries ( ) [ ext::make_pair ( algorithm, templateParams ) ]; auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const std::shared_ptr < Entry > & entry ) { - return entry->getCategory ( ) == category && entry->getParams ( ) == params; + return entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( ); } ); if ( iter == group.end ( ) ) { if ( templateParams.size ( ) == 0 ) - throw std::invalid_argument ( "Entry " + algorithm + " with parameters " + ext::to_string ( params ) + " not registered." ); + throw std::invalid_argument ( "Entry " + algorithm + " with parameters " + ext::to_string ( entryInfo.getParams ( ) ) + " not registered." ); else - throw std::invalid_argument ( "Templated entry " + algorithm + " < " + ext::to_string ( templateParams ) + " > with parameters " + ext::to_string ( params ) + " not registered." ); + throw std::invalid_argument ( "Templated entry " + algorithm + " < " + ext::to_string ( templateParams ) + " > with parameters " + ext::to_string ( entryInfo.getParams ( ) ) + " not registered." ); } (*iter)->setDocumentation ( std::move ( documentation ) ); } @@ -99,15 +99,15 @@ std::shared_ptr < abstraction::OperationAbstraction > AlgorithmRegistry::getAbst // determine how one can actually map what we have ( paramTypes ) as params to what is available as overloads ( group->second ) std::vector < std::pair < ext::vector < MatchType >, std::shared_ptr < Entry > > > compatibilityData; for ( const std::shared_ptr < Entry > & entry : group->second ) { - if ( entry->getParams ( ).size ( ) != paramTypes.size ( ) ) + if ( entry->getEntryInfo ( ).getParams ( ).size ( ) != paramTypes.size ( ) ) continue; ext::vector < MatchType > compatibilityVector; for ( unsigned i = 0; i < paramTypes.size ( ); ++ i ) { MatchType matchType; - if ( std::get < 0 > ( entry->getParams ( ) [ i ] ) == paramTypes [ i ] ) { + if ( std::get < 0 > ( entry->getEntryInfo ( ).getParams ( ) [ i ] ) == paramTypes [ i ] ) { matchType = MatchType::EXACT; - } else if ( abstraction::CastRegistry::castAvailable ( std::get < 0 > ( entry->getParams ( ) [ i ] ), paramTypes [ i ] ) ) { + } else if ( abstraction::CastRegistry::castAvailable ( std::get < 0 > ( entry->getEntryInfo ( ).getParams ( ) [ i ] ), paramTypes [ i ] ) ) { matchType = MatchType::CAST; } else { matchType = MatchType::INCOMPATIBLE; @@ -188,12 +188,12 @@ ext::set < ext::pair < std::string, ext::vector < std::string > > > AlgorithmReg return res; } -ext::set < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > > AlgorithmRegistry::listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ) { +ext::list < ext::tuple < AlgorithmFullInfo, std::string > > AlgorithmRegistry::listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ) { auto group = findAbstractionGroup ( algorithm, templateParams ); - ext::set < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > > res; + ext::list < ext::tuple < AlgorithmFullInfo, std::string > > res; for ( const std::shared_ptr < Entry > & overloads : group->second ) - res.insert ( ext::make_tuple ( overloads->getCategory ( ), overloads->getResult ( ), overloads->getParams ( ), overloads->getParamNames ( ), overloads->getDocumentation ( ) ) ); + res.push_back ( ext::make_tuple ( overloads->getEntryInfo ( ), overloads->getDocumentation ( ) ) ); return res; } diff --git a/alib2abstraction/src/registry/AlgorithmRegistry.hpp b/alib2abstraction/src/registry/AlgorithmRegistry.hpp index 9daf585378c9277296532f19d9763182f693f011..61a7cbec34880549299f5ae094d5cdc1c03ba40b 100644 --- a/alib2abstraction/src/registry/AlgorithmRegistry.hpp +++ b/alib2abstraction/src/registry/AlgorithmRegistry.hpp @@ -18,30 +18,25 @@ #include <alib/tuple> #include <alib/algorithm> #include <exception> -#include <alib/typeinfo> #include <abstraction/OperationAbstraction.hpp> #include <common/ParamQualifiers.hpp> #include <common/AlgorithmCategories.hpp> +#include "AlgorithmRegistryInfo.hpp" + namespace abstraction { class AlgorithmRegistry { public: class Entry { - AlgorithmCategories::AlgorithmCategory m_category; - - ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > m_params; - - ext::vector < std::string > m_paramNames; - - ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > m_result; + AlgorithmFullInfo m_entryInfo; std::string m_documentation; public: - Entry ( AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params, ext::vector < std::string > paramNames, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result ) : m_category ( category ), m_params ( std::move ( params ) ), m_paramNames ( std::move ( paramNames ) ), m_result ( std::move ( result ) ), m_documentation ( "Documentation not avaiable." ) { + Entry ( AlgorithmFullInfo entryInfo ) : m_entryInfo ( std::move ( entryInfo ) ), m_documentation ( "Documentation not avaiable." ) { } virtual ~Entry ( ) { @@ -49,20 +44,8 @@ public: virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0; - AlgorithmCategories::AlgorithmCategory getCategory ( ) const { - return m_category; - } - - const ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > & getParams ( ) const { - return m_params; - } - - const ext::vector < std::string > & getParamNames ( ) const { - return m_paramNames; - } - - const ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & getResult ( ) const { - return m_result; + const AlgorithmFullInfo & getEntryInfo ( ) const { + return m_entryInfo; } const std::string & getDocumentation ( ) { @@ -80,7 +63,7 @@ private: std::function < Return ( typename std::remove_reference < ObjectType >::type *, Params ... ) > m_callback; public: - MemberImpl ( AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params, ext::vector < std::string > paramNames, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result, std::function < Return ( typename std::remove_reference < ObjectType >::type *, Params ... ) > callback ) : Entry ( category, std::move ( params ), std::move ( paramNames ), std::move ( result ) ), m_callback ( callback ) { + MemberImpl ( std::array < std::string, sizeof ... ( Params ) > paramNames, std::function < Return ( typename std::remove_reference < ObjectType >::type *, Params ... ) > callback ) : Entry ( AlgorithmFullInfo::methodEntryInfo < ObjectType, Return, Params ... > ( std::move ( paramNames ) ) ), m_callback ( callback ) { } virtual ~MemberImpl ( ) { @@ -94,7 +77,7 @@ private: std::function < Return ( Params ... ) > m_callback; public: - EntryImpl ( AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params, ext::vector < std::string > paramNames, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result, std::function < Return ( Params ... ) > callback ) : Entry ( category, std::move ( params ), std::move ( paramNames ), std::move ( result ) ), m_callback ( callback ) { + EntryImpl ( AlgorithmCategories::AlgorithmCategory category, std::array < std::string, sizeof ... ( Params ) > paramNames, std::function < Return ( Params ... ) > callback ) : Entry ( AlgorithmFullInfo::algorithmEntryInfo < Return, Params ... > ( category, std::move ( paramNames ) ) ), m_callback ( callback ) { } virtual ~EntryImpl ( ) { @@ -108,7 +91,7 @@ private: std::function < std::shared_ptr < abstraction::OperationAbstraction > ( Params ... ) > m_wrapperFinder; public: - WrapperImpl ( AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params, ext::vector < std::string > paramNames, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result, std::function < std::shared_ptr < abstraction::OperationAbstraction > ( Params ... ) > wrapperFinder ) : Entry ( category, std::move ( params ), std::move ( paramNames ), std::move ( result ) ), m_wrapperFinder ( wrapperFinder ) { + WrapperImpl ( std::array < std::string, sizeof ... ( Params ) > paramNames, std::function < std::shared_ptr < abstraction::OperationAbstraction > ( Params ... ) > wrapperFinder ) : Entry ( AlgorithmFullInfo::wrapperEntryInfo < Return, Params ... > ( std::move ( paramNames ) ) ), m_wrapperFinder ( wrapperFinder ) { } virtual ~WrapperImpl ( ) { @@ -125,39 +108,23 @@ private: INCOMPATIBLE }; - template < class ... ParamTypes > - static ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > convertTypes ( ) { - ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params { convertType < ParamTypes > ( ) ... }; - - return params; - } - - template < class ReturnType > - static ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > convertType ( ) { - return ext::make_pair ( ext::to_string < typename std::decay < ReturnType >::type > ( ), abstraction::ParamQualifiers::paramQualifiers < ReturnType > ( ) ); - } - - static bool isRegistered ( const std::string & algorithm, const ext::vector < std::string > & templateParams, AlgorithmCategories::AlgorithmCategory category, const ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > & params ); + static bool isRegistered ( const std::string & algorithm, const ext::vector < std::string > & templateParams, const AlgorithmBaseInfo & entryInfo ); static void registerInternal ( std::string algorithm, ext::vector < std::string > templateParams, std::shared_ptr < Entry > value ); - 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 > > > params ); + static void unregisterInternal ( std::string algorithm, ext::vector < std::string > templateParams, const AlgorithmBaseInfo & entryInfo ); - static void setDocumentation ( std::string algorithm, ext::vector < std::string > templateParams, AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params, std::string documentation ); + static void setDocumentation ( std::string algorithm, ext::vector < std::string > templateParams, const AlgorithmBaseInfo & entryInfo, std::string documentation ); static ext::map < ext::pair < std::string, ext::vector < std::string > >, ext::list < 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 setDocumentationOfMethod ( std::string methodName, std::string documentation ) { - 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 > > > params = convertTypes < ParamTypes ... > ( ); - params.insert ( params.begin ( ), convertType < ObjectType & > ( ) ); - - setDocumentation ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ), std::move ( documentation ) ); + setDocumentation ( std::move ( algorithm ), std::move ( templateParams ), AlgorithmBaseInfo::methodEntryInfo < ObjectType, ParamTypes ... > ( ), std::move ( documentation ) ); } template < class Algo, class ... ParamTypes > @@ -166,34 +133,24 @@ public: 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 > > > params = convertTypes < ParamTypes ... > ( ); - - setDocumentation ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ), std::move ( documentation ) ); + setDocumentation ( std::move ( algorithm ), std::move ( templateParams ), AlgorithmBaseInfo::algorithmEntryInfo < ParamTypes ... > ( category ), std::move ( documentation ) ); } template < class Algo, class ... ParamTypes > static void setDocumentationOfWrapper ( std::string documentation ) { - AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT; - 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 > > > params = convertTypes < ParamTypes ... > ( ); - - setDocumentation ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ), std::move ( documentation ) ); + setDocumentation ( std::move ( algorithm ), std::move ( templateParams ), AlgorithmBaseInfo::wrapperEntryInfo < ParamTypes ... > ( ), std::move ( documentation ) ); } 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 > > > params = convertTypes < ParamTypes ... > ( ); - params.insert ( params.begin ( ), convertType < ObjectType & > ( ) ); - - unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ) ); + unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), AlgorithmBaseInfo::methodEntryInfo < ObjectType, ParamTypes ... > ( ) ); } template < class Algo, class ... ParamTypes > @@ -202,58 +159,32 @@ public: 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 > > > params = convertTypes < ParamTypes ... > ( ); - - unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ) ); + unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), AlgorithmBaseInfo::algorithmEntryInfo < ParamTypes ... > ( category ) ); } template < class Algo, class ... ParamTypes > static void unregisterWrapper ( ) { - AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT; - 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 > > > params = convertTypes < ParamTypes ... > ( ); - - unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), category, std::move ( params ) ); + unregisterInternal ( std::move ( algorithm ), std::move ( templateParams ), AlgorithmBaseInfo::wrapperEntryInfo < ParamTypes ... > ( ) ); } 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; std::string algorithm = ext::to_string < Algo > ( ) + "::" + methodName; ext::vector < std::string > templateParams; - ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params = convertTypes < ParamTypes ... > ( ); - params.insert ( params.begin ( ), convertType < ObjectType & > ( ) ); - - ext::vector < std::string > parameterNames; - parameterNames.insert ( parameterNames.end ( ), "object" ); - parameterNames.insert ( parameterNames.end ( ), paramNames.begin ( ), paramNames.end ( ) ); - - ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result = convertType < ReturnType > ( ); - - registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < MemberImpl < ObjectType &, ReturnType, ParamTypes ... > > ( category, std::move ( params ), std::move ( parameterNames ), std::move ( result ), callback ) ); + registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < MemberImpl < ObjectType &, ReturnType, ParamTypes ... > > ( std::move ( paramNames ), callback ) ); } template < class Algo, class ObjectType, class ReturnType, class ... ParamTypes > static void registerMethod ( ReturnType ( ObjectType:: * callback ) ( ParamTypes ... ) const, std::string methodName, std::array < std::string, sizeof ... ( ParamTypes ) > paramNames ) { - 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 > > > params = convertTypes < ParamTypes ... > ( ); - params.insert ( params.begin ( ), convertType < const ObjectType & > ( ) ); - - ext::vector < std::string > parameterNames; - parameterNames.insert ( parameterNames.end ( ), "object" ); - parameterNames.insert ( parameterNames.end ( ), paramNames.begin ( ), paramNames.end ( ) ); - - ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result = convertType < ReturnType > ( ); - - registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < MemberImpl < const ObjectType &, ReturnType, ParamTypes ... > > ( category, std::move ( params ), std::move ( parameterNames ), std::move ( result ), callback ) ); + registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < MemberImpl < const ObjectType &, ReturnType, ParamTypes ... > > ( std::move ( paramNames ), callback ) ); } template < class Algo, class ReturnType, class ... ParamTypes > @@ -261,35 +192,23 @@ public: std::string algorithm = ext::to_string < Algo > ( ); ext::vector < std::string > templateParams; - ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params = convertTypes < ParamTypes ... > ( ); - ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result = convertType < ReturnType > ( ); - - ext::vector < std::string > parameterNames ( paramNames.begin ( ), paramNames.end ( ) ); - - registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < EntryImpl < ReturnType, ParamTypes ... > > ( category, std::move ( params ), std::move ( parameterNames ), std::move ( result ), callback ) ); + registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < EntryImpl < ReturnType, ParamTypes ... > > ( category, std::move ( paramNames ), callback ) ); } template < class Algo, class ReturnType, class ... ParamTypes > static void registerWrapper ( std::shared_ptr < abstraction::OperationAbstraction > ( * callback ) ( ParamTypes ... ), std::array < std::string, sizeof ... ( ParamTypes ) > paramNames ) { - AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT; - 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 > > > params = convertTypes < ParamTypes ... > ( ); - ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result = convertType < ReturnType > ( ); - - ext::vector < std::string > parameterNames ( paramNames.begin ( ), paramNames.end ( ) ); - - registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < WrapperImpl < ReturnType, ParamTypes ... > > ( category, std::move ( params ), std::move ( parameterNames ), std::move ( result ), callback ) ); + registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_shared < WrapperImpl < ReturnType, ParamTypes ... > > ( std::move ( paramNames ), callback ) ); } static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & name, const ext::vector < std::string > & templateParams, const ext::vector < std::string > & paramTypes, const ext::vector < ext::set < abstraction::ParamQualifiers::ParamQualifier > > & paramQualifiers, AlgorithmCategories::AlgorithmCategory category ); static ext::set < ext::pair < std::string, ext::vector < std::string > > > listGroup ( const std::string & group ); - static ext::set < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > > listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ); + static ext::list < ext::tuple < AlgorithmFullInfo, std::string > > listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ); static ext::set < ext::pair < std::string, ext::vector < std::string > > > list ( ); }; diff --git a/alib2abstraction/src/registry/AlgorithmRegistryInfo.hpp b/alib2abstraction/src/registry/AlgorithmRegistryInfo.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c9dcd43d4e5798857148f0a6a00f615d7a647dd4 --- /dev/null +++ b/alib2abstraction/src/registry/AlgorithmRegistryInfo.hpp @@ -0,0 +1,129 @@ +/* + * AlgorithmRegistry.hpp + * + * Created on: 11. 7. 2017 + * Author: Jan Travnicek + */ + +#ifndef _ALGORITHM_REGISTRY_INFO_HPP_ +#define _ALGORITHM_REGISTRY_INFO_HPP_ + +#include <alib/vector> +#include <alib/set> +#include <alib/pair> +#include <alib/typeinfo> +#include <alib/tuple> + +#include <common/ParamQualifiers.hpp> +#include <common/AlgorithmCategories.hpp> + +namespace abstraction { + +class AlgorithmBaseInfo { + AlgorithmCategories::AlgorithmCategory m_category; + + ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > m_params; + +protected: + template < class ... ParamTypes > + static ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > convertTypes ( ) { + ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params { convertType < ParamTypes > ( ) ... }; + + return params; + } + + template < class ReturnType > + static ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > convertType ( ) { + return ext::make_pair ( ext::to_string < typename std::decay < ReturnType >::type > ( ), abstraction::ParamQualifiers::paramQualifiers < ReturnType > ( ) ); + } + +public: + AlgorithmBaseInfo ( AlgorithmCategories::AlgorithmCategory category, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params ) : m_category ( category ), m_params ( std::move ( params ) ) { + } + + AlgorithmCategories::AlgorithmCategory getCategory ( ) const { + return m_category; + } + + const ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > & getParams ( ) const { + return m_params; + } + + template < class ObjectType, class ... ParamTypes > + static AlgorithmBaseInfo methodEntryInfo ( ) { + AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT; + + ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params = convertTypes < ParamTypes ... > ( ); + params.insert ( params.begin ( ), convertType < ObjectType & > ( ) ); + + return AlgorithmBaseInfo ( category, std::move ( params ) ); + } + + template < class ... ParamTypes > + static AlgorithmBaseInfo algorithmEntryInfo ( AlgorithmCategories::AlgorithmCategory category ) { + ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params = convertTypes < ParamTypes ... > ( ); + + return AlgorithmBaseInfo ( category, std::move ( params ) ); + } + + template < class ... ParamTypes > + static AlgorithmBaseInfo wrapperEntryInfo ( ) { + AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT; + + ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > > params = convertTypes < ParamTypes ... > ( ); + + return AlgorithmBaseInfo ( category, std::move ( params ) ); + } +}; + +class AlgorithmFullInfo : public AlgorithmBaseInfo { + ext::vector < std::string > m_paramNames; + + ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > m_result; + +public: + AlgorithmFullInfo ( AlgorithmBaseInfo baseInfo, ext::vector < std::string > paramNames, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result ) : AlgorithmBaseInfo ( std::move ( baseInfo ) ), m_paramNames ( std::move ( paramNames ) ), m_result ( std::move ( result ) ) { + } + + const ext::vector < std::string > & getParamNames ( ) const { + return m_paramNames; + } + + const ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & getResult ( ) const { + return m_result; + } + + template < class ObjectType, class ReturnType, class ... ParamTypes > + static AlgorithmFullInfo methodEntryInfo ( std::array < std::string, sizeof ... ( ParamTypes ) > paramNames ) { + ext::vector < std::string > parameterNames; + parameterNames.insert ( parameterNames.end ( ), "object" ); + parameterNames.insert ( parameterNames.end ( ), paramNames.begin ( ), paramNames.end ( ) ); + + ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result = convertType < ReturnType > ( ); + + return AlgorithmFullInfo ( AlgorithmBaseInfo::methodEntryInfo < ObjectType, ParamTypes ... > ( ), std::move ( parameterNames ), std::move ( result ) ); + } + + template < class ReturnType, class ... ParamTypes > + static AlgorithmFullInfo algorithmEntryInfo ( AlgorithmCategories::AlgorithmCategory category, std::array < std::string, sizeof ... ( ParamTypes ) > paramNames ) { + ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result = convertType < ReturnType > ( ); + + ext::vector < std::string > parameterNames ( paramNames.begin ( ), paramNames.end ( ) ); + + return AlgorithmFullInfo ( AlgorithmBaseInfo::algorithmEntryInfo < ParamTypes ... > ( category ), std::move ( parameterNames ), std::move ( result ) ); + } + + template < class ReturnType, class ... ParamTypes > + static AlgorithmFullInfo wrapperEntryInfo ( std::array < std::string, sizeof ... ( ParamTypes ) > paramNames ) { + ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > result = convertType < ReturnType > ( ); + + ext::vector < std::string > parameterNames ( paramNames.begin ( ), paramNames.end ( ) ); + + return AlgorithmFullInfo ( AlgorithmBaseInfo::wrapperEntryInfo < ParamTypes ... > ( ), std::move ( parameterNames ), std::move ( result ) ); + } + +}; + +} /* namespace abstraction */ + +#endif /* _ALGORITHM_REGISTRY_INFO_HPP_ */ diff --git a/alib2abstraction/src/registry/Registry.cpp b/alib2abstraction/src/registry/Registry.cpp index 7dcd2032c8a3406792c2aed77453f71b52de0314..2c66ae04b2a3e36da80bb1740ecbbbae1815ed4c 100644 --- a/alib2abstraction/src/registry/Registry.cpp +++ b/alib2abstraction/src/registry/Registry.cpp @@ -36,7 +36,7 @@ ext::set < ext::pair < std::string, std::string > > Registry::listCasts ( ) { return CastRegistry::list ( ); } -ext::set < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > > Registry::listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ) { +ext::list < ext::tuple < AlgorithmFullInfo, std::string > > Registry::listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ) { return AlgorithmRegistry::listOverloads ( algorithm, templateParams ); } diff --git a/alib2abstraction/src/registry/Registry.h b/alib2abstraction/src/registry/Registry.h index 12f08c528049cc3b406bd3d2eb67683341cb128c..6f2b90efe6708469e7fb76795f602a31d5ec0b49 100644 --- a/alib2abstraction/src/registry/Registry.h +++ b/alib2abstraction/src/registry/Registry.h @@ -11,9 +11,11 @@ #include <abstraction/OperationAbstraction.hpp> #include <common/ParamQualifiers.hpp> #include <common/AlgorithmCategories.hpp> +#include "AlgorithmRegistryInfo.hpp" #include <alib/pair> #include <alib/tuple> +#include <alib/list> namespace abstraction { @@ -26,7 +28,7 @@ public: static ext::set < std::string > listCastsTo ( const std::string & type ); static ext::set < ext::pair < std::string, std::string > > listCasts ( ); - static ext::set < ext::tuple < AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > > listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ); + static ext::list < ext::tuple < AlgorithmFullInfo, std::string > > listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams ); static std::shared_ptr < abstraction::OperationAbstraction > getContainerAbstraction ( const std::string & container, const std::string & type ); static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( const std::string & name, const ext::vector < std::string > & templateParams, const ext::vector < std::string > & paramTypes, const ext::vector < ext::set < abstraction::ParamQualifiers::ParamQualifier > > & paramQualifiers, AlgorithmCategories::AlgorithmCategory ); diff --git a/alib2cli/src/command/OverloadsIntrospectionCommand.h b/alib2cli/src/command/OverloadsIntrospectionCommand.h index 38695a14bd32ca9f4d619e80cea489703e8093e4..dccc9822b35f0cf954ca4c9ab3a465ec563c8e50 100644 --- a/alib2cli/src/command/OverloadsIntrospectionCommand.h +++ b/alib2cli/src/command/OverloadsIntrospectionCommand.h @@ -20,16 +20,16 @@ public: for ( const std::unique_ptr < cli::Arg > & templateParam : m_templateParams ) templateParams.push_back ( templateParam->eval ( environment ) ); - ext::set < ext::tuple < abstraction::AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > > overloads = abstraction::Registry::listOverloads ( param, templateParams ); + ext::list < ext::tuple < abstraction::AlgorithmFullInfo, std::string > > overloads = abstraction::Registry::listOverloads ( param, templateParams ); bool first = false; - for ( const ext::tuple < abstraction::AlgorithmCategories::AlgorithmCategory, ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > >, ext::vector < ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > >, ext::vector < std::string >, std::string > & overload : overloads ) { + for ( const ext::tuple < abstraction::AlgorithmFullInfo, std::string > & overload : overloads ) { if ( first ) common::Streams::out << std::endl << "-------------------------------------------------------------------------------------" << std::endl; { - const ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & result = std::get < 1 > ( overload ); + const ext::pair < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & result = std::get < 0 > ( overload ).getResult ( ); if ( std::get < 1 > ( result ).count ( abstraction::ParamQualifiers::ParamQualifier::CONST ) ) common::Streams::out << "const "; @@ -43,9 +43,9 @@ public: common::Streams::out << " &&"; } common::Streams::out << " ("; - for ( unsigned i = 0; i < std::get < 2 > ( overload ).size ( ); ++ i ) { - const ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & parameter = std::get < 2 > ( overload ) [ i ]; - const std::string & name = std::get < 3 > ( overload ) [ i ]; + for ( unsigned i = 0; i < std::get < 0 > ( overload ).getParams ( ).size ( ); ++ i ) { + const ext::tuple < std::string, ext::set < abstraction::ParamQualifiers::ParamQualifier > > & parameter = std::get < 0 > ( overload ).getParams ( ) [ i ]; + const std::string & name = std::get < 0 > ( overload ).getParamNames ( ) [ i ]; if ( i != 0 ) common::Streams::out << ","; @@ -66,9 +66,9 @@ public: } common::Streams::out << " )" << std::endl << std::endl; - common::Streams::out << "Category: " << std::get < 0 > ( overload ) << std::endl << std::endl; + common::Streams::out << "Category: " << std::get < 0 > ( overload ).getCategory ( ) << std::endl << std::endl; - common::Streams::out << std::get < 4 > ( overload ) << std::endl; + common::Streams::out << std::get < 1 > ( overload ) << std::endl; first = true; } diff --git a/alib2gui/src/Algorithm/Registry.cpp b/alib2gui/src/Algorithm/Registry.cpp index 69fb555693d222eb0dbbc4581cc69fe0de2778fe..fd2e3fabecf035b2ea49f22722adeee3ae30b35b 100644 --- a/alib2gui/src/Algorithm/Registry.cpp +++ b/alib2gui/src/Algorithm/Registry.cpp @@ -13,10 +13,10 @@ void Registry::initialize() { auto algorithm = std::make_unique<Algorithm>(name); for (const auto& overload: abstraction::AlgorithmRegistry::listOverloads(name, item.second)) { - const std::string& resultType = std::get<1>(overload).first; + const std::string& resultType = std::get<0>(overload).getResult().first; std::vector<std::string> paramNames; - for (const auto& param: std::get<2>(overload)) { + for (const auto& param: std::get<0>(overload).getParams()) { paramNames.push_back(std::get<0>(param)); }