Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::SdlNativeData Class Referencefinal

#include <SdlNativeData.h>

Public Types

template<typename Func >
using TElementAccessor = TFunction<Func, 32>
 
using ElementGetter = TElementAccessor<SdlGetterVariant(std::size_t elementIdx)>
 
using ElementSetter = TElementAccessor<bool(std::size_t elementIdx, SdlSetterVariant input)>
 

Public Member Functions

 SdlNativeData ()
 Creates empty native data.
 
 SdlNativeData (ElementGetter getter)
 Creates read-only native data.
 
 SdlNativeData (ElementGetter getter, ElementSetter setter)
 Creates native data with both read and write capabilities.
 
 SdlNativeData (ElementGetter getter, ElementSetter setter, AnyNonConstPtr directPtr)
 Creates native data with custom capabilities.
 
template<typename T >
requires std::is_arithmetic_v<T> || std::is_enum_v<T>
std::optional< T > get (std::size_t elementIdx) const
 
template<typename T >
requires std::is_pointer_v<T>
get (std::size_t elementIdx) const
 
template<typename T >
requires std::is_arithmetic_v<T> || std::is_enum_v<T>
bool set (std::size_t elementIdx, T value) const
 
template<typename T >
requires std::is_pointer_v<T>
bool set (std::size_t elementIdx, T ptr) const
 
template<typename T >
requires std::is_null_pointer_v<T>
bool set (std::size_t elementIdx, T nullPtr) const
 
template<typename T >
T * directAccess () const
 Directly access the underlying data. Use of direct accessor may invalidate getter and setter accessors (should reacquire native data from source for subsequent getter/setter access). Direct accessor never invalidate itself.
 
void setDirectAccessor (AnyNonConstPtr accessor)
 
bool isIntegerElement () const
 
bool isFloatingPointElement () const
 
 operator bool () const
 

Static Public Member Functions

template<typename ElementType >
static SdlNativeData fromSingleElement (ElementType *elementPtr, ESdlDataFormat elementContainer, ESdlDataType elementType, bool canSet=false, bool canDirectAccess=false)
 Creates native data for a single element pointer.
 
template<typename ElementType >
static auto permissiveElementGetter (ElementType *elementPtr) -> SdlGetterVariant
 Given a valid target element, get its value in a permissive way (with auto conversions).
 
template<typename ElementType >
static auto permissiveElementSetter (SdlSetterVariant input, ElementType *out_elementPtr) -> bool
 Given a valid target element, set its value in a permissive way (with auto conversions).
 

Public Attributes

std::size_t numElements = 0
 Hint for number of elements in this block of native data. For example, numElements would be 12 for an array of 12 ints; and 24 for an array of 12 vec2s.
 
std::size_t tupleSize = 0
 Hint for number of elements that form a natural group. For an array of 10 vec3s, tupleSize may have a value of 3 to indicate that for those 30 elements in the array every 3 elements can form a group. This information is not always provided.
 
ESdlDataFormat elementContainer = ESdlDataFormat::None
 Hint for the type that encapsulates elements.
 
ESdlDataType elementType = ESdlDataType::None
 Hint for the type of elements.
 
uint8 isNullClearable: 1 = false
 Whether the data can be set as empty by assigning null to it. For example, if this flag is true and the data is with a ESdlDataFormat::Single format, you can use set(0, nullptr) to clear it (and use set(0, T{}) to set it). Other formats and types follow the same principle.
 

Detailed Description

All public fields are only hints and may not always be available. They provide additional information for the underlying data, which can help to better interpret them. Implementation ensures there is no dynamic allocation and the size of the object should be reasonably small (independent of the data it is representing). This object can be cached if only getter and setter accessors are used.

Note on the implementation of getter & setter accessors: Implementation should guarantee that any calls to getter & setter accessors will not cause the accessors to be invalid (invalidated) in any way, so an instance of SdlNativeData can be reused many times. Use of direct accessor may invalidate getter and setter accessors. See corresponding methods for more information.

Note on getting hints for interpreting native data: If the operation done on the native data would potentially alter the underlying data structure, it is advisable to retrieve a new instance of SdlNativeData to see the updated hint.

Member Typedef Documentation

◆ ElementGetter

◆ ElementSetter

using ph::SdlNativeData::ElementSetter = TElementAccessor<bool(std::size_t elementIdx, SdlSetterVariant input)>

◆ TElementAccessor

template<typename Func >
using ph::SdlNativeData::TElementAccessor = TFunction<Func, 32>

Constructor & Destructor Documentation

◆ SdlNativeData() [1/4]

ph::SdlNativeData::SdlNativeData ( )
inline

