Loading...
Searching...
No Matches
LongParameters Class Reference
Inheritance diagram for LongParameters:
[legend]
Collaboration diagram for LongParameters:
[legend]

## Public Member Functions

| LongParameters (const char *desc, LongParameterList *list)
virtual void | Status ()
virtual void | addParamsToString (String &params)
LongParameters * | SetPrecision (int precision)
Public Member Functions inherited from Parameter
| Parameter (char c, const char *desc, void *v)
virtual bool | Read (int argc, char **argv, int argn)
void | SetWarningBuffer (String &buffer)
void | warning (const char *format,...)

## Protected Member Functions

virtual void | Translate (const char *value)
virtual bool | TranslateExtras (const char *value, const char *extras)
void | ExplainAmbiguity (const char *value)
void | Status (LongParameterList *ptr, int &line_len, bool &need_a_comma)

## Protected Attributes

StringMap | index
StringMap | legacyIndex
LongParameterList * | list
int | group_len
int | precision
Protected Attributes inherited from Parameter
char | ch
char * | description
void * | var
String * | warnings
bool | myNoPhoneHome
String | myVersion

## Additional Inherited Members

Static Public Member Functions inherited from Parameter
static void | SetNameLen (int len)
static void | SetStatusLen (int len)
Static Protected Member Functions inherited from Parameter
static bool | CheckInteger (const char *value)
static bool | CheckDouble (const char *value)
Static Protected Attributes inherited from Parameter
static const char | PARAM_STR_SEP = ','
static int | nameCol = 30
static int | statusCol = 15

## Detailed Description

Definition at line 265 of file Parameters.h.

## Constructor & Destructor Documentation

## LongParameters()

LongParameters::LongParameters | ( | const char * | desc,
|  | LongParameterList * | list
| ) |  |

Definition at line 291 of file Parameters.cpp.

: Parameter('-', desc, NULL)
{
list = lst;
index.Clear();
legacyIndex.Clear();
group_len = 0;
LongParameterList * ptr = list + 1;
while (ptr->description != NULL)
{
if (ptr->type == LP_LEGACY_PARAMETERS)
break;
if(ptr->type == LP_PHONEHOME_VERSION)
{
// Phone home is turned on, so add
// the parameter for the user to turn it off.
myNoPhoneHome = false;
myVersion = ptr->description;
ptr->description = "noPhoneHome";
ptr->value = &myNoPhoneHome;
ptr->type = LP_BOOL_PARAMETER;
index.Add(ptr->description, ptr);
}
else
{
if (ptr->value != NULL)
index.Add(ptr->description, ptr);
else
group_len = max(strlen(ptr->description), group_len);
}
ptr++;
}
while (ptr->description != NULL)
{
if(ptr->type == LP_PHONEHOME_VERSION)
{
// Phone home is turned on, so add
// the parameter for the user to turn it off.
myNoPhoneHome = false;
myVersion = ptr->description;
ptr->description = "noPhoneHome";
ptr->value = &myNoPhoneHome;
ptr->type = LP_BOOL_PARAMETER;
legacyIndex.Add(ptr->description, ptr);
}
else
{
if (ptr->value != NULL)
legacyIndex.Add(ptr->description, ptr);
}
ptr++;
}
precision = 2;
}
Parameter
Definition Parameters.h:30
LongParameterList
Definition Parameters.h:237

## Member Function Documentation

## addParamsToString()

void LongParameters::addParamsToString | ( | String & | params | ) |

virtual

Reimplemented from Parameter.

Definition at line 579 of file Parameters.cpp.

{
for (LongParameterList * ptr = list + 1; ptr->description != NULL; ptr++)
{
if (ptr->touched)
{
if(!params.IsEmpty())
{
params += PARAM_STR_SEP;
}
params += ptr->description;
}
}
}

## ExplainAmbiguity()

void LongParameters::ExplainAmbiguity | ( | const char * | value | ) |

protected

Definition at line 351 of file Parameters.cpp.

{
String value(cstr);
int p = value.FastFindChar(':');
String stem = p == -1 ? value : value.Left(p);
String matches;
for (int i = 0; i < index.Length(); i++)
if (index[i].SlowCompareToStem(stem) == 0)
{
if (matches.Length() + index[i].Length() > 50)
{
matches += " ...";
break;
}
matches.catprintf(" --%s", (const char *) index[i]);
}
warning("Ambiguous --%s matches%s\n",
(const char *) value, (const char *) matches);
}
String
Definition StringBasics.h:39

## SetPrecision()

LongParameters * LongParameters::SetPrecision | ( | int | precision | ) |

inline

Definition at line 273 of file Parameters.h.

{
this->precision = precision;
return this;
}

## Status() [1/2]

void LongParameters::Status | ( |  | ) |

virtual

Implements Parameter.

Definition at line 547 of file Parameters.cpp.

{
if (description != NULL && description[0] != 0)
fprintf(stderr, "\n%s\n", description);
bool need_a_comma = false;
int line_len = 0;
bool legacy_parameters = false;
int legacy_count = 0;
for (LongParameterList * ptr = list + 1; ptr->description != NULL; ptr++)
if (ptr->type == LP_LEGACY_PARAMETERS)
legacy_parameters = true;
else if (legacy_parameters == false)
Status(ptr, line_len, need_a_comma);
else if (ptr->touched)
{
if (legacy_count == 0)
{
fprintf(stderr, "\n\nAdditional Options:\n %*s ", group_len + 3, "");
line_len = group_len + 5;
need_a_comma = false;
}
Status(ptr, line_len, need_a_comma);
legacy_count++;
}
fprintf(stderr, "\n");
}

## Status() [2/2]

void LongParameters::Status | ( | LongParameterList * | ptr,
|  | int & | line_len,
|  | bool & | need_a_comma
| ) |  |

