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

Describes and writes typed data into a raw buffer with object/array hierarchy. More...

#include <spk_buffer_layout.hpp>

Collaboration diagram for spk::BufferLayout:
Collaboration graph

Classes

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

Public Types

using Buffer = std::uint8_t *
 Raw byte buffer bound to the layout operations.

Public Member Functions

 BufferLayout (Buffer p_buffer, std::size_t p_size)
 Creates a layout bound to a buffer.
Elementroot ()
 Accesses the root element.
const Elementroot () const
 Accesses the root element.
ElementaddMember (const std::wstring &p_name, std::size_t p_relativeOffset, const Element &p_member)
 Adds a named member to the root object.
ElementaddArray (const std::wstring &p_name, std::size_t p_relativeOffset, std::size_t p_count, const Element &p_arrayElement)
 Adds an array to the root with explicit offset.
Elementoperator[] (const std::wstring &p_name)
 Accesses a named child from the root.
const Elementoperator[] (const std::wstring &p_name) const
 Accesses a named child from the root (const).
void remove (const std::wstring &p_name)
 Removes a named child from the root.
void resize (std::size_t p_size)
 Resizes the underlying buffer and updates the root size.

Detailed Description

Describes and writes typed data into a raw buffer with object/array hierarchy.

std::vector<uint8_t> buf(64, 0);
spk::BufferLayout layout(buf.data(), buf.size());
layout.addMember(L"pos", 0, spk::BufferLayout::Element(sizeof(float) * 3));
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
Describes and writes typed data into a raw buffer with object/array hierarchy.
Definition spk_buffer_layout.hpp:26

Constructor & Destructor Documentation

◆ BufferLayout()

spk::BufferLayout::BufferLayout ( Buffer p_buffer,
std::size_t p_size )

Creates a layout bound to a buffer.

Parameters
p_bufferTarget buffer pointer.
p_sizeTotal buffer size in bytes.

Member Function Documentation

◆ addArray()

BufferLayout::Element & spk::BufferLayout::addArray ( const std::wstring & p_name,
std::size_t p_relativeOffset,
std::size_t p_count,
const Element & p_arrayElement )

Adds an array to the root with explicit offset.

Parameters
p_nameField name.
p_relativeOffsetOffset within the buffer.
p_countNumber of elements.
p_arrayElementPrototype element layout.
Returns
Reference to the inserted array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMember()

BufferLayout::Element & spk::BufferLayout::addMember ( const std::wstring & p_name,
std::size_t p_relativeOffset,
const Element & p_member )

Adds a named member to the root object.

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

◆ operator[]() [1/2]

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

Accesses a named child from the root.

Parameters
p_nameField name.
Returns
Reference to the child element.

◆ operator[]() [2/2]

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

Accesses a named child from the root (const).

Parameters
p_nameField name.
Returns
Const reference to the child element.

◆ remove()

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

Removes a named child from the root.

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

◆ resize()

void spk::BufferLayout::resize ( std::size_t p_size)

Resizes the underlying buffer and updates the root size.

Parameters
p_sizeNew buffer size.

◆ root() [1/2]

BufferLayout::Element & spk::BufferLayout::root ( )

Accesses the root element.

Returns
Mutable root element.
Here is the caller graph for this function:

◆ root() [2/2]

const BufferLayout::Element & spk::BufferLayout::root ( ) const

Accesses the root element.

Returns
Const root element.

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