IT++ Logo
Public Member Functions | List of all members
itpp::Parser Class Reference

Argument Parser Class. More...

#include <itpp/base/parser.h>

Public Member Functions

 Parser ()
 Default Constructor. More...
 
 Parser (const std::string &filename)
 Constructor. Sets input file name. More...
 
 Parser (int argc, char *argv[])
 Constructor. Uses argc and argv (command line arguments) More...
 
 Parser (const std::string &filename, int argc, char *argv[])
 Constructor. Sets input file name and uses argc and argv (command line arguments) More...
 
 Parser (const Array< std::string > &setup)
 Constructor. Sets and Array of strings. More...
 
void init (const std::string &filename)
 Initialization function. Sets input file name. More...
 
void init (int argc, char *argv[])
 Initialization function. Uses argc and argv (command line arguments) More...
 
void init (const std::string &filename, int argc, char *argv[])
 Initialization function. Sets input file name and uses argc and argv (command line arguments) More...
 
void init (const Array< std::string > &setup)
 Initialization function. Sets and Array of strings. More...
 
void set_silentmode (bool v=true)
 Sets silent mode if true, or verbose mode if false. More...
 
bool exist (const std::string &name)
 Check is name exists in the file. Returns true if the name is found and false otherwise. More...
 
template<class T >
bool get (T &var, const std::string &name, int num=-1)
 Get variable value if name can be found (and return true), otherwise keep old value (and return false) More...
 
bool get_bool (const std::string &name, int num=-1)
 Interpret variable name as a bool. More...
 
int get_int (const std::string &name, int num=-1)
 Interpret variable name as an integer. More...
 
double get_double (const std::string &name, int num=-1)
 Interpret variable name as a double. More...
 
std::string get_string (const std::string &name, int num=-1)
 Interpret variable name as a string. More...
 
vec get_vec (const std::string &name, int num=-1)
 Interpret variable name as a vec. More...
 
ivec get_ivec (const std::string &name, int num=-1)
 Interpret variable name as a ivec. More...
 
svec get_svec (const std::string &name, int num=-1)
 Interpret variable name as a svec. More...
 
bvec get_bvec (const std::string &name, int num=-1)
 Interpret variable name as a bvec. More...
 
mat get_mat (const std::string &name, int num=-1)
 Interpret variable name as a mat. More...
 
imat get_imat (const std::string &name, int num=-1)
 Interpret variable name as a imat. More...
 
smat get_smat (const std::string &name, int num=-1)
 Interpret variable name as a smat. More...
 
bmat get_bmat (const std::string &name, int num=-1)
 Interpret variable name as a bmat. More...
 
template<>
bool get (std::string &var, const std::string &name, int num)
 Specialization or get() for std::string. More...
 
template<>
bool get (int &var, const std::string &name, int num)
 Specialization of get() for int. More...
 
template<>
bool get (bool &var, const std::string &name, int num)
 Specialization of get() for bool. More...
 

Detailed Description

Argument Parser Class.

Author
Thomas Eriksson and Pal Frenger (Thanks to Svante Signell for valuable input)

This class parses strings to variables. The syntax is compatible with Matlab and Octave. It can be used in several different ways. See the Detailed Description in the Argument Parser module.

Definition at line 111 of file parser.h.

Constructor & Destructor Documentation

◆ Parser() [1/5]

itpp::Parser::Parser ( )

Default Constructor.

Definition at line 42 of file parser.cpp.

◆ Parser() [2/5]

itpp::Parser::Parser ( const std::string &  filename)

Constructor. Sets input file name.

Definition at line 47 of file parser.cpp.

References init().

◆ Parser() [3/5]

itpp::Parser::Parser ( int  argc,
char *  argv[] 
)

Constructor. Uses argc and argv (command line arguments)

Definition at line 53 of file parser.cpp.

References init().

◆ Parser() [4/5]

itpp::Parser::Parser ( const std::string &  filename,
int  argc,
char *  argv[] 
)

Constructor. Sets input file name and uses argc and argv (command line arguments)

Definition at line 59 of file parser.cpp.

References init().

◆ Parser() [5/5]

itpp::Parser::Parser ( const Array< std::string > &  setup)

Constructor. Sets and Array of strings.

Definition at line 65 of file parser.cpp.

References init().

Member Function Documentation

◆ init() [1/4]

