10#include <jaffarCommon/exceptions.hpp>
11#include <jaffarCommon/hash.hpp>
82 JAFFAR_THROW_LOGIC(
"Endianness '%s' not recognized.", endiannessName.c_str());
105 JAFFAR_THROW_LOGIC(
"Data type '%s' not recognized.", datatypeName.c_str());
131 JAFFAR_THROW_LOGIC(
"Unidentified datatype %d\n", datatype);
143 template <
typename T>
148 const auto bufferSize =
sizeof(T);
149 if (size != bufferSize) JAFFAR_THROW_LOGIC(
"Incompatible datatypes while getting value of property '%s'",
getName().c_str());
156 const auto sBuf = (uint8_t*)
_pointer;
157 auto dBuf = (uint8_t*)&value;
158 if (size == 1) { dBuf[0] = sBuf[0]; }
A named, typed reference to a value stored at a memory address.
const endianness_t _endianness
Byte order of the value at _pointer.
datatype_t getDatatype() const
Returns the property's datatype.
static endianness_t parseEndiannessName(const std::string &endiannessName)
Maps a configuration endianness string to its endianness_t value.
std::string getName() const
Returns the property's name.
const std::string _name
Identifying name of the property.
T getValue() const
Reads the property's value at its memory address as type T, applying endianness conversion.
const datatype_t _datatype
How the bytes at _pointer are interpreted.
endianness_t
The byte order of the value stored at the property's memory address.
@ little
Little endian byte order (config endianness "Little").
@ big
Big endian byte order (config endianness "Big").
void * getPointer() const
Returns the raw pointer to the property's value in memory.
const jaffarCommon::hash::hash_t _nameHash
Precomputed hash of _name for fast lookup.
size_t getSize() const
Returns the size in bytes of the property's value.
Property(const std::string &name, void *const pointer, const datatype_t datatype, endianness_t endianness)
Constructs a property describing a value in memory.
datatype_t
The interpretation of the bytes at the property's memory address.
@ dt_int32
Signed 32-bit integer (config datatype "INT32").
@ dt_int8
Signed 8-bit integer (config datatype "INT8").
@ dt_float32
Single precision float, 32-bit (config datatype "FLOAT32").
@ dt_uint64
Unsigned 64-bit integer (config datatype "UINT64").
@ dt_uint16
Unsigned 16-bit integer (config datatype "UINT16").
@ dt_uint8
Unsigned 8-bit integer (config datatype "UINT8").
@ dt_int16
Signed 16-bit integer (config datatype "INT16").
@ dt_uint32
Unsigned 32-bit integer (config datatype "UINT32").
@ dt_bool
Boolean stored in a single byte (config datatype "BOOL").
@ dt_float64
Double precision float, 64-bit (config datatype "FLOAT64").
@ dt_int64
Signed 64-bit integer (config datatype "INT64").
static size_t getDatatypeSize(const datatype_t datatype)
Returns the size in bytes of a given datatype.
jaffarCommon::hash::hash_t getNameHash() const
Returns the hash of the property's name.
static datatype_t parseDatatypeName(const std::string &datatypeName)
Maps a configuration datatype string to its datatype_t value.
Property()=delete
Default construction is disabled; a property requires a name, pointer, datatype and endianness.
void *const _pointer
Pointer to the property's value in game memory.