95 lines
2.1 KiB
C++
95 lines
2.1 KiB
C++
#ifndef DOMAIN_VALUE_H
|
|
#define DOMAIN_VALUE_H
|
|
|
|
#include "addressspace.h"
|
|
|
|
#include <string>
|
|
#include <optional>
|
|
|
|
|
|
namespace domain {
|
|
|
|
class Value
|
|
{
|
|
public:
|
|
enum ValueType {
|
|
INT,
|
|
STRING,
|
|
BOOL,
|
|
ADDRESS_SPACE,
|
|
ADDRESS_SPACE_REFERENCE,
|
|
ATTRIBUTE_REFERENCE,
|
|
WIRE_REFERENCE,
|
|
NIL,
|
|
UNDEFINED,
|
|
};
|
|
|
|
private:
|
|
long long intValue;
|
|
std::string stringValue;
|
|
bool boolValue;
|
|
std::optional<AddressSpace> addressSpace;
|
|
std::string reference;
|
|
|
|
ValueType type;
|
|
|
|
public:
|
|
|
|
Value() {
|
|
this->type = UNDEFINED;
|
|
}
|
|
|
|
bool equals(Value value) {
|
|
if(value.getType() == type) {
|
|
switch (type) {
|
|
case INT:
|
|
return value.asInt() == intValue;
|
|
case STRING:
|
|
return value.asString() == stringValue;
|
|
case NIL:
|
|
case UNDEFINED:
|
|
return true;
|
|
case WIRE_REFERENCE:
|
|
case ATTRIBUTE_REFERENCE:
|
|
case ADDRESS_SPACE_REFERENCE:
|
|
return value.asReference() == reference;
|
|
case BOOL:
|
|
return value.asBool() == boolValue;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::string string();
|
|
|
|
ValueType getType();
|
|
bool isType(ValueType type);
|
|
|
|
long long asInt();
|
|
std::string asString();
|
|
bool asBool();
|
|
std::string asReference();
|
|
AddressSpace asAddressSpace();
|
|
|
|
void setInt(long long intValue);
|
|
void setString(std::string value);
|
|
void setBool(bool value);
|
|
void setReference(std::string value);
|
|
|
|
std::string stringify();
|
|
|
|
static Value fromInt(long long value);
|
|
static Value fromString(std::string value);
|
|
static Value fromBool(bool value);
|
|
static Value fromNull();
|
|
static Value fromAddressSpace(AddressSpace addressSpace);
|
|
static Value fromReference(std::string value, ValueType type);
|
|
static Value ofType(ValueType type);
|
|
};
|
|
|
|
} // namespace domain
|
|
|
|
#endif // DOMAIN_VALUE_H
|