Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::TSdlValue< T, Owner > Class Template Referenceabstract

Abstractions for a SDL value type. More...

#include <TSdlValue.h>

Inheritance diagram for ph::TSdlValue< T, Owner >:
ph::TSdlAbstractValue< T, Owner > ph::TSdlOwnedField< Owner > ph::SdlField ph::TSdlBool< Owner, SdlValueType > ph::TSdlEnumField< Owner, EnumType, SdlValueType > ph::TSdlInteger< Owner, IntType, SdlValueType > ph::TSdlPath< Owner, SdlValueType > ph::TSdlQuaternion< Owner, Element, SdlValueType > ph::TSdlReal< Owner, FloatType, SdlValueType > ph::TSdlRealArray< Owner, Element, SdlValueType > ph::TSdlResourceIdentifier< Owner, IS_SRI, SdlValueType > ph::TSdlSpectrum< Owner, SdlValueType > ph::TSdlString< Owner, SdlValueType > ph::TSdlVector2< Owner, Element, SdlValueType > ph::TSdlVector3< Owner, Element, SdlValueType > ph::TSdlVector4< Owner, Element, SdlValueType >

Public Member Functions

 TSdlValue (std::string typeName, std::string valueName, T Owner::*valuePtr)
 
 TSdlValue (std::string typeName, std::string valueName, std::string typeSignature, T Owner::*valuePtr)
 
std::string valueAsString (const T &value) const override=0
 Human-readable representation of the value.
 
SdlNativeData ownedNativeData (Owner &owner) const override=0
 Direct access to the field memory of an owner. Short-lived owner objects such as function parameter structs must be kept alive during during this call and any further usages of the returned native data.
 
void setValue (Owner &owner, T value) const override
 Store a value.
 
T * getValue (Owner &owner) const override
 Get a pointer to the stored value.
 
const T * getConstValue (const Owner &owner) const override
 Get a pointer to the stored value.
 
void ownedValueToDefault (Owner &owner) const override
 Set the value of the field to a default one. Since the field class is templatized by Owner type, we are able to define default value on a per owner type basis.
 
const T * getDefaultValue () const
 
TSdlValuedefaultTo (T defaultValue)
 
TSdlValuenoDefault ()
 
TSdlValuewithImportance (EFieldImportance importance)
 
TSdlValuedescription (std::string descriptionStr)
 
TSdlValueoptional ()
 
TSdlValueniceToHave ()
 
TSdlValuerequired ()
 
TSdlValueenableFallback (bool isFallbackEnabled)
 
- Public Member Functions inherited from ph::TSdlAbstractValue< T, Owner >
 TSdlAbstractValue (std::string typeName, std::string valueName)
 
 TSdlAbstractValue (std::string typeName, std::string valueName, std::string typeSignature)
 
std::string valueToString (const Owner &owner) const override
 Convert the value of the field to human-readable string.
 
void ownedResources (const Owner &owner, std::vector< const ISdlResource * > &out_resources) const override
 Get all SDL resources associated by owner.
 
- Public Member Functions inherited from ph::TSdlOwnedField< Owner >
 TSdlOwnedField (std::string typeName, std::string valueName)
 
 TSdlOwnedField (std::string typeName, std::string valueName, std::string typeSignature)
 
SdlNativeData nativeData (SdlNonConstInstance instance) const override
 Direct access to the field memory of a SDL instance. Note that this field may not necessarily be bound to a SDL resource type (e.g., may bound to any function parameter structs). Empty native data info will be returned in cases where this field is not owned by (or being part of) the input instance. Obtaining native data requires the input instance be valid during this call and any further usages of the returned native data.
 
void fromSdl (Owner &owner, const SdlInputClause &clause, const SdlInputContext &ctx) const
 Acquire value and store in the owner's field. The loading process will follow a series of preset policy. In addition, failed loading attempt may be recovered if needed.
 
void toSdl (const Owner &owner, SdlOutputClause &out_clause, const SdlOutputContext &ctx) const
 
