31 #ifdef HAVE_LIBREADLINE
33 #include <readline/readline.h>
43 #define G_STRING_SET "GApplicationPar::string(std::string&)"
44 #define G_FILENAME_SET "GApplicationPar::filename(GFilename&)"
45 #define G_TIME_SET "GApplicationPar::time(GTime&)"
46 #define G_BOOLEAN_SET "GApplicationPar::boolean(bool&)"
47 #define G_INTEGER_SET "GApplicationPar::integer(int&)"
48 #define G_REAL_SET "GApplicationPar::real(double&)"
49 #define G_STRING_GET "GApplicationPar::string()"
50 #define G_FILENAME_GET "GApplicationPar::filename()"
51 #define G_TIME_GET "GApplicationPar::time()"
52 #define G_BOOLEAN_GET "GApplicationPar::boolean()"
53 #define G_INTEGER_GET "GApplicationPar::integer()"
54 #define G_REAL_GET "GApplicationPar::real()"
55 #define G_CHECK_TYPE "GApplicationPar::check_type(std::string)"
56 #define G_CHECK_MODE "GApplicationPar::check_mode(std::string)"
57 #define G_CHECK_VALUE_BOOL "GApplicationPar::check_value_bool(std::string)"
58 #define G_CHECK_VALUE_INT "GApplicationPar::check_value_int(std::string&)"
59 #define G_CHECK_VALUE_REAL "GApplicationPar::check_value_real(std::string&)"
60 #define G_CHECK_OPTIONS "GApplicationPar::check_options(std::string&)"
102 const std::string& type,
103 const std::string& mode,
104 const std::string& value,
105 const std::string&
min,
106 const std::string&
max,
107 const std::string& prompt)
304 " parameter \""+
m_name+
"\" with string value.";
332 " parameter \""+
m_name+
"\" with filename value.";
361 " parameter \""+
m_name+
"\" with filename value.";
389 " parameter \""+
m_name+
"\" with boolean value.";
394 std::string value_string = (
value) ?
"yes" :
"no";
420 " parameter \""+
m_name+
"\" with integer value.";
451 " parameter \""+
m_name+
"\" with real value.";
479 if (
m_min.length() > 0 &&
m_max.length() > 0) {
482 else if (
m_min.length() > 0) {
483 prompt +=
" ("+
m_min+
")";
485 else if (
m_max.length() > 0) {
486 prompt +=
" ("+
m_max+
")";
491 #ifdef HAVE_LIBREADLINE
493 char* line = readline(prompt.c_str());
495 value = std::string(line);
501 std::cin.getline(line, 1000);
502 std::string value = std::string(line);
509 if (value.length() > 0) {
555 " parameter \""+
m_name+
"\" as a string value.";
564 std::string msg =
"Parameter \""+
m_name+
"\" is "+
591 " parameter \""+
m_name+
"\" as a filename value.";
600 std::string msg =
"Parameter \""+
m_name+
"\" is "+
630 " parameter \""+
m_name+
"\" as a time value.";
639 std::string msg =
"Parameter \""+
m_name+
"\" is "+
665 " parameter \""+
m_name+
"\" as a boolean value.";
674 std::string msg =
"Parameter \""+
m_name+
"\" is "+
684 bool result = (uvalue ==
"YES" || uvalue ==
"Y" ||
685 uvalue ==
"TRUE" || uvalue ==
"T");
707 " parameter \""+
m_name+
"\" as a integer value.";
716 std::string msg =
"Parameter \""+
m_name+
"\" is "+
745 " parameter \""+
m_name+
"\" as a real value.";
754 std::string msg =
"Parameter \""+
m_name+
"\" is "+
892 std::vector<std::string>
string(10);
934 result.append(
"undefined");
937 result.append(
"nan");
940 result.append(
m_value+
" (underflow)");
943 result.append(
m_value+
" (overflow)");
948 if (
min().length() > 0 &&
max().length() > 0) {
949 result.append(
" ("+
min()+
"-"+
max()+
")");
951 else if (
min().length() > 0) {
952 result.append(
" ("+
min()+
")");
956 result.append(
" [t="+
type()+
", m="+
mode()+
"]");
1042 if (type !=
"b" && type !=
"i" && type !=
"r" && type !=
"s" &&
1043 type !=
"f" && type !=
"fr" && type !=
"fw" && type !=
"fe" &&
1044 type !=
"fn" && type !=
"t") {
1045 std::string msg =
"Invalid parameter type \""+type+
"\" encountered"
1046 " for parameter \""+
m_name+
"\".";
1068 if (mode !=
"a" && mode !=
"h" && mode !=
"q" && mode !=
"hl" &&
1069 mode !=
"ql" && mode !=
"lh" && mode !=
"lq") {
1070 std::string msg =
"Invalid parameter mode \""+mode+
"\" encountered"
1071 " for parameter \""+
m_name+
"\".";
1094 else if (
m_type ==
"i") {
1097 else if (
m_type ==
"r") {
1100 else if (
m_type ==
"s") {
1103 else if (
m_type ==
"t") {
1132 if (lvalue !=
"y" && lvalue !=
"yes" && lvalue !=
"true" && lvalue !=
"t" &&
1133 lvalue !=
"n" && lvalue !=
"no" && lvalue !=
"false" && lvalue !=
"f") {
1134 std::string msg =
"Invalid boolean value \""+value+
"\" encountered"
1135 " for parameter \""+
m_name+
"\". Use"
1136 " y/n/yes/no/t/f/true/false";
1169 if (!has_options &&
m_min.length() > 0 &&
m_max.length() > 0) {
1173 std::string msg =
"Parameter \""+
m_name+
"\" value \""+value+
1174 "\" outside validity range ["+
m_min+
","+
1185 if (imin > ivalue || imax < ivalue) {
1186 std::string msg =
"Parameter \""+
m_name+
"\" value \""+value+
1187 "\" outside validity range ["+
m_min+
","+
1225 if (!has_options &&
m_min.length() > 0 &&
m_max.length() > 0) {
1229 std::string msg =
"Parameter \""+
m_name+
"\" value \""+value+
1230 "\" outside validity range ["+
m_min+
","+
1241 if (dmin > dvalue || dmax < dvalue) {
1242 std::string msg =
"Parameter \""+
m_name+
"\" value \""+value+
1243 "\" outside validity range ["+
m_min+
","+
1340 bool has_options =
false;
1343 if (
m_max.length() == 0) {
1349 int num_options = options.size();
1352 if (num_options > 0) {
1362 for (
int i = 0; i < num_options; ++i) {
1373 for (
int i = 0; i < num_options; ++i) {
1374 if (options[i] == v) {
1382 std::string msg =
"Parameter \""+
m_name+
"\" value \""+value+
1383 "\" invalid. Must be one of \""+
m_min+
"\".";
1421 std::string result =
value;
1428 if (lvalue ==
"indef" ||
1430 lvalue ==
"undef" ||
1431 lvalue ==
"undefined") {
1434 else if (lvalue ==
"inf" ||
1435 lvalue ==
"infinity" ||
1447 else if (
m_type ==
"r") {
1449 if (lvalue ==
"indef" ||
1451 lvalue ==
"undef" ||
1452 lvalue ==
"undefined") {
1455 else if (lvalue ==
"inf" ||
1456 lvalue ==
"infinity" ||
1467 else if (
m_type ==
"t") {
1469 if (lvalue ==
"indef" ||
1471 lvalue ==
"undef" ||
1472 lvalue ==
"undefined") {
1482 else if (
m_type ==
"f") {
1485 lvalue ==
"indef" ||
1487 lvalue ==
"undef" ||
1488 lvalue ==
"undefined") {
1560 std::string type_string =
"";
1564 type_string.append(
"boolean");
1566 else if (type ==
"i") {
1567 type_string.append(
"integer");
1569 else if (type ==
"r") {
1570 type_string.append(
"real");
1572 else if (type ==
"s") {
1573 type_string.append(
"string");
1575 else if (type ==
"f" || type ==
"fr" || type ==
"fw" ||
1576 type ==
"fe" || type ==
"fn") {
1577 type_string.append(
"filename");
1579 else if (type ==
"t") {
1580 type_string.append(
"time");
1583 type_string.append(
"unknown");
1604 status.append(
"valid");
1607 status.append(
"undefined");
1610 status.append(
"NaN");
1613 status.append(
"underflow");
1616 status.append(
"overflow");
const std::string & prompt(void) const
Returns parameter prompt.
bool is_learn(void) const
Signals if parameter mode is "learn".
void copy_members(const GApplicationPar &par)
Copy class members.
Status m_status
Parameter status.
#define G_CHECK_VALUE_REAL
bool m_queried
Signal that parameter was queried.
#define G_CHECK_VALUE_BOOL
bool was_queried(void) const
Signals if parameter was queried.
std::string m_name
Parameter name.
GApplicationPar & operator=(const GApplicationPar &par)
Assignment operator.
bool is_valid(void)
Signals if parameter is valid.
bool m_update
Signal value updating.
void check_value_bool(const std::string &value) const
Test validity of boolean value string.
virtual ~GApplicationPar(void)
Destructor.
std::string par_type_string(const std::string &type) const
Return type string.
bool is_undefined(void)
Signals if parameter is undefined.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
bool boolean(void)
Returns boolean.
void check_type(const std::string &type) const
Test validity of type string.
Application parameter class definition.
void check_value_real(const std::string &value) const
Test validity of real parameter value.
double min(const GVector &vector)
Computes minimum vector element.
#define G_STRING_SET
< Needed for declaration of LONG_MAX
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
int integer(void)
Returns integer.
GTime time(void)
Return time in native reference system.
GApplicationPar(void)
Void constructor.
std::string print(const GChatter &chatter=NORMAL) const
Print parameter.
bool is_notanumber(void)
Signals if parameter is not a number.
bool is_filename(void) const
Signals if parameter mode is of type "filename".
bool check_options(const std::string &value) const
Test if parameter value satisfies possible options.
void check_value_time(const std::string &value) const
Test validity of time parameter value.
void stop_query(void)
Don't query parameter again.
void clear(void)
Clear parameter.
std::string m_mode
Parameter mode.
#define G_CHECK_VALUE_INT
const std::string & type(void) const
Returns parameter type.
const std::string & name(void) const
Returns parameter name.
GApplicationPar * clone(void) const
Clone parameter.
const std::string & mode(void) const
Returns parameter mode.
std::string m_type
Parameter type.
std::vector< std::string > pickle(void) const
Return pickled string vector.
const std::string & max(void) const
Returns parameter maximum.
void check_value_filename(const std::string &value) const
Test validity of filename parameter value.
void init_members(void)
Initialise class members.
double real(void)
Returns real.
bool is_query(void) const
Signals if parameter mode is "query".
double max(const GVector &vector)
Computes maximum vector element.
void check_value_string(const std::string &value) const
Test validity of string parameter value.
std::string m_prompt
Parameter prompt.
void set_value(const std::string &value)
Set parameter value.
std::string m_min
Parameter minimum.
Exception handler interface definition.
void check_value_int(const std::string &value) const
Test validity of integer parameter value.
Application parameter class.
GFilename filename(void)
Returns filename parameter value.
std::string toupper(const std::string &s)
Convert string to upper case.
Implements a time reference.
std::string tolower(const std::string &s)
Convert string to lower case.
std::string string(void)
Returns string parameter value.
void free_members(void)
Delete class members.
void check_mode(const std::string &mode) const
Test validity of mode string.
const std::string & min(void) const
Returns parameter minimum.
int toint(const std::string &arg)
Convert string into integer value.
std::string par_status_string(void) const
Return status string.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void query(void)
Query parameter if required.
std::string utc(const int &precision=0) const
Return time as string in UTC time system.
Time class interface definition.
std::string m_max
Parameter maximum.
std::string set_status(const std::string &value)
Set parameter status.
Filename class interface definition.
double todouble(const std::string &arg)
Convert string into double precision value.
std::string value(void)
Returns parameter value as string.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
std::string m_value
Parameter value.
void check_value(const std::string &value) const
Test validity of value string.