ParseOptions Class Reference

#include <ParseOptions.h>

List of all members.

Public Member Functions

 ParseOptions (void)
 ~ParseOptions (void)
int require (const char *newname, const char *parent, const char *msg, BigReal *ptr, BigReal defalt)
int require (const char *newname, const char *parent, const char *msg, BigReal *ptr)
int require (const char *newname, const char *parent, const char *msg, Vector *ptr, Vector defalt)
int require (const char *newname, const char *parent, const char *msg, Vector *ptr)
int require (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int require (const char *newname, const char *parent, const char *msg, int *ptr)
int require (const char *newname, const char *parent, const char *msg, unsigned int *ptr, unsigned int defalt)
int require (const char *newname, const char *parent, const char *msg, unsigned int *ptr)
int requireB (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int requireB (const char *newname, const char *parent, const char *msg, int *ptr)
int require (const char *newname, const char *parent, const char *msg, StringList **ptr=NULL, int many_allowed=FALSE)
int require (const char *newname, const char *parent, const char *msg, char *ptr)
int optional (const char *newname, const char *parent, const char *msg, BigReal *ptr, BigReal defalt)
int optional (const char *newname, const char *parent, const char *msg, BigReal *ptr)
int optional (const char *newname, const char *parent, const char *msg, Vector *ptr, Vector defalt)
int optional (const char *newname, const char *parent, const char *msg, Vector *ptr)
int optional (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int optional (const char *newname, const char *parent, const char *msg, int *ptr)
int optional (const char *newname, const char *parent, const char *msg, unsigned int *ptr, unsigned int defalt)
int optional (const char *newname, const char *parent, const char *msg, unsigned int *ptr)
int optionalB (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int optionalB (const char *newname, const char *parent, const char *msg, int *ptr)
int optional (const char *newname, const char *parent, const char *msg, StringList **ptr=NULL, int many_allowed=FALSE)
int optional (const char *newname, const char *parent, const char *msg, char *ptr)
Range range (const char *name)
void range (const char *name, Range newrange)
Bool check_consistency (void)
Bool set (const ConfigList &configlist)
char * getfromptr (const char *name, char *outbuf)
int istruefromptr (const char *name)
int issetfromptr (const char *name)
Bool get (const char *name, int *val)
Bool get (const char *name, BigReal *val)
Bool get (const char *name, Vector *val)
Bool get (const char *name, StringList **val)
Bool get (const char *name, char *val, int n=0)
int num (const char *name)
Bool defined (const char *name)
Bool exists (const char *name)
Bool units (const char *name, Units units)
Bool units (const char *name, Units *units)

Classes

class  DataElement


Detailed Description

Definition at line 42 of file ParseOptions.h.


Constructor & Destructor Documentation

ParseOptions::ParseOptions ( void   ) 

Definition at line 199 of file ParseOptions.C.

References TRUE, ParseOptions::DataElement::type, and ParseOptions::DataElement::UNDEF.

00199                                {
00200    configList = NULL;
00201    array_size = 0;
00202    array_max_size = 20;
00203    data_array = new DataElement*[array_max_size];
00204    DataElement *tmp = new DataElement("main", "main", TRUE,
00205                                       "Error in ParseOptions",
00206                                       (int *) NULL,  0);
00207    tmp->type = DataElement::UNDEF;
00208    add_element(tmp);
00209 }

ParseOptions::~ParseOptions ( void   ) 

Definition at line 212 of file ParseOptions.C.

00212                                 {
00213    for (int i=0; i<array_size; i++) {
00214       delete data_array[i];
00215    }
00216    delete [] data_array;
00217 }


Member Function Documentation

Bool ParseOptions::check_consistency ( void   ) 

Definition at line 391 of file ParseOptions.C.

References endi(), FALSE, iERROR(), iout, ParseOptions::DataElement::name, ParseOptions::DataElement::parent, and TRUE.

Referenced by SimParameters::initialize_config_data().

00391                                          {
00392    int i;
00393    // check for lack of parent
00394    {
00395       int has_error = FALSE;
00396       for(i=1; i<array_size; i++) {
00397          if (!data_array[i]->parent_ptr) {
00398             // missing a parent
00399             iout << iERROR << "Configuration element '" << data_array[i]->name
00400                     << "' defined, but the parent element" << "\n" << endi;
00401             iout << iERROR << "  '" << data_array[i]->parent << "' is nowhere "
00402                     << "to be found" << "\n" << endi;
00403             has_error = TRUE;
00404          }
00405       }
00406       if (has_error) return 0;
00407    }
00408 
00409    // check for loop constructs in the "main" heirarchy
00410    int *arr = new int[array_size];
00411    for (i=0; i<array_size; i++) {  // initialize it
00412       arr[i] = 0;
00413    }
00414    if (!check_children(0, arr)) {
00415       // a loop was found
00416       iout << iERROR << "Loop found in ParseOptions data" << "\n" << endi;
00417       delete [] arr;
00418       return 0;
00419    }
00420 
00421    // check for elements inaccessible to "main"
00422    {
00423       int has_error = FALSE;
00424       for (i=1; i<array_size; i++) {
00425          if (arr[i] == 0) {
00426             // found an inaccesible element
00427             if (has_error == FALSE) { // first time, so print message
00428                iout << iERROR 
00429                    << "Found data in ParseOptions which are inaccessible "
00430                    << "to" << "\n" << endi;
00431                iout << iERROR 
00432                   << "the main data hierarchy.  Errors in:" << "\n" << endi;
00433                has_error = TRUE;
00434             }
00435             iout << iERROR << "   '" << data_array[i]->name << "' depends on '"
00436                     << data_array[i]->parent << "'" << "\n" << endi;
00437          }
00438       }
00439       if (has_error) {
00440          delete [] arr;
00441          return 0;
00442       }
00443    }
00444    // looks like everything went well
00445    delete [] arr;
00446    return 1;
00447 }

Bool ParseOptions::defined ( const char *  name  ) 

Definition at line 913 of file ParseOptions.C.

References FALSE, ParseOptions::DataElement::is_defined, and TRUE.

00914 {
00915    if (!name) return FALSE;
00916    DataElement *tmp = internal_find(name);
00917    if (!tmp) return FALSE;
00918    if (tmp->is_defined) {
00919       return TRUE;
00920    }
00921    return FALSE;
00922 }

Bool ParseOptions::exists ( const char *  name  ) 

Definition at line 904 of file ParseOptions.C.

00905 {
00906    if (!name) return 0;
00907    if (internal_find(name)) {
00908       return 1;
00909    }
00910    return 0;
00911 }

Bool ParseOptions::get ( const char *  name,
char *  val,
int  n = 0 
)

Definition at line 1134 of file ParseOptions.C.

References StringList::data, FALSE, get(), StringList::next, STRINGNULL, and TRUE.

01135 {
01136    if (!val || n<0) {return FALSE;}
01137    StringList *tmp;
01138    if (!get(name, &tmp)) {val[0]=STRINGNULL; return FALSE; }
01139    int i=n;
01140    while (i>0 && tmp) { // search for the nth element
01141       tmp=tmp->next;
01142       i--;
01143    }
01144    if (tmp) {  // if it was long enough, return it
01145       strcpy(val, tmp->data);
01146       return TRUE;
01147    }
01148    val[0] = STRINGNULL;
01149    return FALSE;
01150 }

Bool ParseOptions::get ( const char *  name,
StringList **  val 
)

Definition at line 1119 of file ParseOptions.C.

References FALSE, ConfigList::find(), ParseOptions::DataElement::is_defined, and TRUE.

01119                                                          {
01120    if (!val) return FALSE;
01121    DataElement *el = internal_find(name); // first check it is internally valid
01122    if (el == NULL || !el->is_defined) {
01123       return FALSE;
01124    }
01125    // then simply ask the configList itself for the answer
01126    // (while I do keep the information internally, in sldata, why bother?
01127    if (!configList) { return FALSE; }
01128    *val = configList->find(name);
01129    if (!*val) { return FALSE; }  // paranoia, I know...
01130    return TRUE;
01131 }

Bool ParseOptions::get ( const char *  name,
Vector val 
)

Definition at line 1076 of file ParseOptions.C.

References StringList::data, endi(), FALSE, ParseOptions::DataElement::FLOAT, iERROR(), ParseOptions::DataElement::INT, iout, ParseOptions::DataElement::is_defined, iWARN(), Vector::set(), ParseOptions::DataElement::sldata, ParseOptions::DataElement::STRING, ParseOptions::DataElement::STRINGLIST, TRUE, ParseOptions::DataElement::type, ParseOptions::DataElement::vdata, and ParseOptions::DataElement::VECTOR.

01076                                                     {
01077    if (!val) return FALSE;
01078    DataElement *el = internal_find(name);
01079    if (el == NULL || !el->is_defined) {
01080       return FALSE;
01081    }
01082    switch (el -> type) {
01083     case DataElement::FLOAT:
01084       iout << iERROR 
01085          << "ParseOptions cannot convert from float to Vector for '"
01086          << name << "'" << "\n" << endi;
01087       return FALSE;
01088     case DataElement::INT:
01089       iout << iERROR 
01090          << "ParseOptions cannot convert from int to Vector for '"
01091          << name << "'" << "\n" << endi;
01092       return FALSE;
01093     case DataElement::STRING:
01094     case DataElement::STRINGLIST:{
01095       iout << iWARN 
01096          << "ParseOptions doing a conversion from StringList[0] to "
01097          << "Vector for '" << name << "'" << "\n" << endi;
01098       Vector v;
01099       if (!v.set(el->sldata->data)) {
01100          iout << iERROR 
01101             << "Could not convert '" << el->sldata->data
01102             << "' to a Vector";
01103          return FALSE;
01104       }
01105       *val = v;
01106       return TRUE;
01107      }
01108      case DataElement::VECTOR : 
01109       *val = el->vdata;
01110       return TRUE;
01111     default:
01112       iout << iERROR 
01113          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
01114          << "\n" << endi;
01115 
01116    }
01117    return FALSE;
01118 }

Bool ParseOptions::get ( const char *  name,
BigReal val 
)

Definition at line 1035 of file ParseOptions.C.

References ParseOptions::DataElement::BOOL, StringList::data, endi(), FALSE, ParseOptions::DataElement::fdata, ParseOptions::DataElement::FLOAT, ParseOptions::DataElement::idata, iERROR(), ParseOptions::DataElement::INT, iout, ParseOptions::DataElement::is_defined, iWARN(), ParseOptions::DataElement::sldata, ParseOptions::DataElement::STRING, ParseOptions::DataElement::STRINGLIST, TRUE, ParseOptions::DataElement::type, and ParseOptions::DataElement::VECTOR.

01035                                                      {
01036    if (!val) return FALSE;
01037    DataElement *el = internal_find(name);
01038    if (el == NULL || !el->is_defined) {
01039       return FALSE;
01040    }
01041    switch (el -> type) {
01042     case DataElement::FLOAT: 
01043       *val =  el->fdata;
01044       return TRUE;
01045     case DataElement::INT:
01046       iout << iWARN 
01047          << "ParseOptions doing a conversion from int to float '"
01048          << name << "'" << "\n" << endi;
01049       *val = (BigReal) el->idata;
01050       return TRUE;
01051     case DataElement::BOOL:
01052       iout << iWARN 
01053          << "ParseOptions doing a conversion from boolean to float for '"
01054          << name << "'" << "\n" << endi;
01055       *val = (BigReal) el->idata;
01056       return TRUE;
01057     case DataElement::STRING:
01058     case DataElement::STRINGLIST:
01059      iout << iWARN 
01060         << "ParseOptions doing a conversion from StringList[0] to float "
01061         << "for '" << name << "'" << "\n" << endi;
01062       *val = atof(el->sldata->data);
01063       return TRUE;
01064     case DataElement::VECTOR :
01065        iout << iERROR 
01066           << "ParseOptions cannot convert from Vector to float for '"
01067           << name << "'" << "\n" << endi;
01068        return FALSE;
01069     default:
01070       iout << iERROR 
01071          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
01072          << "\n" << endi;
01073    }
01074    return FALSE;
01075 }

Bool ParseOptions::get ( const char *  name,
int *  val 
)

Definition at line 998 of file ParseOptions.C.

References ParseOptions::DataElement::BOOL, StringList::data, endi(), FALSE, ParseOptions::DataElement::fdata, ParseOptions::DataElement::FLOAT, ParseOptions::DataElement::idata, iERROR(), ParseOptions::DataElement::INT, iout, ParseOptions::DataElement::is_defined, iWARN(), ParseOptions::DataElement::sldata, ParseOptions::DataElement::STRING, ParseOptions::DataElement::STRINGLIST, TRUE, ParseOptions::DataElement::type, and ParseOptions::DataElement::VECTOR.

Referenced by get(), and num().

00998                                                  {
00999    if (!val) return FALSE;
01000    DataElement *el = internal_find(name);
01001    if (el == NULL || !el->is_defined) {
01002       return FALSE;
01003    }
01004    switch (el->type) {
01005     case DataElement::FLOAT :
01006       iout << iWARN 
01007          << "ParseOptions doing a conversion from float to int for '"
01008          << name << "'" << "\n" << endi;
01009       *val = (int) el->fdata;
01010       return TRUE;
01011     case DataElement::INT:
01012     case DataElement::BOOL:
01013       *val = el->idata;
01014       return TRUE;
01015     case DataElement::STRINGLIST :
01016     case DataElement::STRING :
01017       iout << iWARN 
01018          << "ParseOptions doing a conversion from StringList[0] to int "
01019          << "for '" << name << "'" << "\n" << endi;
01020       *val = atoi(el->sldata->data);
01021       return TRUE;
01022     case DataElement::VECTOR :
01023        iout << iERROR 
01024           << "ParseOptions cannot convert from Vector to int for '"
01025           << name << "'" << "\n" << endi;
01026        return FALSE;
01027     default:
01028       iout << iERROR 
01029          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
01030          << "\n" << endi;
01031    }
01032    return FALSE;
01033 }

char * ParseOptions::getfromptr ( const char *  name,
char *  outbuf 
)

Definition at line 938 of file ParseOptions.C.

References ParseOptions::DataElement::BOOL, StringList::data, endi(), ParseOptions::DataElement::fdata, ParseOptions::DataElement::FLOAT, ParseOptions::DataElement::fptr, ParseOptions::DataElement::idata, iERROR(), ParseOptions::DataElement::INT, iout, ParseOptions::DataElement::iptr, NAMD_bug(), PRINT_DOUBLE, PRINT_VECTOR(), ParseOptions::DataElement::sldata, ParseOptions::DataElement::slptr, ParseOptions::DataElement::sptr, ParseOptions::DataElement::STRING, ParseOptions::DataElement::STRINGLIST, ParseOptions::DataElement::type, ParseOptions::DataElement::vdata, ParseOptions::DataElement::VECTOR, and ParseOptions::DataElement::vptr.

Referenced by SimParameters::getfromparseopts().

00938                                                              {
00939 #ifdef NAMD_TCL
00940    if ( ! name ) NAMD_bug("ParseOptions::getfromptr called with null name");
00941    if ( ! outbuf ) NAMD_bug("ParseOptions::getfromptr called with null outbuf");
00942    DataElement *el = internal_find(name);
00943    if ( el == NULL ) return 0;
00944    switch (el->type) {
00945     case DataElement::FLOAT :
00946       if ( el->fptr ) PRINT_DOUBLE(outbuf, *(el->fptr));
00947       else PRINT_DOUBLE(outbuf, el->fdata);
00948       return outbuf;
00949     case DataElement::INT:
00950     case DataElement::BOOL:
00951       if ( el->iptr ) sprintf(outbuf,"%d", *(el->iptr));
00952       else sprintf(outbuf,"%d", el->idata);
00953       return outbuf;
00954     case DataElement::STRINGLIST :
00955       if ( el->slptr ) return (*(el->slptr))->data;
00956       else if ( el->sldata ) return el->sldata->data;
00957       else return 0;
00958     case DataElement::STRING :
00959       if ( el->sptr ) return el->sptr;
00960       else if ( el->sldata ) return el->sldata->data;
00961       else return 0;
00962     case DataElement::VECTOR :
00963       if ( el->vptr ) PRINT_VECTOR(outbuf, *(el->vptr));
00964       else PRINT_VECTOR(outbuf, el->vdata);
00965       return outbuf;
00966     default:
00967       iout << iERROR 
00968          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
00969          << "\n" << endi;
00970    }
00971 #endif
00972    return 0;
00973 }

int ParseOptions::issetfromptr ( const char *  name  ) 

Definition at line 987 of file ParseOptions.C.

References ParseOptions::DataElement::is_defined, and NAMD_bug().

Referenced by SimParameters::issetinparseopts().

00987                                                {
00988    if ( ! name ) NAMD_bug("ParseOptions::getfromptr called with null name");
00989    DataElement *el = internal_find(name);
00990    if ( el == NULL ) return -1;
00991    return (el->is_defined ? 1 : 0);
00992 }

int ParseOptions::istruefromptr ( const char *  name  ) 

Definition at line 976 of file ParseOptions.C.

References ParseOptions::DataElement::BOOL, ParseOptions::DataElement::idata, ParseOptions::DataElement::iptr, ParseOptions::DataElement::is_defined, NAMD_bug(), and ParseOptions::DataElement::type.

Referenced by SimParameters::istrueinparseopts().

00976                                                 {
00977    if ( ! name ) NAMD_bug("ParseOptions::getfromptr called with null name");
00978    DataElement *el = internal_find(name);
00979    if ( el == NULL ) return -1;
00980    if ( el->type != DataElement::BOOL ) return -2;
00981    if ( el->iptr ) return ((*(el->iptr)) ? 1 : 0);
00982    if ( ! el->is_defined ) return -3;  // ignores defaults
00983    return (el->idata ? 1 : 0);
00984 }

int ParseOptions::num ( const char *  name  ) 

Definition at line 1153 of file ParseOptions.C.

References get(), ParseOptions::DataElement::many_allowed, and StringList::next.

01154 {
01155    DataElement *el = internal_find(name);
01156    if (!el || !el ->is_defined) {
01157       return 0;
01158    }
01159    if (!el->many_allowed) {
01160       return 1;
01161    }
01162    StringList *tmp;
01163    if (!get(name, &tmp)) { return 0; }
01164    int i=0;
01165    while (tmp) {
01166       i++;
01167       tmp=tmp->next;
01168    }
01169    return i;
01170 }

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
char *  ptr 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
StringList **  ptr = NULL,
int  many_allowed = FALSE 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr,
unsigned int  defalt 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr,
Vector  defalt 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr 
)

int ParseOptions::optional ( const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr,
BigReal  defalt 
)

int ParseOptions::optionalB ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr 
)

int ParseOptions::optionalB ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt 
)

void ParseOptions::range ( const char *  name,
Range  newrange 
)

Definition at line 1174 of file ParseOptions.C.

References endi(), iERROR(), iout, and ParseOptions::DataElement::range.

01175 {
01176    DataElement *el = internal_find(name);
01177    if (!el) {
01178       iout << iERROR 
01179          << "Trying to set the range of undefined variable '"
01180          << name << "'" << "\n" << endi;
01181       return;
01182    }
01183    el->range = newrange;
01184    
01185 }

Range ParseOptions::range ( const char *  name  ) 

Definition at line 1186 of file ParseOptions.C.

References endi(), FREE_RANGE, iERROR(), iout, and ParseOptions::DataElement::range.

01187 {
01188    DataElement *el = internal_find(name);
01189    if (!el) {
01190       iout << iERROR 
01191          << "Trying to get the range of undefined variable '"
01192          << name << "'" << "\n" << endi;
01193       return FREE_RANGE;
01194    }
01195    return el->range;
01196 }

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
char *  ptr 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
StringList **  ptr = NULL,
int  many_allowed = FALSE 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr,
unsigned int  defalt 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr,
Vector  defalt 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr 
)

int ParseOptions::require ( const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr,
BigReal  defalt 
)

int ParseOptions::requireB ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr 
)

int ParseOptions::requireB ( const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt 
)

Bool ParseOptions::set ( const ConfigList configlist  ) 

Definition at line 642 of file ParseOptions.C.

References ParseOptions::DataElement::BOOL, StringList::data, endi(), ParseOptions::DataElement::error_message, FALSE, ParseOptions::DataElement::fdata, ParseOptions::DataElement::fdef, ConfigList::find(), ParseOptions::DataElement::FLOAT, ParseOptions::DataElement::has_default, ParseOptions::DataElement::idata, ParseOptions::DataElement::idef, iERROR(), ParseOptions::DataElement::index, ParseOptions::DataElement::INT, iout, ParseOptions::DataElement::is_defined, ParseOptions::DataElement::is_optional, ParseOptions::DataElement::many_allowed, ParseOptions::DataElement::name, StringList::next, ParseOptions::DataElement::parent_ptr, ParseOptions::DataElement::sldata, ParseOptions::DataElement::STRING, ParseOptions::DataElement::STRINGLIST, TRUE, ParseOptions::DataElement::type, ParseOptions::DataElement::uidata, ParseOptions::DataElement::uidef, ParseOptions::DataElement::UINT, ParseOptions::DataElement::vdata, ParseOptions::DataElement::vdef, and ParseOptions::DataElement::VECTOR.

Referenced by SimParameters::initialize_config_data().

00643 {
00644    // the algorithm is easy, though it looks scary
00645    int cont = TRUE, i;  // do some initialization
00646    StringList *slptr;
00647    DataElement *data;
00648    int has_error = FALSE;
00649    int *checked = new int[array_size];
00650    configList = &clist;
00651 
00652    // I make here a list of element I have already checked, starting
00653    // at the head.  I check only children of those that have already
00654    // been defined and add it to the checked list
00655    for (i=0; i<array_size; i++) 
00656    {
00657       checked[i] = FALSE;
00658    }
00659 
00660    //   make "main" 'defined' (at this point, nothing else should be defined)
00661    data_array[0]->is_defined = TRUE;
00662    checked[0] = TRUE;  // and make "main" checked
00663    
00664    // while there is still data which hasn't been defined
00665    while (cont) 
00666    {
00667       cont = FALSE;
00668       for (i=1; i<array_size; i++) 
00669       {  // check each element
00670          data = data_array[i];
00671 
00672          // find unchecked data which has a parent which was checked
00673          // and defined
00674          if (!checked[data->index] &&
00675              checked[data-> parent_ptr -> index] &&
00676              data -> parent_ptr -> is_defined) 
00677          {
00678             cont = TRUE;
00679             checked[data->index] = TRUE;  // so I don't check again
00680 
00681             // check to see if data is available in the StringList
00682             slptr = clist.find(data->name);
00683 
00684             if (slptr != NULL) 
00685             {  // it is 
00686 
00687                // most data types allow only 1 item, so check if that is
00688                // a problem.  (some StringLists, like 'parameters', allow
00689                // multiple strings)
00690                if (!data->many_allowed && slptr->next != NULL) 
00691                {
00692                   iout << iERROR << "Multiple definitions of '" << data->name << "'" << "\n" << endi;
00693                   iout << iERROR << "  in the configuration file are not allowed" << "\n" << endi;
00694                   has_error = TRUE;
00695                }
00696 
00697                data->is_defined = TRUE;
00698 
00699                // set the appropriate data field
00700                if (data->type == DataElement::FLOAT) 
00701                {
00702                   if (!scan_float(data, slptr->data)) 
00703                         has_error = TRUE;
00704                } 
00705                else if (data->type == DataElement::VECTOR) 
00706                {
00707                   if (!scan_vector(data, slptr->data)) 
00708                         has_error = TRUE;
00709                } 
00710                else if (data->type == DataElement::INT) 
00711                {
00712                   if (!scan_int(data, slptr->data)) 
00713                         has_error = TRUE;
00714                } 
00715                else if (data->type == DataElement::UINT) 
00716                {
00717                   if (!scan_uint(data, slptr->data)) 
00718                         has_error = TRUE;
00719                } 
00720                else if (data->type == DataElement::BOOL) 
00721                {
00722                   if (!scan_bool(data, slptr->data)) 
00723                         has_error = TRUE;
00724                } 
00725                else if (data->type == DataElement::STRINGLIST ||
00726                           data->type == DataElement::STRING ) 
00727                {
00728                   data->sldata = slptr;
00729                } 
00730                else 
00731                {
00732                   iout << iERROR << "Unknown ParseOption data type " << (int)(data->type) << " for "
00733                           << "variable " << data->name << "\n" << endi;
00734                   has_error = TRUE;
00735                }
00736             } 
00737             else 
00738             {  // no definition; is there a default?
00739                if (data->has_default) 
00740                {
00741                   data->is_defined = TRUE;
00742 
00743                   if (data->type == DataElement::FLOAT) 
00744                   {
00745                      data->fdata = data->fdef;
00746                   } 
00747                   else if (data->type == DataElement::VECTOR) 
00748                   {
00749                      data->vdata = data->vdef;
00750                   } 
00751                   else if (data->type == DataElement::UINT) 
00752                   {
00753                      data->uidata = data->uidef;
00754                   } 
00755                   else if (data->type == DataElement::INT ||
00756                              data->type == DataElement::BOOL) 
00757                   {
00758                      data->idata = data->idef;
00759                   } 
00760                   else 
00761                   {
00762                         iout << iERROR << "Unknown ParseOption data type " << (int)(data->type) << " for "
00763                                 << "variable " << data->name << "\n" << endi;
00764                     has_error = TRUE;
00765                   }
00766                }
00767             }
00768 
00769             // at this point we should have gotten data from the file or the defaults,
00770             // or it hasn't yet been defined.  If it still isn't defined, check
00771             // to see if it is optional
00772             if (!data->is_defined) 
00773             { // if still not defined,
00774                if (!data->is_optional) 
00775                { // it is it required
00776                   has_error = TRUE;
00777                   iout << iERROR << "'" << data->name << "' is a required configuration option" << "\n" << endi;
00778 
00779                   // print some helpful information if this isn't a "main" option
00780                   if (data->parent_ptr != data_array[0]) 
00781                   {
00782                         iout << iERROR << "  when '" << data->parent_ptr -> name << "' is set" << "\n" << endi;
00783                   }  // printed parent info
00784 
00785                   iout << iERROR << data->name << " defines:   " << data->error_message << "\n" << endi;
00786 
00787                }  // printed error message
00788             }  
00789             else 
00790             { // there was a definition, so assign to the variable
00791                if (data->type ==  DataElement::FLOAT) 
00792                {
00793                   if (!set_float(data)) 
00794                         has_error = TRUE;
00795                } 
00796                else if ( data -> type == DataElement::VECTOR) 
00797                {
00798                   set_vector(data);
00799                } 
00800                else if ( data -> type == DataElement::INT) 
00801                {
00802                   if (!set_int(data)) 
00803                         has_error = TRUE;
00804                } 
00805                else if ( data -> type == DataElement::UINT) 
00806                {
00807                   if (!set_uint(data)) 
00808                         has_error = TRUE;
00809                } 
00810                else if ( data -> type == DataElement::BOOL) 
00811                {
00812                   set_bool(data);
00813 
00814                   if (is_parent_node(data)) 
00815                   {
00816                         // this makes the boolean variable undefined if it is 'off'
00817                         // _and_ it is a parent; this makes it agree with namd's
00818                         // configuration option semantics
00819                         data->is_defined = data->idata;
00820                   }
00821                } 
00822                else if ( data -> type == DataElement::STRINGLIST) 
00823                {
00824                   set_stringlist(data);
00825                } 
00826                else if ( data -> type == DataElement::STRING) 
00827                {
00828                   set_string(data);
00829                } 
00830                else 
00831                {
00832                   // already printed the error message
00833                }
00834             }
00835          }  // end of checking the available variables
00836       } // end of pass through the list
00837    } // end of finding data in the ConfigList
00838 
00839 
00840    // and now print the warning messages
00841 
00842    // first, find elements which are in the configuration file and are
00843    // valid, but which were not needed (ie, the checked array wasn''t set)
00844    {
00845       int flg = 0;
00846 
00847       for (int i=1; i<array_size; i++) 
00848       {
00849          if (!checked[i]) { // wasn't needed
00850             data = data_array[i];
00851             if (clist.find(data->name)) {
00852                if (flg == 0) {
00853                   flg = 1;
00854                   iout << iWARN 
00855                     << "The following variables were set in the\n";
00856                   iout << iWARN 
00857                     << "configuration file but will be ignored:\n" << endi;
00858                }
00859                iout << iWARN << "   " << data->name;
00860                if (data->parent_ptr != data_array[0]) {
00861                  iout << " (" << data->parent_ptr->name << ")";
00862                }
00863                iout << "\n" << endi;
00864             }
00865          }
00866       }
00867    }
00868    // and now look for names which are in the config list but which
00869    // are not in the parseoptions list
00870    {
00871       int flg = 0;
00872       ConfigList::ConfigListNode const *ptr;
00873       for (ptr = clist.head(); ptr != NULL; ptr = ptr -> next) {
00874          if (!exists(ptr -> name)) {
00875             if (flg == 0) {
00876                flg = 1;
00877                has_error = TRUE;
00878                iout << iERROR
00879                   << "The following variables were set in the\n";
00880                iout << iERROR
00881                   << "configuration file but are NOT VALID\n" << endi;
00882             }
00883             iout << iERROR << "   " << ptr -> name << "\n" << endi;
00884          }
00885       }
00886    }
00887       
00888    delete [] checked;
00889    return !has_error;
00890 }