- Public Member Functions inherited from ph::SdlField
 SdlField (std::string typeName, std::string fieldName)
 
 SdlField (std::string typeName, std::string fieldName, std::string typeSignature)
 
virtual ~SdlField ()
 
std::string genPrettyName () const
 
std::string_view getTypeName () const
 
std::string_view getFieldName () const
 
std::string_view getDescription () const
 
std::string_view getTypeSignature () const
 
EFieldImportance getImportance () const
 
bool isFallbackEnabled () const
 Whether the field want to use built-in mechanism to handle I/O problems. An example of this is default field value. With fallback enabled, the field may set itself to the default value supplied (if available) on error. By default, fallback is enabled.
 

Protected Member Functions

void loadFromSdl (Owner &owner, const SdlInputClause &clause, const SdlInputContext &ctx) const override=0
 Load SDL value to actual value and store it in the owner's field. Implementations are highly encouraged to throw SdlLoadError if the loading process is not successful. This will allow things such as automatic fallback to work according to field policies.
 
void saveToSdl (const Owner &owner, SdlOutputClause &out_clause, const SdlOutputContext &ctx) const override=0
 Convert actual value back to SDL value. Saving a loaded value as SDL value should rarely fail–as loaded value has been properly handled by the loading process already. In case of failure, throw SdlSaveError and provide detailed reason describing the event.
 
T & valueRef (Owner &owner) const
 
- Protected Member Functions inherited from ph::SdlField
SdlFieldsetDescription (std::string descriptionStr)
 
SdlFieldsetImportance (EFieldImportance importance)
 Sets the importance of the field. Different importance affect the underlying policy used during the import and export of the field, e.g., whether warnings are emitted.
 
SdlFieldsetEnableFallback (bool isFallbackEnabled)
 

Detailed Description

template<typename T, typename Owner>
class ph::TSdlValue< T, Owner >

Abstractions for a SDL value type.

A default value can be specified for instances of this type. If the default value is not explicitly provided (by defaultTo() or other means), default value will be the value initialization of the type T (basically a mix of default and zero initialization). If default value is not wanted, use noDefault().

value initialization: https://en.cppreference.com/w/cpp/language/value_initialization

Constructor & Destructor Documentation

◆ TSdlValue() [1/2]

template<typename T , typename Owner >
ph::TSdlValue< T, Owner >::TSdlValue ( std::string typeName,
std::string valueName,
T Owner::* valuePtr )
inline

◆ TSdlValue() [2/2]

template<typename T , typename Owner >
ph::TSdlValue< T, Owner >::TSdlValue ( std::string typeName,
std::string valueName,
std::string typeSignature,
T Owner::* valuePtr )
inline

Member Function Documentation

◆ defaultTo()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::defaultTo ( T defaultValue)
inline

◆ description()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::description ( std::string descriptionStr)
inline

◆ enableFallback()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::enableFallback ( bool isFallbackEnabled)
inline

◆ getConstValue()

template<typename T , typename Owner >
const T * ph::TSdlValue< T, Owner >::getConstValue ( const Owner & owner) const
inlineoverridevirtual

Get a pointer to the stored value.

Returns
Pointer to the stored value. nullptr if no value is stored.

Implements ph::TSdlAbstractValue< T, Owner >.

◆ getDefaultValue()

template<typename T , typename Owner >
const T * ph::TSdlValue< T, Owner >::getDefaultValue ( ) const
inline

◆ getValue()

template<typename T , typename Owner >
T * ph::TSdlValue< T, Owner >::getValue ( Owner & owner) const
inlineoverridevirtual

Get a pointer to the stored value.

Returns
Pointer to the stored value. nullptr if no value is stored.

Implements ph::TSdlAbstractValue< T, Owner >.

◆ loadFromSdl()

template<typename T , typename Owner >
void ph::TSdlValue< T, Owner >::loadFromSdl ( Owner & owner,
const SdlInputClause & clause,
const SdlInputContext & ctx ) const
overrideprotectedpure virtual

Load SDL value to actual value and store it in the owner's field. Implementations are highly encouraged to throw SdlLoadError if the loading process is not successful. This will allow things such as automatic fallback to work according to field policies.

Parameters
ownerInstance that owns the field.
clauseThe SDL representation to be loaded into actual value.
ctxThe context for loading.

Implements ph::TSdlAbstractValue< T, Owner >.

Implemented in ph::TSdlBool< Owner, SdlValueType >, ph::TSdlEnumField< Owner, EnumType, SdlValueType >, ph::TSdlInteger< Owner, IntType, SdlValueType >, ph::TSdlPath< Owner, SdlValueType >, ph::TSdlQuaternion< Owner, Element, SdlValueType >, ph::TSdlReal< Owner, FloatType, SdlValueType >, ph::TSdlRealArray< Owner, Element, SdlValueType >, ph::TSdlResourceIdentifier< Owner, IS_SRI, SdlValueType >, ph::TSdlSpectrum< Owner, SdlValueType >, ph::TSdlString< Owner, SdlValueType >, ph::TSdlVector2< Owner, Element, SdlValueType >, ph::TSdlVector3< Owner, Element, SdlValueType >, and ph::TSdlVector4< Owner, Element, SdlValueType >.

◆ niceToHave()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::niceToHave ( )
inline

◆ noDefault()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::noDefault ( )
inline

◆ optional()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::optional ( )
inline

◆ ownedNativeData()

◆ ownedValueToDefault()

template<typename T , typename Owner >
void ph::TSdlValue< T, Owner >::ownedValueToDefault ( Owner & owner) const
inlineoverridevirtual

Set the value of the field to a default one. Since the field class is templatized by Owner type, we are able to define default value on a per owner type basis.

Implements ph::TSdlAbstractValue< T, Owner >.

◆ required()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::required ( )
inline

◆ saveToSdl()

template<typename T , typename Owner >
void ph::TSdlValue< T, Owner >::saveToSdl ( const Owner & owner,
SdlOutputClause & out_clause,
const SdlOutputContext & ctx ) const
overrideprotectedpure virtual

Convert actual value back to SDL value. Saving a loaded value as SDL value should rarely fail–as loaded value has been properly handled by the loading process already. In case of failure, throw SdlSaveError and provide detailed reason describing the event.

Parameters
ownerInstance that owns the field.
out_clauseThe SDL representation for the actual value.
ctxThe context for saving.

Implements ph::TSdlAbstractValue< T, Owner >.

Implemented in ph::TSdlBool< Owner, SdlValueType >, ph::TSdlEnumField< Owner, EnumType, SdlValueType >, ph::TSdlInteger< Owner, IntType, SdlValueType >, ph::TSdlPath< Owner, SdlValueType >, ph::TSdlQuaternion< Owner, Element, SdlValueType >, ph::TSdlReal< Owner, FloatType, SdlValueType >, ph::TSdlRealArray< Owner, Element, SdlValueType >, ph::TSdlResourceIdentifier< Owner, IS_SRI, SdlValueType >, ph::TSdlSpectrum< Owner, SdlValueType >, ph::TSdlString< Owner, SdlValueType >, ph::TSdlVector2< Owner, Element, SdlValueType >, ph::TSdlVector3< Owner, Element, SdlValueType >, and ph::TSdlVector4< Owner, Element, SdlValueType >.

◆ setValue()

template<typename T , typename Owner >
void ph::TSdlValue< T, Owner >::setValue ( Owner & owner,
T value ) const
inlineoverridevirtual

Store a value.

Implements ph::TSdlAbstractValue< T, Owner >.

◆ valueAsString()

template<typename T , typename Owner >
std::string ph::TSdlValue< T, Owner >::valueAsString ( const T & value) const
overridepure virtual

Human-readable representation of the value.

Implements ph::TSdlAbstractValue< T, Owner >.

◆ valueRef()

template<typename T , typename Owner >
T & ph::TSdlValue< T, Owner >::valueRef ( Owner & owner) const
inlineprotected

◆ withImportance()

template<typename T , typename Owner >
auto ph::TSdlValue< T, Owner >::withImportance ( EFieldImportance importance)
inline

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