54 template<
class Type >
59 std::stringstream( argv[0] ) >> value;
69 template<
class Type ,
int Dim >
72 if( v )
for(
int i=0 ; i<Dim ; i++ )
values[i] = v[i];
73 else for(
int i=0 ; i<Dim ; i++ )
values[i] = Type();
76 template<
class Type ,
int Dim >
81 for(
int i=0 ; i<Dim ; i++ ) std::stringstream( argv[i] ) >> values[i];
91 template<
class Type >
94 template<
class Type >
97 if( values )
delete[] values;
102 template<
class Type >
105 if( values )
delete[] values;
110 count = atoi(argv[0]);
111 if( count <= 0 || argc <= count )
return 1;
112 values =
new Type[count];
113 if( !values )
return 0;
114 for(
int i=0 ; i<count ; i++ ) std::stringstream( argv[i+1] ) >> values[i];
129 if( argv[0][0]==
'-' && argv[0][1]==
'-' )
132 for(
int i=0 ;
params[i]!=NULL && readable==NULL ; i++ )
if(
params[i]->name==argv[0]+2 ) readable =
params[i];
135 int j = readable->
read( argv+1 , argc-1 );
136 argv += j , argc -= j;
140 WARN(
"Invalid option: %s" , argv[0] );
141 for(
int i=0 ;
params[i]!=NULL ; i++ ) std::cerr <<
"\t--" <<
params[i]->name << std::endl;
144 else WARN(
"Parameter name should be of the form --<name>: %s" , argv[0] );
149 inline std::string
ToUpper(
const std::string &str )
151 auto _ToUpper = [](
char c ){
return c>=
'a' && c<=
'z' ? c+
'A'-
'a' : c; };
153 upper.resize( str.size() );
154 std::transform( str.begin() , str.end() , upper.begin() , _ToUpper );
149 inline std::string
ToUpper(
const std::string &str ) {
…}
158 inline std::string
ToLower(
const std::string &str )
160 auto _ToLower = [](
char c ){
return c>=
'A' && c<=
'Z' ? c+
'a'-
'A' : c; };
162 lower.resize( str.size() );
163 std::transform( str.begin() , str.end() , lower.begin() , _ToLower );
158 inline std::string
ToLower(
const std::string &str ) {
…}
170 std::stringstream stream( fileName );
171 while( std::getline( stream , ext ,
'.' ) ) ;
178 for(
int i=(
int)fileName.size()-1 ; i>=0 ; i-- )
if( fileName[i]==
FileSeparator ){ idx = i ;
break; }
179 if( idx==-1 )
return fileName;
180 else return fileName.substr( idx+1 , fileName.size() );
186 for(
int i=(
int)fileName.size()-1 ; i>=0 ; i-- )
if( fileName[i]==
FileSeparator ){ idx = i ;
break; }
188 else return fileName.substr( 0 , idx+1 );
191 inline std::string
GetFileName(
const std::string &directory ,
const std::string &localFileName )
193 if( !directory.size() )
return localFileName;
194 else if( localFileName[0]==
FileSeparator )
return localFileName;
195 else if( directory.back()==
FileSeparator )
return directory + localFileName;
191 inline std::string
GetFileName(
const std::string &directory ,
const std::string &localFileName ) {
…}
199 inline std::vector< std::string >
ReadWords(
const std::string &fileName )
201 std::ifstream istream;
202 istream.open( fileName );
203 if( !istream )
THROW(
"Failed to open file for reading: " , fileName );
204 std::vector< std::string > words;
206 while( istream >> word ) words.push_back( word );
199 inline std::vector< std::string >
ReadWords(
const std::string &fileName ) {
…}
int read(char **argv, int argc)
Definition cmdLineParser.inl:77
Type values[Dim]
Definition cmdLineParser.h:85
CmdLineParameterArray(const std::string &name, const Type *v=NULL)
Definition cmdLineParser.inl:70
Type value
Definition cmdLineParser.h:66
CmdLineParameter(const std::string &name)
Definition cmdLineParser.inl:50
int read(char **argv, int argc)
Definition cmdLineParser.inl:55
~CmdLineParameters(void)
Definition cmdLineParser.inl:95
int read(char **argv, int argc)
Definition cmdLineParser.inl:103
CmdLineParameters(const std::string &name)
Definition cmdLineParser.inl:92
Definition cmdLineParser.h:41
bool set
Definition cmdLineParser.h:44
virtual int read(char **argv, int argc)
Definition cmdLineParser.inl:45
virtual ~CmdLineReadable(void)
Definition cmdLineParser.inl:43
CmdLineReadable(const std::string &name)
Definition cmdLineParser.inl:41
#define THROW(...)
Definition exceptions.h:151
#define WARN(...)
Definition exceptions.h:145
CmdLineReadable * params[]
Definition main1.cpp:37
std::string GetFileDirectory(const std::string &fileName)
Definition cmdLineParser.inl:183
void CmdLineParse(int argc, char **argv, CmdLineReadable **params)
Definition cmdLineParser.inl:125
std::string ToLower(const std::string &str)
Definition cmdLineParser.inl:158
static const char FileSeparator
Definition cmdLineParser.h:120
std::string GetLocalFileName(const std::string &fileName)
Definition cmdLineParser.inl:175
std::string ToUpper(const std::string &str)
Definition cmdLineParser.inl:149
std::string GetFileName(const std::string &directory, const std::string &localFileName)
Definition cmdLineParser.inl:191
std::string GetFileExtension(const std::string &fileName)
Definition cmdLineParser.inl:167
std::vector< std::string > ReadWords(const std::string &fileName)
Definition cmdLineParser.inl:199