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

casing to nonprimitive types in cast abstraction

parent 685b2ad1
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -10,10 +10,13 @@ ...@@ -10,10 +10,13 @@
   
#include <memory> #include <memory>
#include <string> #include <string>
#include <set>
   
#include <exception/CommonException.h> #include <exception/CommonException.h>
#include <abstraction/OperationAbstraction.hpp> #include <abstraction/OperationAbstraction.hpp>
   
#include <core/namingApi.hpp>
namespace abstraction { namespace abstraction {
   
class CastRegistry { class CastRegistry {
...@@ -77,11 +80,19 @@ public: ...@@ -77,11 +80,19 @@ public:
} }
   
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( std::string target, std::string param ) { static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( std::string target, std::string param ) {
auto cast = getEntries ( ).find ( std::make_pair ( target, param ) ); std::set < std::string > targetTypes;
if ( cast == getEntries ( ).end ( ) ) if ( alib::namingApi::hasTypes ( target ) )
throw exception::CommonException ( "Entry from " + param + " to " + target + " not available." ); targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } );
else
targetTypes.insert ( target );
for ( const std::string & toType : targetTypes ) {
auto cast = getEntries ( ).find ( std::make_pair ( toType, param ) );
if ( cast != getEntries ( ).end ( ) )
return cast->second->getAbstraction ( );
}
   
return cast->second->getAbstraction ( ); throw exception::CommonException ( "Entry from " + param + " to " + target + " not available." );
} }
   
}; };
......
...@@ -40,6 +40,11 @@ public: ...@@ -40,6 +40,11 @@ public:
return name->second; return name->second;
} }
   
static bool hasTypes ( std::string stringname ) {
auto name = getNames ( ).find ( stringname );
return name != getNames ( ).end ( );
}
}; };
   
} /* namespace alib */ } /* namespace alib */
......
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