STRING_VARIABLE Class Reference

#include <varable.h>

List of all members.


Detailed Description

Dealing with string variables.

Definition at line 237 of file varable.h.

Public Member Functions

Static Public Member Functions

Private Attributes

Static Private Attributes

Friends


Constructor & Destructor Documentation

STRING_VARIABLE::STRING_VARIABLE ( const char *  v,
const char *  vname,
const char *  comment 
)

Constructor for STRING_VARIABLE.

Add the variable to the static list.

Definition at line 295 of file varable.cpp.

References head, info, and name.

00300  :
00301 value(v) { 
00302                                  //list iterator
00303   STRING_VARIABLE_C_IT it = &head;
00304 
00305   //tprintf("Constructing %s\n",vname);
00306   name = vname;                  //strings must be static
00307   info = comment;
00308   it.add_before_stay_put (this); //add it to stack
00309 }

STRING_VARIABLE::STRING_VARIABLE (  )  [inline]

Definition at line 250 of file varable.h.

00250                       {  //for elist only
00251       name = "NONAME";
00252       info = "Uninitialized";
00253     }

STRING_VARIABLE::~STRING_VARIABLE (  ) 

Destructor for STRING_VARIABLE.

Add the variable to the static list.

Definition at line 317 of file varable.cpp.

References head.

00318   {
00319                                  //list iterator
00320   STRING_VARIABLE_C_IT it = &head;
00321 
00322   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00323     if (it.data () == this)
00324       it.extract ();
00325 }


Member Function Documentation

STRING_VARIABLE_CLIST * STRING_VARIABLE::get_head (  )  [static]

Get the head of the list of the variables.

Definition at line 331 of file varable.cpp.

References head.

Referenced by build_list_of_all_leaves().

00331                                                  {  //access to static
00332   return &head;
00333 }

const char* STRING_VARIABLE::info_str (  )  [inline]

Definition at line 274 of file varable.h.

Referenced by STR_VAR_MENU_LEAF::event(), and STR_VAR_MENU_LEAF::write_vars().

00274                            {  //access name
00275       return info;
00276     }

const char* STRING_VARIABLE::name_str (  )  [inline]

Definition at line 270 of file varable.h.

Referenced by STR_VAR_MENU_LEAF::cmp_str(), and STR_VAR_MENU_LEAF::write_vars().

00270                            {  //access name
00271       return name;
00272     }

STRING_VARIABLE::operator const STRING & (  )  [inline]

Definition at line 257 of file varable.h.

00257                               { 
00258       return value;              //access as int
00259     }

void STRING_VARIABLE::print ( FILE *  fp  )  [static]

Print the entire list of STRING_VARIABLEs.

Definition at line 339 of file varable.cpp.

References head, info, name, STRING::string(), tprintf(), and value.

Referenced by print_variables().

00341                              {
00342                                  //list iterator
00343   STRING_VARIABLE_C_IT it = &head;
00344   STRING_VARIABLE *elt;          //current element
00345 
00346   if (fp == stdout) {
00347     tprintf ("#Variables of type STRING_VARIABLE:\n");
00348     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00349       elt = it.data ();
00350       tprintf ("%s #%s %s\n", elt->name, elt->value.string (), elt->info);
00351     }
00352   }
00353   else {
00354     fprintf (fp, "#Variables of type STRING_VARIABLE:\n");
00355     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00356       elt = it.data ();
00357       fprintf (fp, "%s #%s %s\n",
00358         elt->name, elt->value.string (), elt->info);
00359     }
00360   }
00361 }

void STRING_VARIABLE::set_value ( STRING  v  )  [inline]

Definition at line 261 of file varable.h.

Referenced by STR_VAR_MENU_LEAF::event().

00262                              {  //value to set
00263       value = v;
00264     }

const char* STRING_VARIABLE::string (  )  const [inline]

Definition at line 266 of file varable.h.

References STRING::string().

00266                                {  //get string
00267       return value.string ();
00268     }


Friends And Related Function Documentation

DLLSYM BOOL8 read_variables_file ( const char *  file  )  [friend]

Read a file of variables definitions and set/modify the values therein.

If the filename begins with a + or -, the BOOL_VARIABLEs will be ORed or ANDed with any current values. Blank lines and lines beginning # are ignored. Values may have any whitespace after the name and are the rest of line.

Definition at line 471 of file varable.cpp.

