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

take out types comparison from algo getabstraction

parent eab77af5
No related branches found
No related tags found
No related merge requests found
......@@ -35,28 +35,8 @@ void AlgorithmRegistry::registerInternal ( std::string algorithm, AlgorithmCateg
std::shared_ptr < abstraction::OperationAbstraction > AlgorithmRegistry::getAbstraction ( const std::string & name, const ext::vector < std::string > & paramTypes, AlgorithmCategories::AlgorithmCategory ) {
auto group = getEntries ( ).find ( name );
if ( group == getEntries ( ).end ( ) ) {
ext::vector < std::string > explodedName = ext::explode ( name, "::" );
for ( auto iter = getEntries ( ).begin ( ); iter != getEntries ( ).end ( ); ++ iter ) {
ext::vector < std::string > explodedCandidate = ext::explode ( iter->first, "::" );
if ( explodedName.size ( ) > explodedCandidate.size ( ) )
continue;
unsigned offset = explodedCandidate.size ( ) - explodedName.size ( );
bool matches = true;
for ( unsigned index = 0; index < explodedName.size ( ); ++ index ) {
if ( explodedName [ index ] == "" )
continue;
if ( explodedName [ index ] != explodedCandidate [ index + offset ] ) {
matches = false;
break;
}
}
if ( matches ) {
if ( ext::is_same_type ( name, iter->first ) ) {
if ( group == getEntries ( ).end ( ) )
group = iter;
else
......
......@@ -22,4 +22,24 @@ std::string erase_template_info ( std::string str ) {
return str;
}
 
bool is_same_type ( const std::string & first, const std::string & second ) {
ext::vector < std::string > explodedFirst = ext::explode ( first, "::" );
ext::vector < std::string > explodedSecond = ext::explode ( second, "::" );
if ( explodedFirst.size ( ) > explodedSecond.size ( ) )
return false;
unsigned offset = explodedSecond.size ( ) - explodedFirst.size ( );
for ( unsigned index = 0; index < explodedFirst.size ( ); ++ index ) {
if ( explodedFirst [ index ] == "" )
continue;
if ( explodedFirst [ index ] != explodedSecond [ index + offset ] )
return false;
}
return true;
}
} /* namespace ext */
......@@ -11,8 +11,6 @@
#include <typeinfo>
#include <typeindex>
#include <string>
#include <cstdio>
#include <cstring>
 
#include "string.hpp"
#include "typeindex.h"
......@@ -24,18 +22,12 @@ std::string to_string ( ) {
return ext::to_string ( ext::type_index ( typeid ( T ) ) );
}
 
template<typename T>
bool is_same_type(const char* name) {
char namespaceId[100];
char classId[100];
std::string ret = to_string < T > ( );
sscanf(ret.c_str(), "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId);
bool is_same_type ( const std::string & first, const std::string & second );
 
if(strcmp(classId, name) == 0) {
return true;
} else {
return false;
}
template < typename T >
bool is_same_type ( const std::string & name ) {
std::string ret = to_string < T > ( );
return is_same_type ( ret, name );
}
 
std::string erase_template_info ( std::string str );
......
......@@ -62,18 +62,68 @@ void AlgorithmTest::testTransform() {
}
 
void AlgorithmTest::testFindRange ( ) {
std::string str = "abc<dee<fd<<>>>th>::rrr";
{
std::string str = "abc<dee<fd<<>>>th>::rrr";
std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' );
std::cerr << range.first - str.begin ( ) << std::endl;
std::cerr << range.second - str.begin ( ) << std::endl;
CPPUNIT_ASSERT ( range.first - str.begin ( ) == 3 );
CPPUNIT_ASSERT ( range.second - str.begin ( ) == 18 );
str.erase ( range.first, range.second );
std::cerr << str << std::endl;
CPPUNIT_ASSERT ( str == "abc::rrr" );
}
{
std::string str = "aaa::abc<dee<fd<<>>>th>";
std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' );
 
std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' );
std::cerr << range.first - str.begin ( ) << std::endl;
std::cerr << range.second - str.begin ( ) << std::endl;
 
std::cerr << range.first - str.begin ( ) << std::endl;
std::cerr << range.second - str.begin ( ) << std::endl;
CPPUNIT_ASSERT ( range.first - str.begin ( ) == 8 );
CPPUNIT_ASSERT ( range.second - str.begin ( ) == 23 );
 
CPPUNIT_ASSERT ( range.first - str.begin ( ) == 3 );
CPPUNIT_ASSERT ( range.second - str.begin ( ) == 18 );
str.erase ( range.first, range.second );
std::cerr << str << std::endl;
CPPUNIT_ASSERT ( str == "aaa::abc" );
}
{
std::string str = "<dee<fd<<>>>th>aaa";
 
str.erase ( range.first, range.second );
std::cerr << str << std::endl;
std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' );
 
CPPUNIT_ASSERT ( str == "abc::rrr" );
std::cerr << range.first - str.begin ( ) << std::endl;
std::cerr << range.second - str.begin ( ) << std::endl;
CPPUNIT_ASSERT ( range.first - str.begin ( ) == 0 );
CPPUNIT_ASSERT ( range.second - str.begin ( ) == 15 );
str.erase ( range.first, range.second );
std::cerr << str << std::endl;
CPPUNIT_ASSERT ( str == "aaa" );
}
{
std::string str = "<dee<fd<<>>>th>";
std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' );
std::cerr << range.first - str.begin ( ) << std::endl;
std::cerr << range.second - str.begin ( ) << std::endl;
CPPUNIT_ASSERT ( range.first - str.begin ( ) == 0 );
CPPUNIT_ASSERT ( range.second - str.begin ( ) == 15 );
str.erase ( range.first, range.second );
std::cerr << str << std::endl;
CPPUNIT_ASSERT ( str == "" );
}
}
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