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

make introspection use cli internally

parent d4503c42
No related branches found
No related tags found
No related merge requests found
Pipeline #
EXECUTABLE:=aintrospection2
LINK_PATHS=../alib2elgo/ ../alib2algo_experimental/ ../alib2algo/ ../alib2raw/ ../alib2str_experimental/ ../alib2str/ ../alib2data_experimental/ ../alib2data/ ../alib2common/ ../alib2std/
LINK_LIBRARIES=alib2elgo alib2algo_experimental alib2algo alib2raw alib2str_experimental alib2str alib2data_experimental alib2data alib2common alib2std xml2
INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2elgo/src/ \$$(SOURCES_BASE_DIR)/../../alib2algo_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2algo/src/ \$$(SOURCES_BASE_DIR)/../../alib2raw/src/ \$$(SOURCES_BASE_DIR)/../../alib2str_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2str/src/ \$$(SOURCES_BASE_DIR)/../../alib2data_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/
LINK_PATHS=../alib2cli/ ../alib2elgo/ ../alib2algo_experimental/ ../alib2algo/ ../alib2raw/ ../alib2raw/ ../alib2str_experimental/ ../alib2str/ ../alib2data_experimental/ ../alib2data/ ../alib2common/ ../alib2std/
LINK_LIBRARIES=alib2cli alib2elgo alib2algo_experimental alib2algo alib2raw alib2str_experimental alib2str alib2data_experimental alib2data alib2common alib2std xml2
INCLUDE_PATHS=\
\$$(SOURCES_BASE_DIR)/../../alib2cli/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2elgo/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2algo_experimental/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2algo/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2aux/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2raw/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2str_experimental/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2str/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2data_experimental/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2data/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2common/src/ \
\$$(SOURCES_BASE_DIR)/../../alib2std/src/ \
/usr/include/libxml2/
......@@ -8,12 +8,10 @@
#include <tclap/CmdLine.h>
#include <global/GlobalData.h>
#include <measure>
#include <factory/XmlDataFactory.hpp>
#include <exception/CommonException.h>
 
#include <introspection/DataTypes.hpp>
#include <introspection/Algorithms.hpp>
#include <introspection/Casts.hpp>
#include <exception/CommonException.h>
#include <lexer/Lexer.h>
#include <parser/Parser.h>
 
