#include <varable.h>
Definition at line 326 of file varable.h.
double_VARIABLE::double_VARIABLE | ( | double | v, | |
const char * | vname, | |||
const char * | comment | |||
) |
Constructor for double_VARIABLE. Add the variable to the static list.
Definition at line 399 of file varable.cpp.
References head, info, name, and set_value().
00403 { 00404 //list iterator 00405 double_VARIABLE_C_IT it = &head; 00406 00407 //tprintf("Constructing %s\n",vname); 00408 set_value(v); //set the value 00409 name = vname; //strings must be static 00410 info = comment; 00411 it.add_before_stay_put (this); //add it to stack 00412 }
double_VARIABLE::double_VARIABLE | ( | ) | [inline] |
double_VARIABLE::~double_VARIABLE | ( | ) |
Destructor.
Definition at line 418 of file varable.cpp.
References head.
00418 { 00419 //list iterator 00420 double_VARIABLE_C_IT it = &head; 00421 00422 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) 00423 if (it.data () == this) 00424 it.extract (); 00425 }
double_VARIABLE_CLIST * double_VARIABLE::get_head | ( | ) | [static] |
Get the head of the list of the variables.
Definition at line 431 of file varable.cpp.
References head.
Referenced by build_list_of_all_leaves().
00431 { //access to static 00432 return &head; 00433 }
const char* double_VARIABLE::info_str | ( | ) | [inline] |
Definition at line 359 of file varable.h.
Referenced by DBL_VAR_MENU_LEAF::write_vars().
00359 { //access name 00360 return info; 00361 }
const char* double_VARIABLE::name_str | ( | ) | [inline] |
Definition at line 355 of file varable.h.
Referenced by DBL_VAR_MENU_LEAF::cmp_str(), and DBL_VAR_MENU_LEAF::write_vars().
00355 { //access name 00356 return name; 00357 }
double_VARIABLE::operator double | ( | ) | [inline] |
void double_VARIABLE::print | ( | FILE * | fp | ) | [static] |
Print the entire list of double_VARIABLEs.
Definition at line 439 of file varable.cpp.
References head, info, name, tprintf(), and value.
Referenced by print_variables().
00441 { 00442 //list iterator 00443 double_VARIABLE_C_IT it = &head; 00444 double_VARIABLE *elt; //current element 00445 00446 if (fp == stdout) { 00447 tprintf ("#Variables of type double_VARIABLE:\n"); 00448 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { 00449 elt = it.data (); 00450 tprintf ("%s %lg #%s\n", elt->name, elt->value, elt->info); 00451 } 00452 } 00453 else { 00454 fprintf (fp, "#Variables of type double_VARIABLE:\n"); 00455 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) { 00456 elt = it.data (); 00457 fprintf (fp, "%s %g #%s\n", elt->name, elt->value, elt->info); 00458 } 00459 } 00460 }
void double_VARIABLE::set_value | ( | double | v | ) | [inline] |
Definition at line 350 of file varable.h.
Referenced by double_VARIABLE().
00351 { //value to set 00352 value = v; 00353 }
friend class double_VAR_FROM [friend] |
friend class double_VAR_TO [friend] |
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 }
double_VAR_FROM double_VARIABLE::copy [static, private] |
double_VARIABLE_CLIST double_VARIABLE::head [static, private] |
Definition at line 375 of file varable.h.
Referenced by double_VAR_TO::double_VAR_TO(), double_VARIABLE(), get_head(), print(), read_variables_file(), and ~double_VARIABLE().
const char* double_VARIABLE::info [private] |
const char* double_VARIABLE::name [private] |
double_VAR_TO double_VARIABLE::replace [static, private] |
double double_VARIABLE::value [private] |