19 #define PARAM_UNINITIALIZED (-1)
20 #define INFO_SPACER "\t "
22 #define PARAM_SWITCH1 '/'
23 #define PARAM_SWITCH2 '-'
38 Param(
const std::string& _argStr,
bool _isRequired)
52 Param(
const std::string& _argStr,
const std::string& _typeDescStr,
bool _isRequired)
65 virtual std::string
type()
const = 0;
68 virtual bool parse(
const char *arg) = 0;
71 virtual bool parse(
const wchar_t *arg)
73 std::wstring value = arg;
74 std::string str(value.begin(), value.end());
75 return parse(str.c_str());
92 virtual std::string
info(
bool isExtended)
const
121 std::cout <<
" <" <<
type() <<
">";
125 std::cout <<
" : " <<
info(isExtended);
181 if (!param1 || !param2)
return false;
182 bool val = ((param1->
argStr.compare(param2->
argStr) < 0));
200 :
Param(_argStr, _isRequired),
209 std::stringstream stream;
220 virtual std::string
type()
const {
222 return "integer: hex";
225 return "integer: dec";
227 return "integer: decimal, or hexadecimal with '0x' prefix";
237 if (!arg)
return false;
238 const size_t len = strlen(arg);
279 :
Param(_argStr, _isRequired)
287 return "\"" +
value +
"\"";
290 virtual std::string
type()
const {
296 return value.length() > 0;
301 if (!arg)
return false;
320 :
Param(_argStr, _isRequired)
329 return "\"" + str +
"\"";
332 virtual std::string
type()
const
339 return value.length() > 0;
342 virtual bool parse(
const wchar_t *arg)
344 if (!arg)
return false;
352 if (!arg)
return false;
354 std::string
value = arg;
374 :
Param(_argStr, _isRequired)
381 virtual std::string
type()
const
388 std::stringstream stream;
404 virtual bool parse(
const char *arg =
nullptr)
423 EnumParam(
const std::string& _argStr,
const std::string _enumName,
bool _isRequired)
447 return "(undefined)";
449 std::map<int, std::string>::const_iterator foundString =
enumToString.find(
value);
451 return foundString->second;
453 std::stringstream stream;
454 stream << std::dec <<
value;
458 virtual std::string
type()
const
489 std::map<int, std::string>::const_iterator itr;
491 const std::string valDesc = itr->second;
500 if (!arg)
return false;
503 const std::string strVal = arg;
504 std::map<int, std::string>::iterator itr;
506 if (strVal == itr->second) {
507 this->
value = itr->first;
521 this->
value = intVal;
532 std::stringstream stream;
540 std::stringstream stream;
541 std::map<int, std::string>::const_iterator itr;
542 stream <<
type() <<
":\n";
544 int val = itr->first;
545 std::map<int, std::string>::const_iterator foundString =
enumToString.find(itr->first);
547 stream <<
"\t" << std::dec << val;
549 stream <<
" (" << foundString->second <<
")";
552 stream << itr->second;
591 virtual std::string
type()
const
593 return "list: separated by \'" +
delimiter +
"\'";
606 IntListParam(
const std::string& _argStr,
bool _isRequired,
char _delimiter)
611 IntListParam(
const std::string& _argStr,
bool _isRequired, std::string _delimiter)
616 virtual std::string
type()
const
618 return "list: dec or hex, separated by \'" +
delimiter +
"\'";
623 if (!arg)
return false;
625 std::set<std::string> str_list;
629 std::set<std::string>::iterator itr;
630 for (itr = str_list.begin(); itr != str_list.end(); ++itr) {
631 std::string nextEl = *itr;
640 std::set<std::string> str_list;
644 std::set<std::string>::iterator itr;
645 for (itr = str_list.begin(); itr != str_list.end(); ++itr) {
646 std::string nextEl = *itr;
650 elements_list.insert(number);
652 return elements_list.size();
A parameter storing a boolean value.
virtual bool isSet() const
Returns true if the parameter is filled, false otherwise.
virtual std::string type() const
Returns the string representation of the parameter's type.
virtual std::string valToString() const
Returns the string representation of the parameter's value.
BoolParam(const std::string &_argStr, bool _isRequired)
virtual bool parse(const char *arg=nullptr)
Parses the parameter from the given string.
A parameter storing an enum value.
std::map< int, std::string > enumToInfo
required: info about the enum parameter
virtual std::string type() const
Returns the string representation of the parameter's type.
virtual bool parse(const char *arg)
Parses the parameter from the given string.
virtual std::string valToString() const
Returns the string representation of the parameter's value.
bool isKeywordInDescription(const std::string &keyword)
Checks if the description contains the keyword.
EnumParam(const std::string &_argStr, const std::string _enumName, bool _isRequired)
bool addEnumValue(int value, const std::string &info)
virtual bool isSet() const
Returns true if the parameter is filled, false otherwise.
std::map< int, std::string > enumToString
optional: string representation of the enum parameter
bool isInEnumScope(int intVal) const
virtual bool isKeywordInType(const std::string &keyword)
Checks if the parameter type contains the keyword.
bool addEnumValue(int value, const std::string &str_val, const std::string &info)
std::string optionsInfo() const
std::string extendedInfo() const
Extended information.
size_t stripToIntElements(OUT std::set< long > &elements_list)
IntListParam(const std::string &_argStr, bool _isRequired, char _delimiter)
virtual bool parse(const char *arg)
Parses the parameter from the given string.
IntListParam(const std::string &_argStr, bool _isRequired, std::string _delimiter)
virtual std::string type() const
Returns the string representation of the parameter's type.
A parameter storing an integer value.
bool isValidNumber(const char *arg, const size_t len)
virtual bool parse(const char *arg)
Parses the parameter from the given string.
virtual std::string valToString() const
Returns the string representation of the parameter's value.
virtual bool isSet() const
Returns true if the parameter is filled, false otherwise.
virtual std::string type() const
Returns the string representation of the parameter's type.
IntParam(const std::string &_argStr, bool _isRequired, t_int_base _base=INT_BASE_ANY)
A comparator class for Param class.
bool operator()(Param *param1, Param *param2) const
The class responsible for grouping parameters (objects of the type Param)
The base class of a parameter.
virtual bool parse(const char *arg)=0
Parses the parameter from the given string.
virtual std::string type() const =0
Returns the string representation of the parameter's type.
std::string argStr
a unique name of the parameter
std::string m_extInfo
an extended information about the the parameter's purpose
virtual std::string valToString() const =0
Returns the string representation of the parameter's value.
bool isRequired
a flag indicating if this parameter is required
virtual bool isNameSimilar(const std::string &filter)
Checks if the param name is similar to the given filter.
virtual std::string extendedInfo() const
Extended information.
virtual bool isSet() const =0
Returns true if the parameter is filled, false otherwise.
bool active
a flag indicating if this parameter is available
virtual std::string info(bool isExtended) const
bool requiredArg
a flag indicating if this parameter needs to be followed by a value
void printInColor(int color)
Prints the parameter using the given color. Appends the parameter switch to the name.
virtual bool isKeywordInDescription(const std::string &keyword)
Checks if the description contains the keyword.
Param(const std::string &_argStr, bool _isRequired)
A constructor of a parameter.
void setActive(bool _active)
virtual bool isActive() const
Returns true if the parameter is active, false otherwise.
std::string m_info
a basic information about the the parameter's purpose
virtual bool parse(const wchar_t *arg)
Parses the parameter from the given wide string.
void printDesc(bool isExtended=true) const
Prints a formatted description of the parameter, including its unique name, type, and the info.
std::string typeDescStr
a description of the type of the parameter: what type of values are allowed
Param(const std::string &_argStr, const std::string &_typeDescStr, bool _isRequired)
A constructor of a parameter.
virtual bool isKeywordInType(const std::string &keyword)
Checks if the parameter type contains the keyword.
The class responsible for storing and parsing parameters (objects of the type Param),...
const std::string delimiter
virtual std::string type() const
Returns the string representation of the parameter's type.
size_t stripToElements(OUT std::set< std::string > &elements_list)
StringListParam(const std::string &_argStr, bool _isRequired, char _delimiter)
StringListParam(const std::string &_argStr, bool _isRequired, std::string _delimiter)
A parameter storing a string value.
virtual bool parse(const char *arg)
Parses the parameter from the given string.
StringParam(const std::string &_argStr, bool _isRequired)
virtual std::string valToString() const
Returns the string representation of the parameter's value.
virtual std::string type() const
Returns the string representation of the parameter's type.
virtual bool isSet() const
Returns true if the parameter is filled, false otherwise.
size_t copyToCStr(char *buf, size_t buf_max) const
Copy the stored string value into an external buffer of a given length.
A parameter storing a wide string value.
virtual bool parse(const wchar_t *arg)
Parses the parameter from the given wide string.
virtual std::string valToString() const
Returns the string representation of the parameter's value.
virtual std::string type() const
Returns the string representation of the parameter's type.
virtual bool parse(const char *arg)
Parses the parameter from the given string.
WStringParam(const std::string &_argStr, bool _isRequired)
size_t copyToCStr(wchar_t *buf, size_t buf_len) const
Copy the stored string value into an external buffer of a given length.
virtual bool isSet() const
Returns true if the parameter is filled, false otherwise.
stringsim_type is_string_similar(const std::string ¶m, const std::string &filter)
stringsim_type has_keyword(const std::string param, const std::string filter)
bool loadBoolean(IN const T_CHAR *str1, OUT bool &value)
long get_number(const char *my_buf)
bool is_dec(const char *buf, size_t len)
void print_in_color(int color, const std::string &text)
bool is_number(const char *my_buf)
size_t strip_to_list(IN std::string s, IN std::string delim, OUT std::set< std::string > &elements_list)
size_t copy_to_cstr(T_STR value, T_CHAR *buf, size_t buf_count)
Copy the std::string/std::wstring value into an buffer of a given character count.
bool is_hex(const char *buf, size_t len)
int loadInt(const T_CHAR *str1, bool isHex=false)
bool is_hex_with_prefix(const char *buf)
#define PARAM_UNINITIALIZED
#define PARAM_SWITCH1
The switch used to recognize that the given string should be treated as a parameter (variant 1)
unsigned __int64 uint64_t
The set of utility functions used by the ParamKit.
The set of utility functions related with string processing, and finding similarity between strings.