1#ifndef AMPGEN_PROPERTY_H
2#define AMPGEN_PROPERTY_H 1
33 Property(T *parent,
const std::string &
name,
const value_t &def = value_t(),
const std::string_view &helpString =
"")
35 setFromOptionsParser();
36 if constexpr(std::has_virtual_destructor<T>::value and not std::is_const_v<T>) {
43 Property(
const std::nullptr_t ,
const std::string &
name,
const value_t &def = value_t(),
const std::string_view &helpString =
"")
45 setFromOptionsParser();
52 operator const value_t &()
const {
return m_value; }
59 if constexpr(isVector<value_t>::value) {
61 for(
unsigned int i = 0; i < vsl.size(); i++) {
64 ERROR(
"Failed to parse token: " << vsl[i] <<
" for parameter: " <<
m_name);
68 }
else if constexpr(isTuple<value_t>::value) {
69 for_each_with_counter(
m_value, [
this, vsl](
auto &f,
unsigned i) {
71 using basic_t =
typename std::remove_const<
typename std::remove_reference<
decltype(f)>::type>::type;
73 if(!status) {
ERROR(
"Failed to parse token: " << vsl[i] <<
" for parameter: " << this->m_name); }
77 ERROR(
"Constructing parameter: " <<
m_name <<
" only one argument expected, but " << vsl.size() - 1 <<
" found");
78 for(
auto const &v : vsl)
ERROR(v);
83 ERROR(
"Failed to parse token: " << vsl[0] <<
" for parameter: " <<
m_name);
91 void help(
const value_t &def) {
94 if(std::is_same_v<value_t, std::string>) type =
"string";
95 if(std::is_same_v<value_t, std::vector<std::string>>) type =
"strings";
96 std::cout <<
" " <<
bold_on << std::left << std::setw(27) <<
m_name <<
bold_off << std::setw(20) <<
"[" + type +
"]";
98 if(tokens.size() == 0) std::cout << std::endl;
99 for(
size_t i = 0; i < tokens.size(); ++i) {
101 std::cout << tokens[i];
102 if constexpr(isVector<value_t>::value) {
103 if(def != value_t()) std::cout <<
" (default = {" <<
vectorToString(def,
",") <<
"})";
104 }
else if constexpr(isTuple<value_t>::value) {
105 if(def != value_t()) std::cout <<
" (default = [" <<
tupleToString(def,
",") <<
"])";
107 if(def != value_t()) std::cout <<
" (default = " << def <<
")";
109 std::cout << std::endl;
111 std::cout << std::string(48,
' ') << tokens[i] << std::endl;
114 bool setFromOptionsParser() {
116 auto line = parser->find(
m_name);
117 if(line == parser->end())
return false;
118 std::vector<std::string> vsl = line->second;
119 vsl.erase(vsl.begin());
124 template <
typename... T> std::string
helpStringOptions(
const std::string &header,
const T &...args);
129 os << np.
name() <<
" = ";
130 if constexpr(!isVector<T>::value)
133 for(
unsigned i{0}; i != np.
m_value.size(); ++i) os << np.
m_value[i] <<
" ";
139 std::stringstream rt;
141 for_each(std::make_tuple(args...), [&rt](
const auto &f)
mutable { rt <<
"\n\033[3m " << f.first <<
"\033[0m: " << f.second; });
static OptionsParser * getMe()
Properties are configurable characteristics of objects that will at some point inherit from a base cl...
Property(T *parent, const std::string &name, const value_t &def=value_t(), const std::string_view &helpString="")
const value_t & value() const
void set(const value_t &val)
bool operator!=(const T &other) const
bool operator==(const T &other) const
const std::string & name() const
friend std::ostream & operator<<(std::ostream &os, const Property< T > &np)
bool setFromStrings(const std::vector< std::string > &vsl)
Property(const std::nullptr_t, const std::string &name, const value_t &def=value_t(), const std::string_view &helpString="")
#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 tupleToString(const tuple_t &tuple, const std::string &delim)
std::string vectorToString(iterator_type begin, iterator_type end, const std::string &delim, functor_type fcn)
std::vector< std::string > split(const std::string &, char, bool=true)
std::ostream & operator<<(std::ostream &os, const CompiledExpressionBase &expression)
std::string helpStringOptions(const std::string &header, const T &...args)
std::ostream & bold_on(std::ostream &)
std::ostream & bold_off(std::ostream &)
std::string replaceAll(const std::string &input, const std::string &toReplace, const std::string &replaceWith)
std::string type_string()
Utility classes for compile-time metaprogramming, such as identifying the types of arguments for gene...
Expression operator==(const Expression &A, const Expression &B)
return_type lexical_cast(const std::string &word, bool &status)
std::enable_if_t< I==sizeof...(Tp), void > for_each(std::tuple< Tp... > &, FuncT)