1#ifndef AMPGEN_NAMEDPARAMETER_H
2#define AMPGEN_NAMEDPARAMETER_H
38 auto line = parser->find(
m_name);
39 if(line == parser->end())
return false;
40 const std::vector<std::string> &vsl = line->second;
41 if(vsl.size() < 2)
return false;
44 for(
unsigned int i = 1; i < vsl.size(); i++) {
48 ERROR(
"Failed to parse token: " << vsl[i] <<
" for parameter: " <<
m_name);
70 if(type ==
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >") type =
"string";
71 std::cout <<
" " <<
bold_on << std::left << std::setw(27) <<
m_name <<
bold_off << std::setw(20) <<
"[" + type +
"]";
73 if(tokens.size() == 0) std::cout << std::endl;
74 for(
size_t i = 0; i < tokens.size(); ++i) {
76 std::cout << tokens[i];
77 if(def != T()) std::cout <<
" (default = " << def <<
")";
78 std::cout << std::endl;
80 std::cout << std::string(48,
' ') << tokens[i] << std::endl;
88 ERROR(
"Parameter name \"" <<
name() <<
"\". Index: " << i <<
" out of range [ " << 0 <<
" , " <<
m_valueArray.size());
89 throw std::runtime_error(
"array index out of bounds");
94 operator T()
const {
return getVal(); }
119 std::vector<T> return_container;
121 T obj = default_value;
124 if(obj != T()) return_container.push_back(obj);
125 }
while(obj != default_value);
126 return return_container;
129 template <
typename T> std::ostream &
operator<<(std::ostream &os,
const NamedParameter<T> &np);
130 template <
typename... T> std::string
optionalHelpString(
const std::string &header,
const T &...args);
135 for(
size_t i = 0; i < np.
size(); i++) {
136 if(i == 0) os <<
" = ";
138 if(i != np.
size()) os <<
" ";
144 std::stringstream rt;
146 for_each(std::make_tuple(args...), [&rt](
const auto &f)
mutable { rt <<
"\n\033[3m " << f.first <<
"\033[0m: " << f.second; });
A parameter with value specified by the user at runtime, either in an options file or via the command...
void setVal(const std::vector< T > &valList)
const T getVal(int i=0) const
std::vector< T > m_valueArray
< The helper string for this parameter, printed if the flag –help is used.
bool operator==(const G &other) const
bool operator!=(const G &other) const
const std::vector< T > & getVector() const
NamedParameter< T > & operator=(const T &d)
NamedParameter(const std::string &name, const T &def=T(), const std::string &helpString="")
NamedParameter(const std::string &name, const std::vector< T > &defVec, const std::string &helpString="")
bool setFromOptionsParser()
< The value (array) of this parameter.
static std::vector< T > getVectorArgument(const std::string &name, const T &default_value)
const std::string & name() const
NamedParameter< T > & operator=(const std::vector< T > &v)
std::string m_helpString
< Name of this parameter
void setVal(const T &val, int i=0)
static OptionsParser * getMe()
#define ERROR(X)
Used for printing errors messages, and will always be printed.
#define DEBUG(X)
Used for printing verbose debugging messages, only if DEBUGLEVEL is defined.
std::string optionalHelpString(const std::string &header, const T &...args)
std::vector< std::string > split(const std::string &, char, bool=true)
std::ostream & operator<<(std::ostream &os, const CompiledExpressionBase &expression)
std::ostream & bold_on(std::ostream &)
std::ostream & bold_off(std::ostream &)
std::string type_string()
Utility classes for compile-time metaprogramming, such as identifying the types of arguments for gene...
return_type lexical_cast(const std::string &word, bool &status)
std::enable_if_t< I==sizeof...(Tp), void > for_each(std::tuple< Tp... > &, FuncT)