Raw Data and Type Identification
libxr_type.hpp provides the raw data views RawData and ConstRawData and the RTTI-free type identifier TypeID, used to pass raw data between interfaces.
RawData
class RawData;
A generic data wrapper that stores a pointer and size in bytes.
Constructors
RawData(void* addr, size_t size)– Specify address and size directly.RawData()– Default constructor for empty data.RawData(T&)– Construct from a writable object, referencing its address, with sizesizeof(T);std::stringandstd::string_vieware not accepted.RawData(char*)– Construct from a C-style string (excluding the trailing\0).RawData(char (&str)[N])– Construct from a writable char array, trimming at most one trailing\0.explicit RawData(std::string&)– Construct from a writablestd::string, viewing its text.
Fields
void* addr_– Data pointersize_t size_– Size in bytes
ConstRawData
class ConstRawData;
Read-only data wrapper, similar to RawData but with an immutable address:
Constructors
- Constructible from arbitrary objects (except
std::stringandstd::string_view),RawData,char* / const char*and char arrays;std::stringandstd::string_viewconvert only explicitly (the constructors areexplicit). - Ensures
addr_is of typeconst void*, suitable for read-only views.
Additional notes:
- Char-array construction currently trims at most one trailing
\0, not every zero byte in the array. char* / const char*construction usesstd::strlen(...), so it expects a NUL-terminated string.std::stringandstd::string_viewdo not convert implicitly toConstRawDataorRawData: passing one directly to such a parameter or initializing with=fails to compile. A text view must be written explicitly asLibXR::ConstRawData(text)(a writablestd::stringalso asLibXR::RawData(text)), with sizetext.size().
Fields
const void* addr_– Read-only data pointersize_t size_– Size in bytes
TypeID
class TypeID;
A lightweight type identification tool to avoid RTTI and typeid.
Method
template <typename T>
static TypeID::ID GetID();
Returns one process-local static address (const void*) for each type:
auto id1 = LibXR::TypeID::GetID<int>();
auto id2 = LibXR::TypeID::GetID<std::string>();
Useful for type registration, dispatching, or distinguishing types without runtime type information.
Use Cases
- Passing raw data via generic interfaces, data buffers, or IPC mechanisms
- Uniquely identifying types in RTTI-less environments (e.g., embedded registries, plugin systems)
- Passing structs with
LibXR::Topic