Commit 39dadccb authored by Jakub Klinkovský's avatar Jakub Klinkovský

Fixed parseCommandLine after refactoring the getType function

parent 5910a5e8
......@@ -142,7 +142,7 @@ public:
TNL_ASSERT_TRUE( this->currentEntry, "there is no current entry" );
if( isCurrentEntryList ) {
ConfigEntryList< EntryType >& entry = dynamic_cast< ConfigEntryList< EntryType >& >( *currentEntry );
entry.getEnumValues().push_back( entryEnum );
entry.getEnumValues().push_back( entryEnum );
}
else {
ConfigEntry< EntryType >& entry = dynamic_cast< ConfigEntry< EntryType >& >( *currentEntry );
......@@ -216,7 +216,7 @@ public:
std::cerr << "Asking for the default value of unknown parameter." << std::endl;
return nullptr;
}
//! Returns zero pointer if there is no default value
template< class T >
T* getDefaultValue( const String& name )
......@@ -254,55 +254,59 @@ public:
if( entries[ i ]->hasDefaultValue &&
! parameter_container.checkParameter( entry_name ) )
{
if( entries[ i ]->getEntryType() == "String" )
if( entries[ i ]->getEntryType() == "TNL::String" )
{
ConfigEntry< String >& entry = dynamic_cast< ConfigEntry< String >& >( *entries[ i ] );
parameter_container.addParameter< String >( entry_name, entry.defaultValue );
continue;
}
if( entries[ i ]->getEntryType() == "bool" )
else if( entries[ i ]->getEntryType() == "bool" )
{
ConfigEntry< bool >& entry = dynamic_cast< ConfigEntry< bool >& >( *entries[ i ] );
parameter_container.addParameter< bool >( entry_name, entry.defaultValue );
continue;
}
if( entries[ i ]->getEntryType() == "int" )
else if( entries[ i ]->getEntryType() == "int" )
{
ConfigEntry< int >& entry = dynamic_cast< ConfigEntry< int >& >( *entries[ i ] );
parameter_container.addParameter< int >( entry_name, entry.defaultValue );
continue;
}
if( entries[ i ]->getEntryType() == "double" )
else if( entries[ i ]->getEntryType() == "double" )
{
ConfigEntry< double >& entry = dynamic_cast< ConfigEntry< double >& >( *entries[ i ] );
parameter_container.addParameter< double >( entry_name, entry.defaultValue );
continue;
}
if( entries[ i ]->getEntryType() == "ConfigEntryList< String >" )
else if( entries[ i ]->getEntryType() == "ConfigEntryList< TNL::String >" )
{
ConfigEntryList< String >& entry = dynamic_cast< ConfigEntryList< String >& >( *entries[ i ] );
parameter_container.addList< String >( entry_name, entry.defaultValue );
continue;
}
if( entries[ i ]->getEntryType() == "ConfigEntryList< bool >" )
else if( entries[ i ]->getEntryType() == "ConfigEntryList< bool >" )
{
ConfigEntryList< bool >& entry = dynamic_cast< ConfigEntryList< bool >& >( *entries[ i ] );
parameter_container.addList< bool >( entry_name, entry.defaultValue );
continue;
}
if( entries[ i ]->getEntryType() == "ConfigEntryList< int >" )
else if( entries[ i ]->getEntryType() == "ConfigEntryList< int >" )
{
ConfigEntryList< int >& entry = dynamic_cast< ConfigEntryList< int >& >( *entries[ i ] );
parameter_container.addList< int >( entry_name, entry.defaultValue );
continue;
}
if( entries[ i ]->getEntryType() == "ConfigEntryList< double >" )
else if( entries[ i ]->getEntryType() == "ConfigEntryList< double >" )
{
ConfigEntryList< double >& entry = dynamic_cast< ConfigEntryList< double >& >( *entries[ i ] );
parameter_container.addList< double >( entry_name, entry.defaultValue );
continue;
}
else
{
throw std::runtime_error( "Method ConfigDescription::addMissingEntries encountered "
"unsupported entry type: " + entries[ i ]->getEntryType() );
}
}
}
}
......
......@@ -63,7 +63,7 @@ public:
parameters.push_back( std::make_unique< Parameter< T > >( name, TNL::getType< T >(), value ) );
return true;
}
/**
* \brief Adds new parameter to the ParameterContainer.
*
......@@ -73,7 +73,7 @@ public:
*/
template< class T >
bool addList( const String& name,
const T& value )
const T& value )
{
std::vector< T > v;
v.push_back( value );
......
......@@ -50,7 +50,7 @@ parseCommandLine( int argc, char* argv[],
int i;
bool parse_error( false );
for( i = 1; i < argc; i ++ )
for( i = 1; i < argc; i++ )
{
const char* _option = argv[ i ];
if( _option[ 0 ] != '-' )
......@@ -74,7 +74,7 @@ parseCommandLine( int argc, char* argv[],
else
{
const String& entryType = entry->getEntryType();
const char* value = argv[ ++ i ];
const char* value = argv[ ++i ];
if( ! value )
{
std::cerr << "Missing value for the parameter " << option << "." << std::endl;
......@@ -96,11 +96,11 @@ parseCommandLine( int argc, char* argv[],
while( i < argc && ( ( argv[ i ] )[ 0 ] != '-' || ( atof( argv[ i ] ) < 0.0 && ( parsedEntryType[ 1 ] == "int" || parsedEntryType[ 1 ] == "double" ) ) ) )
{
const char* value = argv[ i ++ ];
if( parsedEntryType[ 1 ] == "String" )
if( parsedEntryType[ 1 ] == "TNL::String" )
{
string_list.push_back( String( value ) );
}
if( parsedEntryType[ 1 ] == "bool" )
else if( parsedEntryType[ 1 ] == "bool" )
{
const int v = matob( value );
if( v == -1 )
......@@ -110,14 +110,19 @@ parseCommandLine( int argc, char* argv[],
}
else bool_list.push_back( v );
}
if( parsedEntryType[ 1 ] == "int" )
else if( parsedEntryType[ 1 ] == "int" )
{
integer_list.push_back( atoi( value ) );
}
if( parsedEntryType[ 1 ] == "double" )
else if( parsedEntryType[ 1 ] == "double" )
{
real_list.push_back( atof( value ) );
}
else
{
// this will not happen if all entry types are handled above
throw std::runtime_error( "Function parseCommandLine encountered unsupported entry type: " + entryType );
}
}
if( string_list.size() )
parameters.addParameter< std::vector< String > >( option, string_list );
......@@ -132,14 +137,14 @@ parseCommandLine( int argc, char* argv[],
}
else
{
if( parsedEntryType[ 0 ] == "String" )
if( parsedEntryType[ 0 ] == "TNL::String" )
{
if( ! ( ( ConfigEntry< String >* ) entry )->checkValue( value ) )
return false;
parameters.addParameter< String >( option, value );
continue;
}
if( parsedEntryType[ 0 ] == "bool" )
else if( parsedEntryType[ 0 ] == "bool" )
{
const int v = matob( value );
if( v == -1 )
......@@ -150,7 +155,7 @@ parseCommandLine( int argc, char* argv[],
else parameters.addParameter< bool >( option, v );
continue;
}
if( parsedEntryType[ 0 ] == "int" )
else if( parsedEntryType[ 0 ] == "int" )
{
/*if( ! std::isdigit( value ) ) //TODO: Check for real number
{
......@@ -162,7 +167,7 @@ parseCommandLine( int argc, char* argv[],
return false;
parameters.addParameter< int >( option, atoi( value ) );
}
if( parsedEntryType[ 0 ] == "double" )
else if( parsedEntryType[ 0 ] == "double" )
{
/*if( ! std::isdigit( value ) ) //TODO: Check for real number
{
......@@ -174,6 +179,11 @@ parseCommandLine( int argc, char* argv[],
return false;
parameters.addParameter< double >( option, atof( value ) );
}
else
{
// this will not happen if all entry types are handled above
throw std::runtime_error( "Function parseCommandLine encountered unsupported entry type: " + entryType );
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment