INT_VARIABLE Class Reference

#include <varable.h>

List of all members.


Detailed Description

Dealing with integer variables.

Definition at line 67 of file varable.h.

Public Member Functions

Static Public Member Functions

Private Attributes

Static Private Attributes

Friends


Constructor & Destructor Documentation

INT_VARIABLE::INT_VARIABLE ( INT32  v,
const char *  vname,
const char *  comment 
)

Constructor for INT_VARIABLE.

Add the variable to the static list.

Definition at line 97 of file varable.cpp.

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

00101                             {
00102   INT_VARIABLE_C_IT it = &head;  //list iterator
00103 
00104   //tprintf("Constructing %s\n",vname);
00105   set_value(v);  //set the value
00106   name = vname;                  //strings must be static
00107   info = comment;
00108   it.add_before_stay_put (this); //add it to stack
00109 }

INT_VARIABLE::INT_VARIABLE (  )  [inline]

Definition at line 80 of file varable.h.

00080                    {  //for elist only
00081       value = 0;
00082       name = "NONAME";
00083       info = "Uninitialized";
00084     }

INT_VARIABLE::~INT_VARIABLE (  ) 

Definition at line 112 of file varable.cpp.

References head.

00113   {
00114   INT_VARIABLE_C_IT it = &head;  //list iterator
00115 
00116   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00117     if (it.data () == this)
00118       it.extract ();
00119 }


Member Function Documentation

INT_VARIABLE_CLIST * INT_VARIABLE::get_head (  )  [static]

Get the head of the list of the variables.

Definition at line 125 of file varable.cpp.

References head.

Referenced by build_list_of_all_leaves().

00125                                            {  //access to static
00126   return &head;
00127 }

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

Definition at line 100 of file varable.h.

Referenced by INT_VAR_MENU_LEAF::write_vars().

00100                            {  //access name
00101       return info;
00102     }

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

Definition at line 96 of file varable.h.

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

00096                            {  //access name
00097       return name;
00098     }

INT_VARIABLE::operator INT32 (  )  [inline]

Definition at line 87 of file varable.h.

00087                      {  //conversion
00088       return value;              //access as int
00089     }

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

Print the entire list of INT_VARIABLEs.

Definition at line 133 of file varable.cpp.

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

Referenced by print_variables().

00135                           {
00136   INT_VARIABLE_C_IT it = &head;  //list iterator
00137   INT_VARIABLE *elt;             //current element
00138 
00139   if (fp == stdout) {
00140     tprintf ("#Variables of type INT_VARIABLE:\n");
00141     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00142       elt = it.data ();
00143       tprintf ("%s %d #%s\n", elt->name, elt->value, elt->info);
00144     }
00145   }
00146   else {
00147     fprintf (fp, "#Variables of type INT_VARIABLE:\n");
00148     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00149       elt = it.data ();
00150       fprintf (fp, "%s " INT32FORMAT " #%s\n", elt->name, elt->value,
00151         elt->info);
00152     }
00153   }
00154 }

void INT_VARIABLE::set_value ( INT32  v  )  [inline]

Definition at line 91 of file varable.h.

Referenced by INT_VARIABLE().

00092                             {  //value to set
00093       value = v;
00094     }


Friends And Related Function Documentation

friend class INT_VAR_FROM [friend]

Definition at line 70 of file varable.h.

friend class INT_VAR_TO [friend]

Definition at line 69 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

INT_VAR_FROM INT_VARIABLE::copy [static, private]

Definition at line 114 of file varable.h.

Referenced by INT_VAR_TO::INT_VAR_TO().

INT_VARIABLE_CLIST INT_VARIABLE::head [static, private]

Definition at line 116 of file varable.h.

Referenced by get_head(), INT_VAR_TO::INT_VAR_TO(), INT_VARIABLE(), print(), read_variables_file(), and ~INT_VARIABLE().

const char* INT_VARIABLE::info [private]

Definition at line 113 of file varable.h.

Referenced by INT_VARIABLE(), and print().

const char* INT_VARIABLE::name [private]

Definition at line 112 of file varable.h.

Referenced by INT_VARIABLE(), and print().

INT_VAR_TO INT_VARIABLE::replace [static, private]

Definition at line 117 of file varable.h.

INT32 INT_VARIABLE::value [private]

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