protected

Definition at line 492 of file Parameters.cpp.

{
String state;
int line_start = group_len ? group_len + 5 : 0;
if (ptr->value == NULL)
{
fprintf(stderr, "%s %*s :", need_a_comma ? "\n" : "", group_len + 2, ptr->description);
need_a_comma = false;
line_len = line_start;
}
else
{
if (ptr->type == LP_BOOL_PARAMETER)
state = * (bool *) ptr->value ? " [ON]" : "";
else if (ptr->type == LP_INT_PARAMETER)
if (((* (int *) ptr->value == 1) && (ptr->exclusive)) || (* (int *) ptr->value == 0))
state = * (int *) ptr->value ? " [ON]" : "";
else
state = " [", state += * (int *) ptr->value, state += ']';
else if (ptr->type == LP_DOUBLE_PARAMETER)
if (* (double *) ptr->value != _NAN_)
{
double value = * (double *) ptr->value;
state = " [";
if (value == 0.0 || value >= 0.01)
state.catprintf("%.*f", precision, value);
else
state.catprintf("%.1e", value);
state += ']';
}
else
state = "";
else if (ptr->type == LP_STRING_PARAMETER)
state = " [" + * (String *) ptr->value + "]";
int item_len = 3 + strlen(ptr->description) + need_a_comma + state.Length();
if (item_len + line_len > 78 && line_len > line_start)
{
line_len = line_start;
fprintf(stderr, "%s\n%*s", need_a_comma ? "," : "", line_len, "");
need_a_comma = 0;
item_len -= 1;
}
fprintf(stderr, "%s --%s%s", need_a_comma ? "," : (need_a_comma = true, ""),
ptr->description, (const char *) state);
need_a_comma = true;
line_len += item_len;
}
}

## Translate()

void LongParameters::Translate | ( | const char * | value | ) |

protected virtual

Implements Parameter.

Definition at line 375 of file Parameters.cpp.

{
String value(cstr);
int p = value.FastFindChar(':');
int option = p == -1 ? index.FindStem(value) : index.FindStem(value.Left(p));
if (option == -2)
{
ExplainAmbiguity(cstr);
return;
}
LongParameterList * ptr;
if (option >= 0)
ptr = (LongParameterList *) index.Object(option);
else
{
int alternate = p == -1 ? legacyIndex.FindFirstStem(value) :
legacyIndex.FindFirstStem(value.Left(p));
if (alternate < 0)
{
warning("Command line parameter --%s is undefined\n", (const char *) value);
return;
}
ptr = (LongParameterList *) legacyIndex.Object(alternate);
ptr->touched = true;
}
ptr->touched = true;
if (ptr->type == LP_BOOL_PARAMETER)
{
if (p == -1)
* (bool *) ptr->value ^= true;
else
*(bool *) ptr->value = value.SubStr(p + 1).SlowCompare("ON") == 0;
// In exclusive groups, only one option may be selected
if (ptr->exclusive)
{
for (int i = -1; ptr[i].exclusive; i--) *(bool *)ptr[i].value = false;
for (int i = 1; ptr[i].exclusive; i++) *(bool *)ptr[i].value = false;
}
}
else if (ptr->type == LP_INT_PARAMETER)
if (p == -1)
* (int *) ptr->value = * (int *) ptr->value ? 0 : 1;
else
*(int *) ptr->value = value.SubStr(p + 1).SlowCompare("ON") == 0 ?
1 : value.SubStr(p + 1).AsInteger();
else if (ptr->type == LP_DOUBLE_PARAMETER)
{
if (p != -1)
* (double *) ptr->value = value.SubStr(p + 1).AsDouble();
}
else if (ptr->type == LP_STRING_PARAMETER)
{
if (p != -1)
* (String *) ptr->value = value.SubStr(p + 1);
}
}

## TranslateExtras()

bool LongParameters::TranslateExtras | ( | const char * | value,
|  | const char * | extras
| ) |  |

protected virtual

Reimplemented from Parameter.

Definition at line 440 of file Parameters.cpp.

{
if (strchr(cstr, ':') != NULL)
return false;
int option = index.FindStem(cstr);
if (option == -2)
{
// No need to explain ambiguity here ... will be handle by later call
// to Translate()
// ExplainAmbiguity(cstr);
return false;
}
LongParameterList * ptr;
if (option >= 0)
ptr = (LongParameterList *) index.Object(option);
else
{
option = legacyIndex.FindFirstStem(cstr);
if (option < 0)
return false;
ptr = (LongParameterList *) legacyIndex.Object(option);
ptr->touched = true;
}
if (ptr->type == LP_INT_PARAMETER && CheckInteger(extras))
{
*(int *) ptr->value = atoi(extras);
ptr->touched = true;
return true;
}
else if (ptr->type == LP_DOUBLE_PARAMETER && CheckDouble(extras))
{
*(double *) ptr->value = atof(extras);
ptr->touched = true;
return true;
}
else if (ptr->type == LP_STRING_PARAMETER)
{
*(String *) ptr->value = extras;
ptr->touched = true;
return true;
}
return false;
}

## Member Data Documentation

## group_len

int LongParameters::group_len

protected

Definition at line 285 of file Parameters.h.

## index

StringMap LongParameters::index

protected

Definition at line 281 of file Parameters.h.

## legacyIndex

StringMap LongParameters::legacyIndex

protected

Definition at line 282 of file Parameters.h.

## list

LongParameterList* LongParameters::list

protected

Definition at line 284 of file Parameters.h.

## precision

int LongParameters::precision

protected

Definition at line 286 of file Parameters.h.

The documentation for this class was generated from the following files:

- general/Parameters.h
- general/Parameters.cpp