Creates empty native data.

◆ SdlNativeData() [2/4]

ph::SdlNativeData::SdlNativeData ( ElementGetter getter)
inlineexplicit

Creates read-only native data.

◆ SdlNativeData() [3/4]

ph::SdlNativeData::SdlNativeData ( ElementGetter getter,
ElementSetter setter )
inline

Creates native data with both read and write capabilities.

◆ SdlNativeData() [4/4]

ph::SdlNativeData::SdlNativeData ( ElementGetter getter,
ElementSetter setter,
AnyNonConstPtr directPtr )
inline

Creates native data with custom capabilities.

Member Function Documentation

◆ directAccess()

template<typename T >
T * ph::SdlNativeData::directAccess ( ) const
inline

Directly access the underlying data. Use of direct accessor may invalidate getter and setter accessors (should reacquire native data from source for subsequent getter/setter access). Direct accessor never invalidate itself.

◆ fromSingleElement()

template<typename ElementType >
SdlNativeData ph::SdlNativeData::fromSingleElement ( ElementType * elementPtr,
ESdlDataFormat elementContainer,
ESdlDataType elementType,
bool canSet = false,
bool canDirectAccess = false )
inlinestatic

Creates native data for a single element pointer.

Parameters
elementPtrPointer to the single element. If null, all native data access will be no-op.
canSetIf true, elementPtr will also be used for ordinary setter.
canDirectAccessIf true, elementPtr will also be used for direct access.

◆ get() [1/2]

template<typename T >
requires std::is_arithmetic_v<T> || std::is_enum_v<T>
std::optional< T > ph::SdlNativeData::get ( std::size_t elementIdx) const
inline

◆ get() [2/2]

template<typename T >
requires std::is_pointer_v<T>
T ph::SdlNativeData::get ( std::size_t elementIdx) const
inline

◆ isFloatingPointElement()

bool ph::SdlNativeData::isFloatingPointElement ( ) const
inline

◆ isIntegerElement()

bool ph::SdlNativeData::isIntegerElement ( ) const
inline

◆ operator bool()

ph::SdlNativeData::operator bool ( ) const
inline

◆ permissiveElementGetter()

template<typename ElementType >
auto ph::SdlNativeData::permissiveElementGetter ( ElementType * elementPtr) -> SdlGetterVariant
inlinestatic

Given a valid target element, get its value in a permissive way (with auto conversions).

Parameters
elementPtrPointer to the target element. Cannot be null.

◆ permissiveElementSetter()

template<typename ElementType >
auto ph::SdlNativeData::permissiveElementSetter ( SdlSetterVariant input,
ElementType * out_elementPtr ) -> bool
inlinestatic

Given a valid target element, set its value in a permissive way (with auto conversions).

Parameters
out_elementPtrPointer to the target element. Cannot be null.

◆ set() [1/3]

template<typename T >
requires std::is_null_pointer_v<T>
bool ph::SdlNativeData::set ( std::size_t elementIdx,
T nullPtr ) const

◆ set() [2/3]

template<typename T >
requires std::is_pointer_v<T>
bool ph::SdlNativeData::set ( std::size_t elementIdx,
T ptr ) const

◆ set() [3/3]

template<typename T >
requires std::is_arithmetic_v<T> || std::is_enum_v<T>
bool ph::SdlNativeData::set ( std::size_t elementIdx,
T value ) const
inline

◆ setDirectAccessor()

void ph::SdlNativeData::setDirectAccessor ( AnyNonConstPtr accessor)
inline

Member Data Documentation

◆ elementContainer

ESdlDataFormat ph::SdlNativeData::elementContainer = ESdlDataFormat::None

Hint for the type that encapsulates elements.

◆ elementType

ESdlDataType ph::SdlNativeData::elementType = ESdlDataType::None

Hint for the type of elements.

◆ isNullClearable

uint8 ph::SdlNativeData::isNullClearable

Whether the data can be set as empty by assigning null to it. For example, if this flag is true and the data is with a ESdlDataFormat::Single format, you can use set(0, nullptr) to clear it (and use set(0, T{}) to set it). Other formats and types follow the same principle.

◆ numElements

std::size_t ph::SdlNativeData::numElements = 0

Hint for number of elements in this block of native data. For example, numElements would be 12 for an array of 12 ints; and 24 for an array of 12 vec2s.

◆ tupleSize

std::size_t ph::SdlNativeData::tupleSize = 0

Hint for number of elements that form a natural group. For an array of 10 vec3s, tupleSize may have a value of 3 to indicate that for those 30 elements in the array every 3 elements can form a group. This information is not always provided.


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