Bool ParseOptions::units ( const char *  name,
Units units 
)

Definition at line 1219 of file ParseOptions.C.

References endi(), FALSE, ParseOptions::DataElement::FLOAT, iERROR(), ParseOptions::DataElement::INT, iout, N_UNIT, TRUE, and ParseOptions::DataElement::units.

01220 {
01221    DataElement *tmp = internal_find(name);
01222    *units = N_UNIT;
01223    if (!tmp) {
01224       iout << iERROR 
01225          << "'" << name << "' doesn't exist so cannot get its units"
01226          << "\n" << endi;
01227       return FALSE;
01228    }
01229    if (tmp -> type != DataElement::INT && 
01230        tmp -> type != DataElement::FLOAT) {
01231       iout << iERROR 
01232          << "Can only get units for FLOAT and INT variables, and '"
01233          << name << "' isn't one of those" << "\n" << endi;
01234       return FALSE;
01235    }
01236    *units = tmp->units;
01237    return TRUE;
01238 }

Bool ParseOptions::units ( const char *  name,
Units  units 
)

Definition at line 1199 of file ParseOptions.C.

References endi(), FALSE, ParseOptions::DataElement::FLOAT, iERROR(), ParseOptions::DataElement::INT, iout, N_UNIT, TRUE, and ustring().

01200 {
01201   DataElement *tmp = internal_find(name);
01202   if (!tmp) {
01203      iout << iERROR 
01204         << name << " not found so units not set" << "\n" << endi;
01205      return FALSE;
01206   }
01207   if ((tmp -> type == DataElement::INT && units != N_UNIT) ||
01208       (tmp -> type != DataElement::INT && 
01209        tmp -> type != DataElement::FLOAT)) {
01210      iout << iERROR 
01211         << "Cannot set units '" << ustring(units) << "' for option '"
01212         << name << "'; wrong data type" << "\n" << endi;
01213      return FALSE;
01214   }
01215   tmp -> units = units;
01216   return TRUE;
01217 }


The documentation for this class was generated from the following files:
Generated on Mon Jun 18 01:17:20 2018 for NAMD by  doxygen 1.4.7