BOOL_VARIABLE Class Reference

#include <varable.h>

List of all members.


Detailed Description

Dealing with boolean variables.

Definition at line 152 of file varable.h.

Public Member Functions

Static Public Member Functions

Private Attributes

Static Private Attributes

Friends


Constructor & Destructor Documentation

BOOL_VARIABLE::BOOL_VARIABLE ( BOOL8  v,
const char *  vname,
const char *  comment 
)

Constructor for BOOL_VARIABLE.

Add the variable to the static list.

Definition at line 194 of file varable.cpp.

References head, info, name, and set_value().

00198                               {
00199   BOOL_VARIABLE_C_IT it = &head; //list iterator
00200 
00201   //tprintf("Constructing %s\n",vname);
00202   set_value(v);  //set the value
00203   name = vname;                  //strings must be static
00204   info = comment;
00205   it.add_before_stay_put (this); //add it to stack
00206 
00207 }

BOOL_VARIABLE::BOOL_VARIABLE (  )  [inline]

Definition at line 165 of file varable.h.

References FALSE.

00165                     {  //for elist only
00166       value = FALSE;
00167       name = "NONAME";
00168       info = "Uninitialized";
00169     }

BOOL_VARIABLE::~BOOL_VARIABLE (  ) 

Constructor for BOOL_VARIABLE. Add the variable to the static list.

Definition at line 213 of file varable.cpp.

References head.

00213                                {
00214   BOOL_VARIABLE_C_IT it = &head; //list iterator
00215 
00216   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00217     if (it.data () == this)
00218       it.extract ();
00219 }


Member Function Documentation

BOOL_VARIABLE_CLIST * BOOL_VARIABLE::get_head (  )  [static]

Get the head of the list of the variables.

Definition at line 225 of file varable.cpp.

References head.

Referenced by build_list_of_all_leaves().

00225                                              {  //access to static
00226   return &head;
00227 }

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

Definition at line 185 of file varable.h.

Referenced by BOOL_VAR_MENU_LEAF::write_vars().

00185                            {  //access name
00186       return info;
00187     }

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

Definition at line 181 of file varable.h.

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

00181                            {  //access name
00182       return name;
00183     }

BOOL_VARIABLE::operator BOOL8 (  )  [inline]

Definition at line 172 of file varable.h.

00172                      {  //conversion
00173       return value;              //access as int
00174     }

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

Print the entire list of BOOL_VARIABLEs.

Definition at line 233 of file varable.cpp.

References head, info, name, tprintf(), and value.

Referenced by print_variables().

00235                            {
00236   BOOL_VARIABLE_C_IT it = &head; //list iterator
00237   BOOL_VARIABLE *elt;            //current element
00238 
00239   if (fp == stdout) {
00240     tprintf ("#Variables of type BOOL_VARIABLE:\n");
00241     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00242       elt = it.data ();
00243       tprintf ("%s %c #%s\n",
00244         elt->name, elt->value ? 'T' : 'F', elt->info);
00245     }
00246   }
00247   else {
00248     fprintf (fp, "#Variables of type BOOL_VARIABLE:\n");
00249     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00250       elt = it.data ();
00251       fprintf (fp, "%s %c #%s\n",
00252         elt->name, elt->value ? 'T' : 'F', elt->info);
00253     }
00254   }
00255 }

void BOOL_VARIABLE::set_value ( BOOL8  v  )  [inline]

Definition at line 176 of file varable.h.

Referenced by BOOL_VARIABLE(), and BOOL_VAR_MENU_LEAF::event().

00177                             {  //value to set
00178       value = v;
00179     }


Friends And Related Function Documentation

friend class BOOL_VAR_FROM [friend]

Definition at line 154 of file varable.h.

friend class BOOL_VAR_TO [friend]

Definition at line 155 of file varable.h.

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 }


Member Data Documentation

BOOL_VAR_FROM BOOL_VARIABLE::copy [static, private]

Definition at line 199 of file varable.h.

Referenced by BOOL_VAR_TO::BOOL_VAR_TO().

BOOL_VARIABLE_CLIST BOOL_VARIABLE::head [static, private]

Definition at line 201 of file varable.h.

Referenced by BOOL_VAR_TO::BOOL_VAR_TO(), BOOL_VARIABLE(), get_head(), print(), read_variables_file(), and ~BOOL_VARIABLE().

const char* BOOL_VARIABLE::info [private]

Definition at line 198 of file varable.h.

Referenced by BOOL_VARIABLE(), and print().

const char* BOOL_VARIABLE::name [private]

Definition at line 197 of file varable.h.

Referenced by BOOL_VARIABLE(), and print().

BOOL_VAR_TO BOOL_VARIABLE::replace [static, private]

Definition at line 202 of file varable.h.

BOOL8 BOOL_VARIABLE::value [private]

Definition at line 196 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:30 2007 for Tesseract by  doxygen 1.5.1