int main ( int argc, char * argv[] ) {
try {
......@@ -22,27 +20,24 @@ int main ( int argc, char * argv[] ) {
 
TCLAP::CmdLine cmd ( "Introspection binary", ' ', "0.01" );
 
TCLAP::SwitchArg dataTypeGroups ( "", "datatype_groups", "Data type Groups", false );
cmd.add ( dataTypeGroups );
TCLAP::SwitchArg dataTypes ( "d", "datatypes", "Data types", false );
cmd.add ( dataTypes );
 
TCLAP::ValueArg < std::string > dataTypesInGroup ( "d", "datatypes_in_group", "Data type Groups", false, "", "string" );
cmd.add ( dataTypesInGroup );
TCLAP::SwitchArg algorithms ( "", "algorithms", "Algorithms", false );
TCLAP::SwitchArg algorithms ( "a", "algorithms", "Algorithms", false );
cmd.add ( algorithms );
 
TCLAP::ValueArg < std::string > algorithmInterface ( "", "algorithm_interface", "Algorithm Interface", false, "", "string" );
cmd.add ( algorithmInterface );
TCLAP::ValueArg < std::string > algorithmCallbacks ( "a", "algorithm_callbacks", "Algorithm Callbacks", false, "", "string" );
cmd.add ( algorithmCallbacks );
TCLAP::SwitchArg overloads ( "o", "overloads", "Overloads", false );
cmd.add ( overloads );
 
TCLAP::ValueArg < std::string > castFrom ( "", "cast_from", "Casting handlers from type", false, "", "string" );
TCLAP::SwitchArg castFrom ( "f", "cast_from", "Casting from type", false );
cmd.add ( castFrom );
 
TCLAP::ValueArg < std::string > castTo ( "", "cast_to", "Casting handlers to type", false, "", "string" );
TCLAP::SwitchArg castTo ( "t", "cast_to", "Casting to type", false );
cmd.add ( castTo );
 
TCLAP::UnlabeledValueArg < std::string > argument ( "argument", "Type name for casts, algorithm name for overloads, group name for algorithms or datatypes", false, "", "string" );
cmd.add ( argument );
TCLAP::SwitchArg measure ( "m", "measure", "Measure times", false );
cmd.add ( measure );
 
......@@ -60,53 +55,24 @@ int main ( int argc, char * argv[] ) {
measurements::start ( "Overal", measurements::Type::OVERALL );
measurements::start ( "Output write", measurements::Type::AUXILIARY );
 
if ( dataTypeGroups.getValue ( ) ) {
for ( const std::string & group : introspection::DataTypes::getGroups ( ) )
std::cout << group << std::endl;
} else if ( dataTypesInGroup.isSet ( ) ) {
auto groupIter = introspection::DataTypes::getTypesInGroup ( ).find ( dataTypesInGroup.getValue ( ) );
if ( groupIter == introspection::DataTypes::getTypesInGroup ( ).end ( ) )
std::cout << "No such group as " << dataTypesInGroup.getValue ( ) << std::endl;
else
for ( const std::string & group : groupIter->second )
std::cout << group << std::endl;
} else if ( algorithms.getValue ( ) ) {
for ( const std::string & algorithm : introspection::Algorithms::getAlgorithms ( ) )
std::cout << algorithm << std::endl;
} else if ( algorithmInterface.isSet ( ) ) {
auto algorithmInterfaceIter = introspection::Algorithms::getAlgorithmInterfaces ( ).find ( algorithmInterface.getValue ( ) );
if ( algorithmInterfaceIter == introspection::Algorithms::getAlgorithmInterfaces ( ).end ( ) )
std::cout << "No such algorithm as " << algorithmInterface.getValue ( ) << std::endl;
else
std::cout << algorithmInterfaceIter->second << std::endl;
} else if ( algorithmCallbacks.isSet ( ) ) {
auto algorithmCallbacksIter = introspection::Algorithms::getAlgorithmCallbacks ( ).find ( algorithmCallbacks.getValue ( ) );
if ( algorithmCallbacksIter == introspection::Algorithms::getAlgorithmCallbacks ( ).end ( ) )
std::cout << "No such algorithm as " << algorithmCallbacks.getValue ( ) << std::endl;
else
for ( const auto & callback : algorithmCallbacksIter->second )
std::cout << callback << std::endl;
cli::Environment environment;
environment.setBinding ( "argument", argument.getValue ( ) );
if ( dataTypes.isSet ( ) ) {
cli::Parser parser ( cli::Lexer ( "introspect datatypes #argument" ) );
parser.parse ( )->run ( environment );
} else if ( algorithms.isSet ( ) ) {
cli::Parser parser ( cli::Lexer ( "introspect algorithms #argument" ) );
parser.parse ( )->run ( environment );
} else if ( overloads.isSet ( ) ) {
cli::Parser parser ( cli::Lexer ( "introspect overloads #argument" ) );
parser.parse ( )->run ( environment );
} else if ( castFrom.isSet ( ) ) {
auto fromIter = introspection::Casts::getCastsFrom ( ).find ( castFrom.getValue ( ) );
if ( fromIter == introspection::Casts::getCastsFrom ( ).end ( ) || fromIter->second.empty ( ) )
std::cout << "No cast from " << castFrom.getValue ( ) << " registered" << std::endl;
else
for ( const std::string & castTarget : fromIter->second )
std::cout << castTarget << std::endl;
cli::Parser parser ( cli::Lexer ( "introspect casts :from #argument" ) );
parser.parse ( )->run ( environment );
} else if ( castTo.isSet ( ) ) {
auto toIter = introspection::Casts::getCastsTo ( ).find ( castTo.getValue ( ) );
if ( toIter == introspection::Casts::getCastsTo ( ).end ( ) || toIter->second.empty ( ) )
std::cout << "No cast to " << castTo.getValue ( ) << " registered" << std::endl;
else
for ( const std::string & castSource : toIter->second )
std::cout << castSource << std::endl;
cli::Parser parser ( cli::Lexer ( "introspect casts :to #argument" ) );
parser.parse ( )->run ( environment );
}
 
measurements::end ( );
......
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