2022-03-31 21:20:41 +00:00
|
|
|
#ifndef DOMAIN_VALUE_H
|
|
|
|
#define DOMAIN_VALUE_H
|
|
|
|
|
|
|
|
#include "addressspace.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <optional>
|
|
|
|
|
2022-04-08 17:13:53 +00:00
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
namespace domain {
|
|
|
|
|
2022-05-15 21:55:03 +00:00
|
|
|
class ComponentInstance;
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
class Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum ValueType {
|
|
|
|
INT,
|
|
|
|
STRING,
|
|
|
|
BOOL,
|
|
|
|
ADDRESS_SPACE,
|
2022-04-10 12:23:18 +00:00
|
|
|
ADDRESS_SPACE_REFERENCE,
|
2022-03-31 21:20:41 +00:00
|
|
|
ATTRIBUTE_REFERENCE,
|
2022-05-15 21:55:03 +00:00
|
|
|
MEMORY_REFERENCE,
|
|
|
|
MEMORY,
|
2022-03-31 21:20:41 +00:00
|
|
|
WIRE_REFERENCE,
|
2022-04-08 20:46:47 +00:00
|
|
|
NIL,
|
2022-03-31 21:20:41 +00:00
|
|
|
UNDEFINED,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
long long intValue;
|
|
|
|
std::string stringValue;
|
|
|
|
bool boolValue;
|
|
|
|
std::optional<AddressSpace> addressSpace;
|
|
|
|
std::string reference;
|
2022-05-15 21:55:03 +00:00
|
|
|
domain::ComponentInstance *memory;
|
|
|
|
|
|
|
|
std::optional<std::string> memoryReference;
|
2022-03-31 21:20:41 +00:00
|
|
|
|
|
|
|
ValueType type;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Value() {
|
|
|
|
this->type = UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2022-05-15 14:13:29 +00:00
|
|
|
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;
|
2022-05-15 21:55:03 +00:00
|
|
|
case MEMORY_REFERENCE:
|
|
|
|
return value.asMemoryReference() == memoryReference;
|
|
|
|
case MEMORY:
|
|
|
|
return value.asMemory() == memory;
|
2022-05-15 14:13:29 +00:00
|
|
|
case BOOL:
|
|
|
|
return value.asBool() == boolValue;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-10 12:23:18 +00:00
|
|
|
std::string string();
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
ValueType getType();
|
|
|
|
bool isType(ValueType type);
|
|
|
|
|
|
|
|
long long asInt();
|
|
|
|
std::string asString();
|
|
|
|
bool asBool();
|
|
|
|
std::string asReference();
|
2022-05-15 21:55:03 +00:00
|
|
|
std::optional<std::string> asMemoryReference();
|
|
|
|
domain::ComponentInstance* asMemory();
|
2022-03-31 21:20:41 +00:00
|
|
|
AddressSpace asAddressSpace();
|
|
|
|
|
2022-04-05 21:48:07 +00:00
|
|
|
void setInt(long long intValue);
|
|
|
|
void setString(std::string value);
|
|
|
|
void setBool(bool value);
|
|
|
|
void setReference(std::string value);
|
|
|
|
|
2022-04-24 20:21:45 +00:00
|
|
|
std::string stringify();
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
static Value fromInt(long long value);
|
|
|
|
static Value fromString(std::string value);
|
|
|
|
static Value fromBool(bool value);
|
2022-04-08 20:46:47 +00:00
|
|
|
static Value fromNull();
|
2022-03-31 21:20:41 +00:00
|
|
|
static Value fromAddressSpace(AddressSpace addressSpace);
|
|
|
|
static Value fromReference(std::string value, ValueType type);
|
|
|
|
static Value ofType(ValueType type);
|
2022-05-15 21:55:03 +00:00
|
|
|
static Value fromMemoryReference(std::optional<std::string> memoryReference);
|
|
|
|
static Value fromMemory(domain::ComponentInstance *memory);
|
2022-03-31 21:20:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace domain
|
|
|
|
|
|
|
|
#endif // DOMAIN_VALUE_H
|