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 200 of file ParseOptions.C.

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

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

ParseOptions::~ParseOptions ( void   ) 

Definition at line 213 of file ParseOptions.C.

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


Member Function Documentation

Bool ParseOptions::check_consistency ( void   ) 

Definition at line 392 of file ParseOptions.C.

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

Referenced by SimParameters::initialize_config_data().

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

Bool ParseOptions::defined ( const char *  name  ) 

Definition at line 914 of file ParseOptions.C.

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

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

Bool ParseOptions::exists ( const char *  name  ) 

Definition at line 905 of file ParseOptions.C.

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

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

Definition at line 1135 of file ParseOptions.C.

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

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

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

Definition at line 1120 of file ParseOptions.C.

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

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

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

Definition at line 1077 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.

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

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

Definition at line 1036 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.

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

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

Definition at line 999 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().

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

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

Definition at line 939 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().

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

int ParseOptions::issetfromptr ( const char *  name  ) 

Definition at line 988 of file ParseOptions.C.

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

Referenced by SimParameters::issetinparseopts().

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

int ParseOptions::istruefromptr ( const char *  name  ) 

Definition at line 977 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().

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

int ParseOptions::num ( const char *  name  ) 

Definition at line 1154 of file ParseOptions.C.

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

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

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 1175 of file ParseOptions.C.

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

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

Range ParseOptions::range ( const char *  name  ) 

Definition at line 1187 of file ParseOptions.C.

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

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

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 643 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().

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

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

Definition at line 1220 of file ParseOptions.C.

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

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

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

Definition at line 1200 of file ParseOptions.C.

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

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


The documentation for this class was generated from the following files:
Generated on Mon Sep 25 01:17:19 2017 for NAMD by  doxygen 1.4.7