libStatGen Software 1
Loading...
Searching...
No Matches
LongParameters Class Reference
Inheritance diagram for LongParameters:
Collaboration diagram for LongParameters:

Public Member Functions

 LongParameters (const char *desc, LongParameterList *list)
virtual void Status ()
virtual void addParamsToString (String &params)
LongParametersSetPrecision (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
LongParameterListlist
int group_len
int precision
Protected Attributes inherited from Parameter
char ch
char * description
void * var
Stringwarnings
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.

292 : Parameter('-', desc, NULL)
293{
294 list = lst;
295
296 index.Clear();
297 legacyIndex.Clear();
298 group_len = 0;
299
300 LongParameterList * ptr = list + 1;
301
302 while (ptr->description != NULL)
303 {
304 if (ptr->type == LP_LEGACY_PARAMETERS)
305 break;
306 if(ptr->type == LP_PHONEHOME_VERSION)
307 {
308 // Phone home is turned on, so add
309 // the parameter for the user to turn it off.
310 myNoPhoneHome = false;
311 myVersion = ptr->description;
312 ptr->description = "noPhoneHome";
313 ptr->value = &myNoPhoneHome;
314 ptr->type = LP_BOOL_PARAMETER;
315 index.Add(ptr->description, ptr);
316 }
317 else
318 {
319 if (ptr->value != NULL)
320 index.Add(ptr->description, ptr);
321 else
322 group_len = max(strlen(ptr->description), group_len);
323 }
324 ptr++;
325 }
326
327 while (ptr->description != NULL)
328 {
329 if(ptr->type == LP_PHONEHOME_VERSION)
330 {
331 // Phone home is turned on, so add
332 // the parameter for the user to turn it off.
333 myNoPhoneHome = false;
334 myVersion = ptr->description;
335 ptr->description = "noPhoneHome";
336 ptr->value = &myNoPhoneHome;
337 ptr->type = LP_BOOL_PARAMETER;
338 legacyIndex.Add(ptr->description, ptr);
339 }
340 else
341 {
342 if (ptr->value != NULL)
343 legacyIndex.Add(ptr->description, ptr);
344 }
345 ptr++;
346 }
347
348 precision = 2;
349}

Member Function Documentation

◆ addParamsToString()

void LongParameters::addParamsToString ( String & params)
virtual

Reimplemented from Parameter.

Definition at line 579 of file Parameters.cpp.

580{
581 for (LongParameterList * ptr = list + 1; ptr->description != NULL; ptr++)
582 {
583 if (ptr->touched)
584 {
585 if(!params.IsEmpty())
586 {
587 params += PARAM_STR_SEP;
588 }
589 params += ptr->description;
590 }
591 }
592}

◆ ExplainAmbiguity()

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

Definition at line 351 of file Parameters.cpp.

352{
353 String value(cstr);
354
355 int p = value.FastFindChar(':');
356 String stem = p == -1 ? value : value.Left(p);
357 String matches;
358
359 for (int i = 0; i < index.Length(); i++)
360 if (index[i].SlowCompareToStem(stem) == 0)
361 {
362 if (matches.Length() + index[i].Length() > 50)
363 {
364 matches += " ...";
365 break;
366 }
367
368 matches.catprintf(" --%s", (const char *) index[i]);
369 }
370
371 warning("Ambiguous --%s matches%s\n",
372 (const char *) value, (const char *) matches);
373}

◆ SetPrecision()

LongParameters * LongParameters::SetPrecision ( int precision)
inline

Definition at line 273 of file Parameters.h.

274 {
275 this->precision = precision;
276
277 return this;
278 }

◆ Status() [1/2]

void LongParameters::Status ( )
virtual

Implements Parameter.

Definition at line 547 of file Parameters.cpp.

548{
549 if (description != NULL && description[0] != 0)
550 fprintf(stderr, "\n%s\n", description);
551
552 bool need_a_comma = false;
553 int line_len = 0;
554
555 bool legacy_parameters = false;
556 int legacy_count = 0;
557
558 for (LongParameterList * ptr = list + 1; ptr->description != NULL; ptr++)
559 if (ptr->type == LP_LEGACY_PARAMETERS)
560 legacy_parameters = true;
561 else if (legacy_parameters == false)
562 Status(ptr, line_len, need_a_comma);
563 else if (ptr->touched)
564 {
565 if (legacy_count == 0)
566 {
567 fprintf(stderr, "\n\nAdditional Options:\n %*s ", group_len + 3, "");
568 line_len = group_len + 5;
569 need_a_comma = false;
570 }
571
572 Status(ptr, line_len, need_a_comma);
573 legacy_count++;
574 }
575
576 fprintf(stderr, "\n");
577}

◆ Status() [2/2]

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

Definition at line 492 of file Parameters.cpp.

493{
494 String state;
495 int line_start = group_len ? group_len + 5 : 0;
496
497 if (ptr->value == NULL)
498 {
499 fprintf(stderr, "%s %*s :", need_a_comma ? "\n" : "", group_len + 2, ptr->description);
500 need_a_comma = false;
501 line_len = line_start;
502 }
503 else
504 {
505 if (ptr->type == LP_BOOL_PARAMETER)
506 state = * (bool *) ptr->value ? " [ON]" : "";
507 else if (ptr->type == LP_INT_PARAMETER)
508 if (((* (int *) ptr->value == 1) && (ptr->exclusive)) || (* (int *) ptr->value == 0))
509 state = * (int *) ptr->value ? " [ON]" : "";
510 else
511 state = " [", state += * (int *) ptr->value, state += ']';
512 else if (ptr->type == LP_DOUBLE_PARAMETER)
513 if (* (double *) ptr->value != _NAN_)
514 {
515 double value = * (double *) ptr->value;
516
517 state = " [";
518 if (value == 0.0 || value >= 0.01)
519 state.catprintf("%.*f", precision, value);
520 else
521 state.catprintf("%.1e", value);
522 state += ']';
523 }
524 else
525 state = "";
526 else if (ptr->type == LP_STRING_PARAMETER)
527 state = " [" + * (String *) ptr->value + "]";
528
529 int item_len = 3 + strlen(ptr->description) + need_a_comma + state.Length();
530
531 if (item_len + line_len > 78 && line_len > line_start)
532 {
533 line_len = line_start;
534 fprintf(stderr, "%s\n%*s", need_a_comma ? "," : "", line_len, "");
535 need_a_comma = 0;
536 item_len -= 1;
537 }
538
539 fprintf(stderr, "%s --%s%s", need_a_comma ? "," : (need_a_comma = true, ""),
540 ptr->description, (const char *) state);
541
542 need_a_comma = true;
543 line_len += item_len;
544 }
545}

◆ Translate()

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

Implements Parameter.

Definition at line 375 of file Parameters.cpp.

376{
377 String value(cstr);
378
379 int p = value.FastFindChar(':');
380 int option = p == -1 ? index.FindStem(value) : index.FindStem(value.Left(p));
381
382 if (option == -2)
383 {
384 ExplainAmbiguity(cstr);
385 return;
386 }
387
388 LongParameterList * ptr;
389
390 if (option >= 0)
391 ptr = (LongParameterList *) index.Object(option);
392 else
393 {
394 int alternate = p == -1 ? legacyIndex.FindFirstStem(value) :
395 legacyIndex.FindFirstStem(value.Left(p));
396
397 if (alternate < 0)
398 {
399 warning("Command line parameter --%s is undefined\n", (const char *) value);
400 return;
401 }
402
403 ptr = (LongParameterList *) legacyIndex.Object(alternate);
404 ptr->touched = true;
405 }
406 ptr->touched = true;
407
408 if (ptr->type == LP_BOOL_PARAMETER)
409 {
410 if (p == -1)
411 * (bool *) ptr->value ^= true;
412 else
413 *(bool *) ptr->value = value.SubStr(p + 1).SlowCompare("ON") == 0;
414
415 // In exclusive groups, only one option may be selected
416 if (ptr->exclusive)
417 {
418 for (int i = -1; ptr[i].exclusive; i--) *(bool *)ptr[i].value = false;
419 for (int i = 1; ptr[i].exclusive; i++) *(bool *)ptr[i].value = false;
420 }
421 }
422 else if (ptr->type == LP_INT_PARAMETER)
423 if (p == -1)
424 * (int *) ptr->value = * (int *) ptr->value ? 0 : 1;
425 else
426 *(int *) ptr->value = value.SubStr(p + 1).SlowCompare("ON") == 0 ?
427 1 : value.SubStr(p + 1).AsInteger();
428 else if (ptr->type == LP_DOUBLE_PARAMETER)
429 {
430 if (p != -1)
431 * (double *) ptr->value = value.SubStr(p + 1).AsDouble();
432 }
433 else if (ptr->type == LP_STRING_PARAMETER)
434 {
435 if (p != -1)
436 * (String *) ptr->value = value.SubStr(p + 1);
437 }
438}

◆ TranslateExtras()

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

Reimplemented from Parameter.

Definition at line 440 of file Parameters.cpp.

441{
442 if (strchr(cstr, ':') != NULL)
443 return false;
444
445 int option = index.FindStem(cstr);
446
447 if (option == -2)
448 {
449 // No need to explain ambiguity here ... will be handle by later call
450 // to Translate()
451 // ExplainAmbiguity(cstr);
452 return false;
453 }
454
455 LongParameterList * ptr;
456
457 if (option >= 0)
458 ptr = (LongParameterList *) index.Object(option);
459 else
460 {
461 option = legacyIndex.FindFirstStem(cstr);
462
463 if (option < 0)
464 return false;
465
466 ptr = (LongParameterList *) legacyIndex.Object(option);
467 ptr->touched = true;
468 }
469
470 if (ptr->type == LP_INT_PARAMETER && CheckInteger(extras))
471 {
472 *(int *) ptr->value = atoi(extras);
473 ptr->touched = true;
474 return true;
475 }
476 else if (ptr->type == LP_DOUBLE_PARAMETER && CheckDouble(extras))
477 {
478 *(double *) ptr->value = atof(extras);
479 ptr->touched = true;
480 return true;
481 }
482 else if (ptr->type == LP_STRING_PARAMETER)
483 {
484 *(String *) ptr->value = extras;
485 ptr->touched = true;
486 return true;
487 }
488
489 return false;
490}

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: