Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

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_consistancy (void)
Bool set (const ConfigList &configlist)
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)


Constructor & Destructor Documentation

ParseOptions::ParseOptions void   ) 
 

Definition at line 194 of file ParseOptions.C.

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

00194                                {
00195    configList = NULL;
00196    array_size = 0;
00197    array_max_size = 20;
00198    data_array = new DataElement*[array_max_size];
00199    DataElement *tmp = new DataElement("main", "main", TRUE,
00200                                       "Error in ParseOptions",
00201                                       (int *) NULL,  0);
00202    tmp->type = DataElement::UNDEF;
00203    add_element(tmp);
00204 }

ParseOptions::~ParseOptions void   ) 
 

Definition at line 207 of file ParseOptions.C.

00207                                 {
00208    for (int i=0; i<array_size; i++) {
00209       delete data_array[i];
00210    }
00211    delete [] data_array;
00212 }


Member Function Documentation

Bool ParseOptions::check_consistancy void   ) 
 

Definition at line 386 of file ParseOptions.C.

References Bool, iERROR(), iout, ParseOptions::DataElement::name, ParseOptions::DataElement::parent, and ParseOptions::DataElement::parent_ptr.

Referenced by SimParameters::initialize_config_data().

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

Bool ParseOptions::defined const char *  name  ) 
 

Definition at line 892 of file ParseOptions.C.

References Bool, and ParseOptions::DataElement::is_defined.

00893 {
00894    if (!name) return FALSE;
00895    DataElement *tmp = internal_find(name);
00896    if (!tmp) return FALSE;
00897    if (tmp->is_defined) {
00898       return TRUE;
00899    }
00900    return FALSE;
00901 }

Bool ParseOptions::exists const char *  name  ) 
 

Definition at line 883 of file ParseOptions.C.

References Bool.

Referenced by set().

00884 {
00885    if (!name) return 0;
00886    if (internal_find(name)) {
00887       return 1;
00888    }
00889    return 0;
00890 }

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

Definition at line 1043 of file ParseOptions.C.

References Bool, StringList::data, get(), and StringList::next.

01044 {
01045    if (!val || n<0) {return FALSE;}
01046    StringList *tmp;
01047    if (!get(name, &tmp)) {val[0]=STRINGNULL; return FALSE; }
01048    int i=n;
01049    while (i>0 && tmp) { // search for the nth element
01050       tmp=tmp->next;
01051       i--;
01052    }
01053    if (tmp) {  // if it was long enough, return it
01054       strcpy(val, tmp->data);
01055       return TRUE;
01056    }
01057    val[0] = STRINGNULL;
01058    return FALSE;
01059 }

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

Definition at line 1028 of file ParseOptions.C.

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

01028                                                          {
01029    if (!val) return FALSE;
01030    DataElement *el = internal_find(name); // first check it is internally valid
01031    if (el == NULL || !el->is_defined) {
01032       return FALSE;
01033    }
01034    // then simply ask the configList itself for the answer
01035    // (while I do keep the information internally, in sldata, why bother?
01036    if (!configList) { return FALSE; }
01037    *val = configList->find(name);
01038    if (!*val) { return FALSE; }  // paranoia, I know...
01039    return TRUE;
01040 }

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

Definition at line 985 of file ParseOptions.C.

References Bool, StringList::data, iERROR(), iout, ParseOptions::DataElement::is_defined, iWARN(), Vector::set(), ParseOptions::DataElement::sldata, ParseOptions::DataElement::type, and ParseOptions::DataElement::vdata.

00985                                                     {
00986    if (!val) return FALSE;
00987    DataElement *el = internal_find(name);
00988    if (el == NULL || !el->is_defined) {
00989       return FALSE;
00990    }
00991    switch (el -> type) {
00992     case DataElement::FLOAT:
00993       iout << iERROR 
00994          << "ParseOptions cannot convert from float to Vector for '"
00995          << name << "'" << "\n" << endi;
00996       return FALSE;
00997     case DataElement::INT:
00998       iout << iERROR 
00999          << "ParseOptions cannot convert from int to Vector for '"
01000          << name << "'" << "\n" << endi;
01001       return FALSE;
01002     case DataElement::STRING:
01003     case DataElement::STRINGLIST:{
01004       iout << iWARN 
01005          << "ParseOptions doing a conversion from StringList[0] to "
01006          << "Vector for '" << name << "'" << "\n" << endi;
01007       Vector v;
01008       if (!v.set(el->sldata->data)) {
01009          iout << iERROR 
01010             << "Could not convert '" << el->sldata->data
01011             << "' to a Vector";
01012          return FALSE;
01013       }
01014       *val = v;
01015       return TRUE;
01016      }
01017      case DataElement::VECTOR : 
01018       *val = el->vdata;
01019       return TRUE;
01020     default:
01021       iout << iERROR 
01022          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
01023          << "\n" << endi;
01024 
01025    }
01026    return FALSE;
01027 }

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

Definition at line 944 of file ParseOptions.C.

References Bool, StringList::data, ParseOptions::DataElement::fdata, ParseOptions::DataElement::idata, iERROR(), iout, ParseOptions::DataElement::is_defined, iWARN(), ParseOptions::DataElement::sldata, and ParseOptions::DataElement::type.

00944                                                      {
00945    if (!val) return FALSE;
00946    DataElement *el = internal_find(name);
00947    if (el == NULL || !el->is_defined) {
00948       return FALSE;
00949    }
00950    switch (el -> type) {
00951     case DataElement::FLOAT: 
00952       *val =  el->fdata;
00953       return TRUE;
00954     case DataElement::INT:
00955       iout << iWARN 
00956          << "ParseOptions doing a conversion from int to float '"
00957          << name << "'" << "\n" << endi;
00958       *val = (BigReal) el->idata;
00959       return TRUE;
00960     case DataElement::BOOL:
00961       iout << iWARN 
00962          << "ParseOptions doing a conversion from boolean to float for '"
00963          << name << "'" << "\n" << endi;
00964       *val = (BigReal) el->idata;
00965       return TRUE;
00966     case DataElement::STRING:
00967     case DataElement::STRINGLIST:
00968      iout << iWARN 
00969         << "ParseOptions doing a conversion from StringList[0] to float "
00970         << "for '" << name << "'" << "\n" << endi;
00971       *val = atof(el->sldata->data);
00972       return TRUE;
00973     case DataElement::VECTOR :
00974        iout << iERROR 
00975           << "ParseOptions cannot convert from Vector to float for '"
00976           << name << "'" << "\n" << endi;
00977        return FALSE;
00978     default:
00979       iout << iERROR 
00980          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
00981          << "\n" << endi;
00982    }
00983    return FALSE;
00984 }

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

Definition at line 907 of file ParseOptions.C.

References Bool, StringList::data, ParseOptions::DataElement::fdata, ParseOptions::DataElement::idata, iERROR(), iout, ParseOptions::DataElement::is_defined, iWARN(), ParseOptions::DataElement::sldata, and ParseOptions::DataElement::type.

Referenced by get(), and num().

00907                                                  {
00908    if (!val) return FALSE;
00909    DataElement *el = internal_find(name);
00910    if (el == NULL || !el->is_defined) {
00911       return FALSE;
00912    }
00913    switch (el->type) {
00914     case DataElement::FLOAT :
00915       iout << iWARN 
00916          << "ParseOptions doing a conversion from float to int for '"
00917          << name << "'" << "\n" << endi;
00918       *val = (int) el->fdata;
00919       return TRUE;
00920     case DataElement::INT:
00921     case DataElement::BOOL:
00922       *val = el->idata;
00923       return TRUE;
00924     case DataElement::STRINGLIST :
00925     case DataElement::STRING :
00926       iout << iWARN 
00927          << "ParseOptions doing a conversion from StringList[0] to int "
00928          << "for '" << name << "'" << "\n" << endi;
00929       *val = atoi(el->sldata->data);
00930       return TRUE;
00931     case DataElement::VECTOR :
00932        iout << iERROR 
00933           << "ParseOptions cannot convert from Vector to int for '"
00934           << name << "'" << "\n" << endi;
00935        return FALSE;
00936     default:
00937       iout << iERROR 
00938          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
00939          << "\n" << endi;
00940    }
00941    return FALSE;
00942 }

