tclvar

Tcl variables can be accessed by means of the tclvar class. For example, if the programmer declares:

tclvar hello("hello"); float floatvar;

then the variable hello can be used just like a normal C variable in expression such as

floatvar=hello*3.4;.

The class allows assignment to and from double and char* variables, incrementing and decrementing the variables, compound assignment and accessing array Tcl variables by means of the C array syntax. The is also a function that tests for the existence of a Tcl variable.

The complete class definition is given by:

class tclvar
{ 
 public:

/* constructors */
  tclvar();
  tclvar(char *nm, char* val=NULL);
  tclvar(tclvar&);
  ~tclvar();

/* These four statements allow tclvars to be freely mixed with arithmetic 
 expressions */
  double operator=(double x);
  char* operator=(char* x);
  operator double ();
  operator char* ();

  double operator++();
  double operator++(int);
  double operator--();
  double operator--(int); 
  double operator+=(double x);
  double operator-=(double x);
  double operator*=(double x);
  double operator/=(double x);

  tclvar operator=(tclvar x); 
/* arrays can be indexed either by integers, or by strings */
  tclvar operator[](int index);
  tclvar operator[](char* index);

  friend int exists(tclvar x);
};