void itpp::Parser::init ( const std::string &  filename)

Initialization function. Sets input file name.

Definition at line 272 of file parser.cpp.

References it_assert, itpp::Array< T >::set_size(), and itpp::Array< T >::size().

Referenced by Parser().

◆ init() [2/4]

void itpp::Parser::init ( int  argc,
char *  argv[] 
)

Initialization function. Uses argc and argv (command line arguments)

Definition at line 289 of file parser.cpp.

References itpp::Array< T >::set_size().

◆ init() [3/4]

void itpp::Parser::init ( const std::string &  filename,
int  argc,
char *  argv[] 
)

Initialization function. Sets input file name and uses argc and argv (command line arguments)

Definition at line 300 of file parser.cpp.

References it_assert, itpp::Array< T >::set_size(), and itpp::Array< T >::size().

◆ init() [4/4]

void itpp::Parser::init ( const Array< std::string > &  setup)

Initialization function. Sets and Array of strings.

Definition at line 324 of file parser.cpp.

◆ set_silentmode()

void itpp::Parser::set_silentmode ( bool  v = true)

Sets silent mode if true, or verbose mode if false.

Definition at line 330 of file parser.cpp.

◆ exist()

bool itpp::Parser::exist ( const std::string &  name)

Check is name exists in the file. Returns true if the name is found and false otherwise.

Definition at line 335 of file parser.cpp.

◆ get() [1/4]

template<class T >
bool itpp::Parser::get ( T &  var,
const std::string &  name,
int  num = -1 
)

Get variable value if name can be found (and return true), otherwise keep old value (and return false)

Definition at line 209 of file parser.h.

◆ get_bool()

bool itpp::Parser::get_bool ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a bool.

Definition at line 425 of file parser.cpp.

References it_assert, and it_error.

◆ get_int()

int itpp::Parser::get_int ( const std::string &  name,
int  num = -1 
)

Interpret variable name as an integer.

Definition at line 445 of file parser.cpp.

References it_assert.

◆ get_double()

double itpp::Parser::get_double ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a double.

Definition at line 459 of file parser.cpp.

References it_error.

◆ get_string()

std::string itpp::Parser::get_string ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a string.

Definition at line 470 of file parser.cpp.

References it_error.

◆ get_vec()

vec itpp::Parser::get_vec ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a vec.

Definition at line 480 of file parser.cpp.

References it_error.

◆ get_ivec()

ivec itpp::Parser::get_ivec ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a ivec.

Definition at line 490 of file parser.cpp.

References it_error.

◆ get_svec()

svec itpp::Parser::get_svec ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a svec.

Definition at line 500 of file parser.cpp.

References it_error.

◆ get_bvec()

bvec itpp::Parser::get_bvec ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a bvec.

Definition at line 510 of file parser.cpp.

References it_error.

◆ get_mat()

mat itpp::Parser::get_mat ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a mat.

Definition at line 520 of file parser.cpp.

References it_error.

◆ get_imat()

imat itpp::Parser::get_imat ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a imat.

Definition at line 530 of file parser.cpp.

References it_error.

◆ get_smat()

smat itpp::Parser::get_smat ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a smat.

Definition at line 540 of file parser.cpp.

References it_error.

◆ get_bmat()

bmat itpp::Parser::get_bmat ( const std::string &  name,
int  num = -1 
)

Interpret variable name as a bmat.

Definition at line 550 of file parser.cpp.

References it_error.

◆ get() [2/4]

template<>
ITPP_EXPORT bool itpp::Parser::get ( std::string &  var,
const std::string &  name,
int  num 
)

Specialization or get() for std::string.

Definition at line 348 of file parser.cpp.

◆ get() [3/4]

template<>
ITPP_EXPORT bool itpp::Parser::get ( int &  var,
const std::string &  name,
int  num 
)

Specialization of get() for int.

Definition at line 370 of file parser.cpp.

References it_assert.

◆ get() [4/4]

template<>
ITPP_EXPORT bool itpp::Parser::get ( bool &  var,
const std::string &  name,
int  num 
)

Specialization of get() for bool.

Definition at line 395 of file parser.cpp.

References it_error.


The documentation for this class was generated from the following files:
SourceForge Logo

Generated on Sun Jun 5 2022 21:26:42 for IT++ by Doxygen 1.9.3