int ParseOptions::num const char *  name  ) 
 

Definition at line 1062 of file ParseOptions.C.

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

01063 {
01064    DataElement *el = internal_find(name);
01065    if (!el || !el ->is_defined) {
01066       return 0;
01067    }
01068    if (!el->many_allowed) {
01069       return 1;
01070    }
01071    StringList *tmp;
01072    if (!get(name, &tmp)) { return 0; }
01073    int i=0;
01074    while (tmp) {
01075       i++;
01076       tmp=tmp->next;
01077    }
01078    return i;
01079 }

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

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

01084 {
01085    DataElement *el = internal_find(name);
01086    if (!el) {
01087       iout << iERROR 
01088          << "Trying to set the range of undefined variable '"
01089          << name << "'" << "\n" << endi;
01090       return;
01091    }
01092    el->range = newrange;
01093    
01094 }

Range ParseOptions::range const char *  name  ) 
 

Definition at line 1095 of file ParseOptions.C.

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

01096 {
01097    DataElement *el = internal_find(name);
01098    if (!el) {
01099       iout << iERROR 
01100          << "Trying to get the range of undefined variable '"
01101          << name << "'" << "\n" << endi;
01102       return FREE_RANGE;
01103    }
01104    return el->range;
01105 }

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

References Bool, StringList::data, ParseOptions::DataElement::error_message, exists(), ParseOptions::DataElement::fdata, ParseOptions::DataElement::fdef, ConfigList::find(), ParseOptions::DataElement::has_default, ConfigList::head(), ParseOptions::DataElement::idata, ParseOptions::DataElement::idef, iERROR(), ParseOptions::DataElement::index, iout, ParseOptions::DataElement::is_defined, ParseOptions::DataElement::is_optional, iWARN(), ParseOptions::DataElement::many_allowed, ParseOptions::DataElement::name, StringList::next, ParseOptions::DataElement::parent_ptr, ParseOptions::DataElement::sldata, ParseOptions::DataElement::type, ParseOptions::DataElement::uidata, ParseOptions::DataElement::uidef, ParseOptions::DataElement::vdata, and ParseOptions::DataElement::vdef.

Referenced by SimParameters::initialize_config_data().

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

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

Definition at line 1128 of file ParseOptions.C.

References Bool, iERROR(), iout, and ParseOptions::DataElement::units.

01129 {
01130    DataElement *tmp = internal_find(name);
01131    *units = N_UNIT;
01132    if (!tmp) {
01133       iout << iERROR 
01134          << "'" << name << "' doesn't exist so cannot get its units"
01135          << "\n" << endi;
01136       return FALSE;
01137    }
01138    if (tmp -> type != DataElement::INT && 
01139        tmp -> type != DataElement::FLOAT) {
01140       iout << iERROR 
01141          << "Can only get units for FLOAT and INT variables, and '"
01142          << name << "' isn't one of those" << "\n" << endi;
01143       return FALSE;
01144    }
01145    *units = tmp->units;
01146    return TRUE;
01147 }

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

Definition at line 1108 of file ParseOptions.C.

References Bool, iERROR(), iout, and ustring().

01109 {
01110   DataElement *tmp = internal_find(name);
01111   if (!tmp) {
01112      iout << iERROR 
01113         << name << " not found so units not set" << "\n" << endi;
01114      return FALSE;
01115   }
01116   if ((tmp -> type == DataElement::INT && units != N_UNIT) ||
01117       (tmp -> type != DataElement::INT && 
01118        tmp -> type != DataElement::FLOAT)) {
01119      iout << iERROR 
01120         << "Cannot set units '" << ustring(units) << "' for option '"
01121         << name << "'; wrong data type" << "\n" << endi;
01122      return FALSE;
01123   }
01124   tmp -> units = units;
01125   return TRUE;
01126 }


The documentation for this class was generated from the following files:
Generated on Tue Jul 8 04:07:19 2008 for NAMD by  doxygen 1.3.9.1