-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvarStorage.h
129 lines (89 loc) · 3.21 KB
/
varStorage.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef VARSTORAGE_H
#define VARSTORAGE_H
extern bool SHOW_DEBUGGING;
#include <map>
#include <vector>
#include <stdint.h>
//################ PROTOTYPES ################//
struct strCmp {
bool operator() (std::string, std::string) const;
};
class InternalDataType {
protected:
void * dataValue; // a void pointer to whatever it is ...
uint32_t validType; // which type is currently valid (best effort)
/*
* value's representation as a string -- 0
* 1 and 2 are arrays and vectors, respectively
* as an int -- 4
* as a double -- 8
* someday ... complex number -- 16
* someday ... ClassWrap -- 32
*/
int references; // how many pointers are pointing to you?
public:
InternalDataType( void *, int );
InternalDataType(const InternalDataType *);
~InternalDataType();
void setData( void *, int ); // update the object
void upRef();
void downRef();
void nullRef();
int getRefs() const;
uint32_t getType() const;
void * getValue() const;
};
class VariableStorage {
protected:
std::map<std::string, InternalDataType *, strCmp> dataNames; // must be a pointer for mult. references
int startVariableReference; // 1000000000 -- hopefully find a better way than this later
int arrayAutoIndex;
// all of these methods will be called in the CORRECT level already (bc of getVector)
void refresh(bool = false);
void garbageCollect();
public:
VariableStorage(int = 0);
VariableStorage(const VariableStorage *);
~VariableStorage();
std::string variableReferencer(std::string);
bool addVector(std::string, const VariableStorage &, int = -1);
bool addVariable(std::string = "", std::string = "", int = -1);
bool removeVariable(const std::string &);
VariableStorage * getVector(const std::string &, bool = true);
VariableStorage * vecStringToVector(std::string *, bool = true, bool = false);
std::string getData(const std::string &, bool = true);
std::map<std::string, InternalDataType *, strCmp> * getVectorNodes();
std::string dumpData() const;
int size() const;
int type(std::string = "") const;
std::string typeString(std::string = "") const;
bool variableExists(std::string) const;
};
class DataStorageStack {
protected:
std::vector<VariableStorage *> dataStack; // data stack
public:
DataStorageStack();
DataStorageStack(VariableStorage *);
DataStorageStack(const DataStorageStack *);
~DataStorageStack();
void clearMemory();
void pop(); // pop and destroy the top of the stack
std::string variableReferencer(std::string);
bool addVector(std::string, const VariableStorage &, int = -1, bool = false);
bool addVariable(std::string = "", std::string = "", int = -1, bool = false);
bool removeVariable(std::string);
VariableStorage * getVector(std::string, bool = true);
VariableStorage * vecStringToVector(std::string *, bool = true, bool = false);
std::string getData(std::string, bool = true);
std::map<std::string, InternalDataType *, strCmp> * getVectorNodes();
std::string dumpData() const;
int size() const;
int type(std::string = "") const;
std::string typeString(std::string = "") const;
bool variableExists(std::string) const;
void pushStorage(VariableStorage * = NULL);
int stackSize() const;
};
/// ################################ ///
#endif