00473                                   {
00474   BOOL8 anyerr;                  //true if any error
00475   char flag;                     //file flag
00476   BOOL8 foundit;                 //found variable
00477   INT16 length;                  //length of line
00478   INT16 nameoffset;              //offset for real name
00479   char *valptr;                  //value field
00480   char *stringend;               //end of string value
00481   FILE *fp;                      //file pointer
00482   INT32 intval;                  //value from file
00483   double doubleval;              //value form file
00484                                  //iterators
00485   INT_VARIABLE_C_IT int_it = &INT_VARIABLE::head;
00486   BOOL_VARIABLE_C_IT BOOL_it = &BOOL_VARIABLE::head;
00487   STRING_VARIABLE_C_IT STRING_it = &STRING_VARIABLE::head;
00488   double_VARIABLE_C_IT double_it = &double_VARIABLE::head;
00489   char line[MAX_PATH];           //input line
00490 
00491   anyerr = FALSE;
00492   if (*file == PLUS) {
00493     flag = PLUS;                 //file has flag
00494     nameoffset = 1;
00495   }
00496   else if (*file == MINUS) {
00497     flag = MINUS;
00498     nameoffset = 1;
00499   }
00500   else {
00501     flag = EQUAL;
00502     nameoffset = 0;
00503   }
00504 
00505   fp = fopen (file + nameoffset, "r");
00506   if (fp == NULL) {
00507     tprintf ("read_variables_file:Can't open %s", file + nameoffset);
00508     return TRUE;                 //can't open it
00509   }
00510   while (fgets (line, MAX_PATH, fp)) {
00511     if (line[0] != '\n' && line[0] != '#') {
00512       length = strlen (line);
00513       if (line[length - 1] == '\n')
00514         line[length - 1] = '\0'; //cut newline
00515       for (valptr = line; *valptr && *valptr != ' ' && *valptr != '\t';
00516         valptr++);
00517       if (*valptr) {             //found blank
00518         *valptr = '\0';          //make name a string
00519         do
00520 
00521         valptr++;              //find end of blanks
00522         while (*valptr == ' ' || *valptr == '\t');
00523 
00524         if (*valptr && *valptr != '#') {
00525                                  //last char in string
00526           stringend = valptr + strlen (valptr) - 1;
00527           while (stringend != valptr) {
00528             while (stringend != valptr
00529               && (*stringend == ' ' || *stringend == '\t'))
00530               //cut trailing blanks
00531               stringend--;
00532             stringend[1] = '\0'; //terminate string
00533 
00534             while (stringend != valptr
00535               && (*stringend != ' ' && *stringend != '\t'
00536               || stringend[1] != '#'))
00537               stringend--;       //find word start
00538           }
00539         }
00540       }
00541       foundit = FALSE;
00542 
00543                                  //find name
00544       for (STRING_it.mark_cycle_pt (); !STRING_it.cycled_list () && strcmp (line, STRING_it.data ()->name); STRING_it.forward ());
00545                                  //found it
00546       if (!STRING_it.cycled_list ()) {
00547         foundit = TRUE;          //found the varaible
00548         if (*valptr == '\0' || *valptr == '#')
00549           STRING_it.data ()->set_value ((char *) NULL);
00550         //no value
00551         else
00552                                  //set its value
00553           STRING_it.data ()->set_value (valptr);
00554       }
00555 
00556       if (*valptr) {
00557                                  //find name
00558         for (int_it.mark_cycle_pt (); !int_it.cycled_list () && strcmp (line, int_it.data ()->name); int_it.forward ());
00559                                  //found it
00560         if (!int_it.cycled_list ()
00561         && sscanf (valptr, INT32FORMAT, &intval) == 1) {
00562           foundit = TRUE;        //found the varaible
00563                                  //set its value
00564           int_it.data ()->set_value (intval);
00565         }
00566 
00567                                  //find name
00568         for (BOOL_it.mark_cycle_pt (); !BOOL_it.cycled_list () && strcmp (line, BOOL_it.data ()->name); BOOL_it.forward ());
00569                                  //found it
00570         if (!BOOL_it.cycled_list ()) {
00571           if (*valptr == 'T' || *valptr == 't'
00572           || *valptr == 'Y' || *valptr == 'y' || *valptr == '1') {
00573             foundit = TRUE;
00574             if (flag == MINUS)
00575               BOOL_it.data ()->set_value (FALSE);
00576             //set to false
00577             else
00578               BOOL_it.data ()->set_value (TRUE);
00579             //set to true
00580           }
00581           else if (*valptr == 'F' || *valptr == 'f'
00582             || *valptr == 'N' || *valptr == 'n'
00583           || *valptr == '0') {
00584             foundit = TRUE;
00585             if (flag == EQUAL)
00586               BOOL_it.data ()->set_value (FALSE);
00587             //set to false
00588           }
00589         }
00590 
00591                                  //find name
00592         for (double_it.mark_cycle_pt (); !double_it.cycled_list () && strcmp (line, double_it.data ()->name); double_it.forward ());
00593                                  //found it
00594         
00595         #ifdef EMBEDDED
00596         if (!double_it.cycled_list ()) {
00597           doubleval = strtofloat(valptr);
00598         #else
00599         if (!double_it.cycled_list ()
00600         && sscanf (valptr, "%lf", &doubleval) == 1) {
00601         #endif
00602           foundit = TRUE;        //found the varaible
00603           double_it.data ()->set_value (doubleval);
00604           //set its value
00605         }
00606 
00607         if (!foundit) {
00608           anyerr = TRUE;         //had an error
00609           tprintf ("read_variables_file:variable not found: %s",
00610             line);
00611         }
00612       }
00613       else if (!foundit) {
00614         anyerr = TRUE;           //had an error
00615         tprintf ("read_variables_file:No value for variable %s", line);
00616       }
00617     }
00618   }
00619   fclose(fp);  //close file
00620   return anyerr;
00621 }

friend class STRING_VAR_FROM [friend]

Definition at line 240 of file varable.h.

friend class STRING_VAR_TO [friend]

Definition at line 239 of file varable.h.


Member Data Documentation

STRING_VAR_FROM STRING_VARIABLE::copy [static, private]

Definition at line 288 of file varable.h.

Referenced by STRING_VAR_TO::STRING_VAR_TO().

STRING_VARIABLE_CLIST STRING_VARIABLE::head [static, private]

Definition at line 290 of file varable.h.

Referenced by get_head(), print(), read_variables_file(), STRING_VAR_TO::STRING_VAR_TO(), STRING_VARIABLE(), and ~STRING_VARIABLE().

const char* STRING_VARIABLE::info [private]

Definition at line 287 of file varable.h.

Referenced by print(), and STRING_VARIABLE().

const char* STRING_VARIABLE::name [private]

Definition at line 286 of file varable.h.

Referenced by print(), and STRING_VARIABLE().

STRING_VAR_TO STRING_VARIABLE::replace [static, private]

Definition at line 291 of file varable.h.

STRING STRING_VARIABLE::value [private]

Definition at line 285 of file varable.h.

Referenced by print().


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 19:49:34 2007 for Tesseract by  doxygen 1.5.1