|
Sparkle 0.0.1
|
Node within a BufferLayout representing an object, array or leaf segment. More...
#include <spk_buffer_layout.hpp>

Public Types | |
| using | Content = std::variant<std::monostate, ObjectData, ArrayData> |
| Internal storage describing whether the element is empty, object or array shaped. | |
Public Member Functions | |
| Element ()=default | |
| Builds an empty element. | |
| Element (std::size_t p_size) | |
| Builds a leaf element with a fixed size. | |
| Element (const Element &p_other)=default | |
| Copies layout metadata from another element. | |
| Element & | operator= (const Element &p_other)=default |
| Assigns layout metadata from another element. | |
| std::size_t | offset () const |
| Returns the byte offset from the parent buffer start. | |
| std::size_t | size () const |
| Returns the size of this element in bytes. | |
| void | bind (Buffer p_parentBuffer) |
| Binds this element to a parent buffer. | |
| template<typename TType> | |
| Element & | operator= (const TType &p_value) |
| Assigns data to this element via setData. | |
| template<typename TType> | |
| void | setData (const TType &p_value) |
| Writes trivially-copyable data into the element. | |
| template<typename TType> | |
| const TType & | as () const |
| Interprets the element data as a const reference to a value type. | |
| template<typename TType> | |
| TType & | as () |
| Interprets the element data as a mutable reference to a value type. | |
| void | setData (const void *p_data, std::size_t p_size) |
| Writes raw bytes into the element. | |
| Element & | addMember (const std::wstring &p_name, std::size_t p_relativeOffset, const Element &p_member) |
| Adds a named child member to an object element. | |
| Element & | addArray (const std::wstring &p_name, std::size_t p_relativeOffset, std::size_t p_count, const Element &p_arrayElement) |
| Adds an array child with explicit offset for the first element. | |
| Element & | addArray (const std::wstring &p_name, std::size_t p_count, const Element &p_arrayElement) |
| Adds an array child appended after previous content. | |
| Element & | operator[] (const std::wstring &p_name) |
| Accesses a named child element by reference. | |
| const Element & | operator[] (const std::wstring &p_name) const |
| Accesses a named child element by const reference. | |
| Element & | operator[] (std::size_t p_index) |
| Accesses an array element by index. | |
| const Element & | operator[] (std::size_t p_index) const |
| Accesses an array element by index. | |
| void | remove (const std::wstring &p_name) |
| Removes a named child from an object element. | |
| std::unordered_map< std::wstring, Element > & | objectChildren () |
| Returns mutable children map for objects. | |
| const std::unordered_map< std::wstring, Element > & | objectChildren () const |
| Returns const children map for objects. | |
| std::vector< Element > & | arrayElements () |
| Returns mutable array elements. | |
| const std::vector< Element > & | arrayElements () const |
| Returns const array elements. | |
Friends | |
| class | BufferLayout |
| struct | ObjectData |
| struct | ArrayData |
Node within a BufferLayout representing an object, array or leaf segment.
|
inlineexplicit |
Builds a leaf element with a fixed size.
| p_size | Size in bytes. |
|
default |
Copies layout metadata from another element.
| p_other | Element to copy. |

| BufferLayout::Element & spk::BufferLayout::Element::addArray | ( | const std::wstring & | p_name, |
| std::size_t | p_count, | ||
| const Element & | p_arrayElement ) |
Adds an array child appended after previous content.
| p_name | Field name. |
| p_count | Number of elements. |
| p_arrayElement | Prototype of each element. |

| BufferLayout::Element & spk::BufferLayout::Element::addArray | ( | const std::wstring & | p_name, |
| std::size_t | p_relativeOffset, | ||
| std::size_t | p_count, | ||
| const Element & | p_arrayElement ) |
Adds an array child with explicit offset for the first element.
| p_name | Field name. |
| p_relativeOffset | Offset from this element start. |
| p_count | Number of elements. |
| p_arrayElement | Prototype of each element. |


| BufferLayout::Element & spk::BufferLayout::Element::addMember | ( | const std::wstring & | p_name, |
| std::size_t | p_relativeOffset, | ||
| const Element & | p_member ) |
Adds a named child member to an object element.
| p_name | Field name. |
| p_relativeOffset | Offset from this element start. |
| p_member | Child element layout. |


| std::vector< BufferLayout::Element > & spk::BufferLayout::Element::arrayElements | ( | ) |
Returns mutable array elements.
| const std::vector< BufferLayout::Element > & spk::BufferLayout::Element::arrayElements | ( | ) | const |
Returns const array elements.
|
inline |
Interprets the element data as a mutable reference to a value type.
| TType | Trivially copyable value type matching the element size. |
| std::runtime_error | when the element is unbound or size mismatches. |
|
inline |
Interprets the element data as a const reference to a value type.
| TType | Trivially copyable value type matching the element size. |
| std::runtime_error | when the element is unbound or size mismatches. |
| void spk::BufferLayout::Element::bind | ( | Buffer | p_parentBuffer | ) |
Binds this element to a parent buffer.
| p_parentBuffer | Base buffer pointer. |

| std::unordered_map< std::wstring, BufferLayout::Element > & spk::BufferLayout::Element::objectChildren | ( | ) |
Returns mutable children map for objects.
| const std::unordered_map< std::wstring, BufferLayout::Element > & spk::BufferLayout::Element::objectChildren | ( | ) | const |
Returns const children map for objects.
| std::size_t spk::BufferLayout::Element::offset | ( | ) | const |
Returns the byte offset from the parent buffer start.

Assigns layout metadata from another element.
| p_other | Element to copy from. |

|
inline |
Assigns data to this element via setData.
| TType | Trivially copyable value type. |
| p_value | Value to write. |

| BufferLayout::Element & spk::BufferLayout::Element::operator[] | ( | const std::wstring & | p_name | ) |
Accesses a named child element by reference.
| p_name | Field name. |
| std::out_of_range | when missing. |
| const BufferLayout::Element & spk::BufferLayout::Element::operator[] | ( | const std::wstring & | p_name | ) | const |
Accesses a named child element by const reference.
| p_name | Field name. |
| std::out_of_range | when missing. |
| BufferLayout::Element & spk::BufferLayout::Element::operator[] | ( | std::size_t | p_index | ) |
Accesses an array element by index.
| p_index | Element index. |
| std::out_of_range | when index is invalid. |
| const BufferLayout::Element & spk::BufferLayout::Element::operator[] | ( | std::size_t | p_index | ) | const |
Accesses an array element by index.
| p_index | Element index. |
| std::out_of_range | when index is invalid. |
| void spk::BufferLayout::Element::remove | ( | const std::wstring & | p_name | ) |
Removes a named child from an object element.
| p_name | Field name to remove. |

|
inline |
Writes trivially-copyable data into the element.
| TType | Type of the value; must be trivially copyable. |
| p_value | Value to write. |


| void spk::BufferLayout::Element::setData | ( | const void * | p_data, |
| std::size_t | p_size ) |
Writes raw bytes into the element.
| p_data | Source data pointer. |
| p_size | Number of bytes to copy (must match element size). |
| std::size_t spk::BufferLayout::Element::size | ( | ) | const |
Returns the size of this element in bytes.
