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

make instrospection able to list groups of algos

parent c372644c
Branches
Tags
No related merge requests found
...@@ -7,17 +7,19 @@ ...@@ -7,17 +7,19 @@
namespace cli { namespace cli {
   
class IntrospectionCommand : public Command { class IntrospectionCommand : public Command {
std::string m_algorithm; std::string m_param;
   
public: public:
IntrospectionCommand ( std::string algorithm ) : m_algorithm ( std::move ( algorithm ) ) { IntrospectionCommand ( std::string param ) : m_param ( std::move ( param ) ) {
} }
   
virtual Command::Result run ( Environment & ) const override { virtual Command::Result run ( Environment & ) const override {
if ( m_algorithm == "" ) { if ( m_param == "" ) {
abstraction::Registry::listAlgorithms ( ); abstraction::Registry::listAlgorithms ( );
} else if ( m_param.find ( "::", m_param.size ( ) - 2 ) != std::string::npos ) {
abstraction::Registry::listGroup ( m_param );
} else { } else {
abstraction::Registry::listAlgorithmOverloads ( m_algorithm ); abstraction::Registry::listAlgorithmOverloads ( m_param );
} }
return Command::Result::OK; return Command::Result::OK;
} }
......
...@@ -103,6 +103,13 @@ public: ...@@ -103,6 +103,13 @@ public:
return getAbstraction ( std::move ( name ), paramTypes, downcast, normalize ); return getAbstraction ( std::move ( name ), paramTypes, downcast, normalize );
} }
   
static void listGroup ( const std::string & group ) {
for ( const std::pair < const std::string, std::map < std::vector < std::type_index >, std::unique_ptr < Entry > > > & entry : getEntries ( ) ) {
if ( entry.first.find ( group ) == 0 ) //found at the begining
std::cout << entry.first << std::endl;
}
}
static void listOverloads ( const std::string & algorithm ) { static void listOverloads ( const std::string & algorithm ) {
auto group = getEntries ( ).find ( algorithm ); auto group = getEntries ( ).find ( algorithm );
if ( group == getEntries ( ).end ( ) ) if ( group == getEntries ( ).end ( ) )
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
   
namespace abstraction { namespace abstraction {
   
void Registry::listGroup ( const std::string & group ) {
AlgorithmRegistry::listGroup ( group );
}
void Registry::listAlgorithmOverloads ( const std::string & algorithm ) { void Registry::listAlgorithmOverloads ( const std::string & algorithm ) {
AlgorithmRegistry::listOverloads ( algorithm ); AlgorithmRegistry::listOverloads ( algorithm );
} }
......
...@@ -14,6 +14,7 @@ namespace abstraction { ...@@ -14,6 +14,7 @@ namespace abstraction {
   
class Registry { class Registry {
public: public:
static void listGroup ( const std::string & algorithm );
static void listAlgorithmOverloads ( const std::string & algorithm ); static void listAlgorithmOverloads ( const std::string & algorithm );
static void listAlgorithms ( ); static void listAlgorithms ( );
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment