Newer
Older
/*
* CastRegistry.cpp
*
* Created on: 21. 7. 2017
* Author: Jan Travnicek
*/
#include <registry/CastRegistry.hpp>
#include <alib/algorithm>
#include <alib/typeinfo>
namespace abstraction {
std::shared_ptr < abstraction::OperationAbstraction > CastRegistry::getAbstraction ( const std::string & target, const std::string & param ) {
auto entry = getEntries ( ).end ( );
for ( auto iter = getEntries ( ).begin ( ); iter != getEntries ( ).end ( ); ++ iter )
if ( iter->first.second == param && ext::is_same_type ( target, ext::erase_template_info ( iter->first.first ) ) ) {
if ( entry == getEntries ( ).end ( ) )
entry = iter;
else
throw std::invalid_argument ( "Entry from " + param + " to " + target + " is ambigous." );
throw std::invalid_argument ( "Entry from " + param + " to " + target + " not available." );
}
bool CastRegistry::isNoOp ( const std::string & target, const std::string & param ) {
return ext::is_same_type ( ext::erase_template_info ( target ), ext::erase_template_info ( param ) );
}
bool CastRegistry::castAvailable ( const std::string & target, const std::string & param ) {
for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) )
if ( entry.first.second == param && ext::is_same_type ( target, ext::erase_template_info ( entry.first.first ) ) )
return true;
return false;
}
ext::set < std::string > CastRegistry::listFrom ( const std::string & type ) {
ext::set < std::string > res;
for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) )
if ( ext::is_same_type ( type, ext::erase_template_info ( entry.first.second ) ) )
ext::set < std::string > CastRegistry::listTo ( const std::string & type ) {
ext::set < std::string > res;
for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) )
if ( ext::is_same_type ( type, ext::erase_template_info ( entry.first.first ) ) )
ext::set < ext::pair < std::string, std::string > > CastRegistry::list ( ) {
ext::set < ext::pair < std::string, std::string > > res;
for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) )
res.insert ( ext::make_pair ( entry.first.first, entry.first.second ) );
}
} /* namespace abstraction */