TorqueScript  0.2
storedvalue.hpp
1 
15 #pragma once
16 
17 #include <iostream>
18 #include <assert.h>
19 #include <memory>
20 #include <string>
21 
22 namespace TorqueScript
23 {
24  class ExecutionScope;
25  class ConsoleObject;
26  class ExecutionState;
27 
28  enum StoredValueType
29  {
30  NullType,
31  Integer,
32  Float,
33  String,
34  LocalReference,
35  GlobalReference,
36  MemoryReference,
37  SubfieldReference
38  };
39 
40  enum MemoryReferenceType
41  {
42  NullReferenceType,
43  FloatMemory,
44  IntegerMemory,
45  StringMemory
46  };
47 
49  {
50  int mInteger;
51  float mFloat;
52  std::size_t mStringID;
53 
55  {
56 
57  }
58 
59  StoredValueUnion(const int value) : mInteger(value)
60  {
61 
62  }
63 
64  StoredValueUnion(const float value) : mFloat(value)
65  {
66 
67  }
68 
69  StoredValueUnion(const std::size_t value) : mStringID(value)
70  {
71 
72  }
73  };
74 
80  {
81  public:
82  StoredValue(void* memoryLocation, const MemoryReferenceType type) : mType(StoredValueType::MemoryReference), mStorage(), mMemoryReferenceType(type), mMemoryLocation(memoryLocation), mConsoleObject(nullptr)
83  {
84 
85  }
86 
87  StoredValue(const int value) : mType(StoredValueType::Integer), mStorage(value), mMemoryReferenceType(MemoryReferenceType::NullReferenceType), mMemoryLocation(nullptr), mConsoleObject(nullptr)
88  {
89 
90  }
91 
92  StoredValue(const float value) : mType(StoredValueType::Float), mStorage(value), mMemoryReferenceType(MemoryReferenceType::NullReferenceType), mMemoryLocation(nullptr), mConsoleObject(nullptr)
93  {
94 
95  }
96 
97  StoredValue(const std::size_t value, const StoredValueType type) : mType(type), mStorage(value), mMemoryReferenceType(MemoryReferenceType::NullReferenceType), mMemoryLocation(nullptr), mConsoleObject(nullptr)
98  {
99 
100  }
101 
102  StoredValue(std::shared_ptr<ConsoleObject> object, const std::size_t field) : mType(StoredValueType::SubfieldReference), mStorage(field), mMemoryReferenceType(MemoryReferenceType::NullReferenceType), mMemoryLocation(nullptr), mConsoleObject(object)
103  {
104 
105  }
106 
112 
113  int toInteger(std::shared_ptr<ExecutionState> state);
114 
120  float toFloat(std::shared_ptr<ExecutionState> state);
121 
127  std::string toString(std::shared_ptr<ExecutionState> state);
128 
129  bool toBoolean(std::shared_ptr<ExecutionState> state);
130 
131  std::shared_ptr<ConsoleObject> toConsoleObject(std::shared_ptr<ExecutionState> state);
132 
134 
135  StoredValue getReferencedValueCopy(std::shared_ptr<ExecutionState> state);
136 
137  bool isInteger(std::shared_ptr<ExecutionState> state);
138 
146  bool setValue(StoredValue newValue, std::shared_ptr<ExecutionState> state);
147 
148  std::string getRepresentation();
149 
150  private:
151  StoredValueType mType;
152  StoredValueUnion mStorage;
153  MemoryReferenceType mMemoryReferenceType;
154 
155  void* mMemoryLocation;
156  std::shared_ptr<ConsoleObject> mConsoleObject;
157  };
158 }
Storage class used to keep variable values in-memory of arbitrary data types. The data types supporte...
Definition: storedvalue.hpp:80
float toFloat(std::shared_ptr< ExecutionState > state)
Converts the value in question to a native floating point type.
bool setValue(StoredValue newValue, std::shared_ptr< ExecutionState > state)
Sets the value of this object. Only has an effect if this object is a reference to a local or global ...
std::string toString(std::shared_ptr< ExecutionState > state)
Converts the value in question to a native sting type.
Definition: ast.hpp:28
Definition: storedvalue.hpp:49