Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::BufferLayout::Element Class Reference

Node within a BufferLayout representing an object, array or leaf segment. More...

#include <spk_buffer_layout.hpp>

Collaboration diagram for spk::BufferLayout::Element:
Collaboration graph

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.
Elementoperator= (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>
Elementoperator= (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.
ElementaddMember (const std::wstring &p_name, std::size_t p_relativeOffset, const Element &p_member)
 Adds a named child member to an object element.
ElementaddArray (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.
ElementaddArray (const std::wstring &p_name, std::size_t p_count, const Element &p_arrayElement)
 Adds an array child appended after previous content.
Elementoperator[] (const std::wstring &p_name)
 Accesses a named child element by reference.
const Elementoperator[] (const std::wstring &p_name) const
 Accesses a named child element by const reference.
Elementoperator[] (std::size_t p_index)
 Accesses an array element by index.
const Elementoperator[] (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

Detailed Description

Node within a BufferLayout representing an object, array or leaf segment.

spk::BufferLayout::Element position(sizeof(float) * 3);
layout.addMember(L"pos", 0, position);
layout[L"pos"].setData(glm::vec3{1.f, 2.f, 3.f});
Node within a BufferLayout representing an object, array or leaf segment.
Definition spk_buffer_layout.hpp:65

Constructor & Destructor Documentation

◆ Element() [1/2]

spk::BufferLayout::Element::Element ( std::size_t p_size)
inlineexplicit

Builds a leaf element with a fixed size.

Parameters
p_sizeSize in bytes.

◆ Element() [2/2]

spk::BufferLayout::Element::Element ( const Element & p_other)
default

Copies layout metadata from another element.

Parameters
p_otherElement to copy.
Here is the call graph for this function:

Member Function Documentation

◆ addArray() [1/2]

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.

Parameters
p_nameField name.
p_countNumber of elements.
p_arrayElementPrototype of each element.
Returns
Reference to the inserted array element container.
Here is the call graph for this function:

◆ addArray() [2/2]

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.

Parameters
p_nameField name.
p_relativeOffsetOffset from this element start.
p_countNumber of elements.
p_arrayElementPrototype of each element.
Returns
Reference to the inserted array element container.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMember()

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.

Parameters
p_nameField name.
p_relativeOffsetOffset from this element start.
p_memberChild element layout.
Returns
Reference to the inserted child.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ arrayElements() [1/2]

std::vector< BufferLayout::Element > & spk::BufferLayout::Element::arrayElements ( )

Returns mutable array elements.

Returns
Vector of elements.

◆ arrayElements() [2/2]

const std::vector< BufferLayout::Element > & spk::BufferLayout::Element::arrayElements ( ) const

Returns const array elements.

Returns
Vector of elements.

◆ as() [1/2]

template<typename TType>
TType & spk::BufferLayout::Element::as ( )
inline

Interprets the element data as a mutable reference to a value type.

Template Parameters
TTypeTrivially copyable value type matching the element size.
Returns
Mutable reference to the stored value.
Exceptions
std::runtime_errorwhen the element is unbound or size mismatches.

◆ as() [2/2]

template<typename TType>
const TType & spk::BufferLayout::Element::as ( ) const
inline

Interprets the element data as a const reference to a value type.

Template Parameters
TTypeTrivially copyable value type matching the element size.
Returns
Const reference to the stored value.
Exceptions
std::runtime_errorwhen the element is unbound or size mismatches.

◆ bind()

void spk::BufferLayout::Element::bind ( Buffer p_parentBuffer)

Binds this element to a parent buffer.

Parameters
p_parentBufferBase buffer pointer.
Here is the caller graph for this function:

◆ objectChildren() [1/2]

std::unordered_map< std::wstring, BufferLayout::Element > & spk::BufferLayout::Element::objectChildren ( )

Returns mutable children map for objects.

Returns
Map of name to element.

◆ objectChildren() [2/2]

const std::unordered_map< std::wstring, BufferLayout::Element > & spk::BufferLayout::Element::objectChildren ( ) const

Returns const children map for objects.

Returns
Map of name to element.

◆ offset()

std::size_t spk::BufferLayout::Element::offset ( ) const

Returns the byte offset from the parent buffer start.

Returns
Offset in bytes.
Here is the caller graph for this function:

◆ operator=() [1/2]

Element & spk::BufferLayout::Element::operator= ( const Element & p_other)
default

Assigns layout metadata from another element.

Parameters
p_otherElement to copy from.
Returns
Reference to this element.
Here is the call graph for this function:

◆ operator=() [2/2]

template<typename TType>
Element & spk::BufferLayout::Element::operator= ( const TType & p_value)
inline

Assigns data to this element via setData.

Template Parameters
TTypeTrivially copyable value type.
Parameters
p_valueValue to write.
Returns
Reference to this element.
Here is the call graph for this function:

◆ operator[]() [1/4]

BufferLayout::Element & spk::BufferLayout::Element::operator[] ( const std::wstring & p_name)

Accesses a named child element by reference.

Parameters
p_nameField name.
Returns
Reference to the child element.
Exceptions
std::out_of_rangewhen missing.

◆ operator[]() [2/4]

const BufferLayout::Element & spk::BufferLayout::Element::operator[] ( const std::wstring & p_name) const

Accesses a named child element by const reference.

Parameters
p_nameField name.
Returns
Const reference to the child element.
Exceptions
std::out_of_rangewhen missing.

◆ operator[]() [3/4]

BufferLayout::Element & spk::BufferLayout::Element::operator[] ( std::size_t p_index)

Accesses an array element by index.

Parameters
p_indexElement index.
Returns
Reference to the element.
Exceptions
std::out_of_rangewhen index is invalid.

◆ operator[]() [4/4]

const BufferLayout::Element & spk::BufferLayout::Element::operator[] ( std::size_t p_index) const

Accesses an array element by index.

Parameters
p_indexElement index.
Returns
Const reference to the element.
Exceptions
std::out_of_rangewhen index is invalid.

◆ remove()

void spk::BufferLayout::Element::remove ( const std::wstring & p_name)

Removes a named child from an object element.

Parameters
p_nameField name to remove.
Here is the caller graph for this function:

◆ setData() [1/2]

template<typename TType>
void spk::BufferLayout::Element::setData ( const TType & p_value)
inline

Writes trivially-copyable data into the element.

Template Parameters
TTypeType of the value; must be trivially copyable.
Parameters
p_valueValue to write.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setData() [2/2]

void spk::BufferLayout::Element::setData ( const void * p_data,
std::size_t p_size )

Writes raw bytes into the element.

Parameters
p_dataSource data pointer.
p_sizeNumber of bytes to copy (must match element size).

◆ size()

std::size_t spk::BufferLayout::Element::size ( ) const

Returns the size of this element in bytes.

Returns
Byte size.
Here is the caller graph for this function:

The documentation for this class was generated from the following files: