|
cgma
|
#include <iostream>#include <sstream>#include <iomanip>#include <cstdlib>#include <list>#include <limits>#include <set>#include <assert.h>#include <string.h>#include "ProgOptions.hpp"Go to the source code of this file.
Classes | |
| class | ProgOpt |
Defines | |
| #define | DECLARE_OPTION_TYPE(T) |
| #define | DECLARE_VALUED_OPTION_TYPE(T) |
Enumerations | |
| enum | OptType { FLAG = 0, INT, REAL, STRING, INT_VECT } |
Functions | |
| template<typename T > | |
| static OptType | get_opt_type () |
| template<> | |
| OptType | get_opt_type< void > () |
| template<> | |
| OptType | get_opt_type< int > () |
| template<> | |
| OptType | get_opt_type< double > () |
| template<> | |
| OptType | get_opt_type< std::string > () |
| template<> | |
| OptType | get_opt_type< std::vector< int > > () |
| static bool | parse_int_list (const char *string, std::vector< int > &results) |
| static std::string | do_rank_subst (const std::string &s) |
| #define DECLARE_OPTION_TYPE | ( | T | ) |
template void ProgOptions::addOpt<T>( const std::string&, const std::string&, T*, int ); \ template bool ProgOptions::getOpt<T>( const std::string&, T* );
Definition at line 963 of file ProgOptions.cpp.
| #define DECLARE_VALUED_OPTION_TYPE | ( | T | ) |
DECLARE_OPTION_TYPE(T) \ template void ProgOptions::getOptAllArgs<T> (const std::string&, std::vector<T>& ); \ template void ProgOptions::addRequiredArg<T>( const std::string&, const std::string&, T*, int ); \ template void ProgOptions::addOptionalArgs<T>( unsigned, const std::string&, const std::string&, int ); \ template T ProgOptions::getReqArg<T>( const std::string& ); \ template void ProgOptions::getArgs<T>( const std::string&, std::vector<T>& );
Definition at line 967 of file ProgOptions.cpp.
| enum OptType |
| static std::string do_rank_subst | ( | const std::string & | s | ) | [static] |
Definition at line 430 of file ProgOptions.cpp.
{
#ifndef USE_MPI
return s;
#else
int rank, size;
if (MPI_SUCCESS != MPI_Comm_rank( MPI_COMM_WORLD, &rank )
|| MPI_SUCCESS != MPI_Comm_size( MPI_COMM_WORLD, &size ))
return s;
int width = 1;
while (size > 10) {
size /= 10;
width++;
}
size_t j = s.find( '%' );
if (j == std::string::npos)
return s;
std::ostringstream st;
st << std::setfill('0');
st << s.substr( 0, j );
st << rank;
size_t i;
while ((i = s.find( '%', j+1)) != std::string::npos) {
st << s.substr( j, i - j );
st << std::setw(width) << rank;
j = i;
}
st << s.substr( j+1 );
return st.str();
#endif
}
| static OptType get_opt_type | ( | ) | [inline, static] |
| OptType get_opt_type< double > | ( | ) |
Definition at line 35 of file ProgOptions.cpp.
{ return REAL; }
| OptType get_opt_type< int > | ( | ) |
Definition at line 34 of file ProgOptions.cpp.
{ return INT; }
| OptType get_opt_type< std::string > | ( | ) |
Definition at line 36 of file ProgOptions.cpp.
{ return STRING; }
| OptType get_opt_type< std::vector< int > > | ( | ) |
Definition at line 37 of file ProgOptions.cpp.
{ return INT_VECT; }
| OptType get_opt_type< void > | ( | ) |
Definition at line 33 of file ProgOptions.cpp.
{ return FLAG; }
| static bool parse_int_list | ( | const char * | string, |
| std::vector< int > & | results | ||
| ) | [static] |
Definition at line 382 of file ProgOptions.cpp.
{
bool okay = true;
char* mystr = strdup( string );
for (const char* ptr = strtok(mystr, ", \t"); ptr; ptr = strtok(0,", \t"))
{
char* endptr;
long val = strtol( ptr, &endptr, 0 );
if (endptr == ptr) {
std::cerr << "Not an integer: \"" << ptr << '"' << std::endl;
okay = false;
break;
}
long val2 = val;
if (*endptr == '-') {
const char* sptr = endptr+1;
val2 = strtol( sptr, &endptr, 0 );
if (endptr == sptr) {
std::cerr << "Not an integer: \"" << sptr << '"' << std::endl;
okay = false;
break;
}
if (val2 < val) {
std::cerr << "Invalid id range: \"" << ptr << '"' << std::endl;
okay = false;
break;
}
}
if (*endptr) {
okay = false;
break;
}
for (; val <= val2; ++val)
results.push_back( (int)val );
}
free( mystr );
return okay;
}