1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
// implement variables using a c++ map of the variable number and a pointer to the variable structure
// this will allow for a dynamically allocated number of variables
// 2010-12-13 j.m.reneau
#pragma once
#include <map>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "ErrorCodes.h"
#include "Stack.h"
#define VARIABLE_MAXARRAYELEMENTS 100000
struct array
{
int xdim;
int ydim;
int size;
union
{
double *fdata;
char **sdata;
} data;
};
struct variable
{
b_type type;
union {
char *string;
double floatval;
array *arr;
} value;
};
class Variables
{
public:
Variables();
~Variables();
//
void clear();
//
int type(int);
int error();
//
void setfloat(int, double);
double getfloat(int);
//
void setstring(int, char *);
char *getstring(int);
//
void arraydimfloat(int, int, int, bool);
void arraydimstring(int, int, int, bool);
//
int arraysize(int);
int arraysizex(int);
int arraysizey(int);
//
void arraysetfloat(int, int, double);
void array2dsetfloat(int, int, int, double);
double arraygetfloat(int, int);
double array2dgetfloat(int, int, int);
//
void arraysetstring(int, int, char *);
void array2dsetstring(int, int, int, char *);
char *arraygetstring(int, int);
char *array2dgetstring(int, int, int);
private:
int lasterror;
std::map<int, variable*> varmap;
void clearvariable(variable*);
variable* getvfromnum(int, bool);
};
|