65 lines
1.5 KiB
C++
Executable File

// $Id: value.h,v 1.1.1.1 1994-08-12 10:52:08 alex Exp $
// language types for Simulation and SimulationManager
// -------------------------------------------------------------------------
#ifndef __VALUE_H
#define __VALUE_H
#ifndef _string_h
#include <string.h>
#endif
#ifndef _iostream_h
#include <iostream.h>
#endif
enum basetype
{
UNDEFINED, VOID, INT, LONG, CHAR, DOUBLE, STRING
};
class Value
{
basetype _type;
char _buf[20];
union {
char c;
int i;
long l;
double d;
} v;
char* _s;
public:
Value() { _buf[0] = '\0'; _type = VOID; }
Value(long l) { sprintf(_buf,"%ld",l); _type = LONG; }
Value(char* s) { _s = s; _type = STRING; }
Value(int i) { sprintf(_buf,"%d",i); _type = INT; }
Value(char c) { sprintf(_buf,"%c",c); _type = CHAR; }
Value(double d) { sprintf(_buf,"%lf",d); _type = DOUBLE; }
Value(Value& vl){ strcpy(_buf,vl._buf); v = vl.v; _s = vl._s;
_type = vl._type; }
enum basetype type() { return _type; }
operator int() { sscanf(_type == STRING ? _s : _buf,"%d",&(v.i));
return v.i; }
operator double() { sscanf(_type == STRING ? _s : _buf,"%lf",&(v.d));
return v.d; }
operator char*() { return _type == STRING ? _s : _buf; }
operator long() { sscanf(_type == STRING ? _s : _buf,"%ld",&(v.l));
return v.l; }
operator char() { sscanf(_type == STRING ? _s : _buf,"%c",&(v.c));
return v.c; }
Value& operator=(const Value& val);
};
#endif
// EOF langtypes.H