parser.h
Go to the documentation of this file.
#ifndef PARSER_H
#define PARSER_H
// #define MAX_STR_LEN 4096
#include <itpp/base/vec.h>
#include <itpp/base/mat.h>
#include <itpp/base/array.h>
#include <iostream>
#include <itpp/itexports.h>
namespace itpp
{
#if (defined(_MSC_VER) && defined(ITPP_SHARED_LIB))
//MSVC explicitely instantiate required template while building the shared library
template class ITPP_EXPORT Array<std::string>;
#endif
class ITPP_EXPORT Parser
{
public:
Parser();
Parser(const std::string &filename);
Parser(int argc, char *argv[]);
Parser(const std::string &filename, int argc, char *argv[]);
Parser(const Array<std::string> &setup);
void init(const std::string &filename);
void init(int argc, char *argv[]);
void init(const std::string &filename, int argc, char *argv[]);
void init(const Array<std::string> &setup);
void set_silentmode(bool v = true);
bool exist(const std::string &name);
template<class T>
bool get(T &var, const std::string &name, int num = -1);
bool get_bool(const std::string &name, int num = -1);
int get_int(const std::string &name, int num = -1);
double get_double(const std::string &name, int num = -1);
std::string get_string(const std::string &name, int num = -1);
vec get_vec(const std::string &name, int num = -1);
ivec get_ivec(const std::string &name, int num = -1);
svec get_svec(const std::string &name, int num = -1);
bvec get_bvec(const std::string &name, int num = -1);
mat get_mat(const std::string &name, int num = -1);
imat get_imat(const std::string &name, int num = -1);
smat get_smat(const std::string &name, int num = -1);
bmat get_bmat(const std::string &name, int num = -1);
protected:
private:
std::string findname(const std::string &name,
bool &error_flag,
bool &print_flag,
int num = 0,
bool keep_brackets = false);
void pre_parsing(void);
Array<std::string> SetupStrings;
bool VERBOSE;
};
// ----------------------- Implementation starts here -----------------------
template<class T>
bool Parser::get(T &var, const std::string &name, int num)
{
bool error_flag, print_flag;
std::string str = findname(name, error_flag, print_flag, num, true);
std::istringstream buffer(str);
if (error_flag) {
if (VERBOSE) {
std::cout << name << " = " << var << ";" << std::endl;
}
}
else {
buffer >> var;
if (print_flag) {
std::cout << name << " = " << var << std::endl;
}
else if (VERBOSE) {
std::cout << name << " = " << var << ";" << std::endl;
}
}
return !error_flag;
}
template<>
ITPP_EXPORT bool Parser::get(std::string &var, const std::string &name, int num);
template<>
ITPP_EXPORT bool Parser::get(int &var, const std::string &name, int num);
template<>
ITPP_EXPORT bool Parser::get(bool &var, const std::string &name, int num);
} // namespace itpp
#endif // #ifndef PARSER_H
itpp::Array< std::string >
std
STL namespace.
itpp::Parser::get
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...
Definition: parser.h:209
array.h
Definition of Array class (container)
itpp::Parser
Argument Parser Class.
Definition: parser.h:111
mat.h
Matrix Class Definitions.
itpp
itpp namespace
Definition: itmex.h:36
itpp::exist
bool exist(const std::string &name)
Checks if a file named name already exists on the disk.
Definition: binfile.cpp:98
bmat
Mat< bin > bmat
bin matrix
Definition: mat.h:508
vec.h
Templated Vector Class Definitions.

Generated on Thu Aug 20 2015 21:02:50 for IT++ by Doxygen 1.8.9.1