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

A value that points to a SDL resource. More...

#include <TSdlReference.h>

Inheritance diagram for ph::TSdlReference< T, Owner >:
ph::TSdlOwnedField< Owner > ph::SdlField

Public Member Functions

 TSdlReference (std::string valueName, std::shared_ptr< T > Owner::*valuePtr)
 
void ownedValueToDefault (Owner &owner) const override
 By default, default value of a SDL reference is empty.
 
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.
 
SdlNativeData ownedNativeData (Owner &owner) const override
 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 setValueRef (Owner &owner, std::shared_ptr< T > value) const
 
const std::shared_ptr< T > & getValueRef (const Owner &owner) const
 
TSdlReferencewithImportance (EFieldImportance importance)
 
TSdlReferencedescription (std::string descriptionStr)
 
TSdlReferenceoptional ()
 
TSdlReferenceniceToHave ()
 
TSdlReferencerequired ()
 
- 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.
 

Static Public Member Functions

template<typename ResourceType = T>
static std::shared_ptr< ResourceType > loadReference (const SdlInputClause &clause, const SdlInputContext &ctx)
 
template<typename ResourceType = T>
static std::shared_ptr< ResourceType > loadReference (std::string_view referenceName, const SdlInputContext &ctx)
 

Protected Member Functions

void loadFromSdl (Owner &owner, const SdlInputClause &clause, const SdlInputContext &ctx) const override
 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
 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.
 
- 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::TSdlReference< T, Owner >

A value that points to a SDL resource.

Template Parameters
TType of the referenced SDL resource.
OwnerOwner type of T. Note that Owner can be any type (not necessarily a SDL resource).

Constructor & Destructor Documentation

◆ TSdlReference()

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

Member Function Documentation

◆ description()

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

◆ getValueRef()

template<typename T , typename Owner >
const std::shared_ptr< T > & ph::TSdlReference< T, Owner >::getValueRef ( const Owner & owner) const
inline

◆ loadFromSdl()

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

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::TSdlOwnedField< Owner >.

◆ loadReference() [1/2]

template<typename T , typename Owner >
template<typename ResourceType >
std::shared_ptr< ResourceType > ph::TSdlReference< T, Owner >::loadReference ( const SdlInputClause & clause,
const SdlInputContext & ctx )
inlinestatic

◆ loadReference() [2/2]

template<typename T , typename Owner >
template<typename ResourceType >
std::shared_ptr< ResourceType > ph::TSdlReference< T, Owner >::loadReference ( std::string_view referenceName,
const SdlInputContext & ctx )
inlinestatic

◆ niceToHave()

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

◆ optional()

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

◆ ownedNativeData()

template<typename T , typename Owner >
SdlNativeData ph::TSdlReference< T, Owner >::ownedNativeData ( Owner & owner) const
inlineoverridevirtual

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.

Implements ph::TSdlOwnedField< Owner >.

◆ ownedResources()

template<typename T , typename Owner >
void ph::TSdlReference< T, Owner >::ownedResources ( const Owner & owner,
std::vector< const ISdlResource * > & out_resources ) const
inlineoverridevirtual

Get all SDL resources associated by owner.

Parameters
ownerOwner instance in question.
out_resourcesSDL resources associated with this field by the owner. Never contains null. Appends to existing ones.

Implements ph::TSdlOwnedField< Owner >.

◆ ownedValueToDefault()

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

By default, default value of a SDL reference is empty.

Implements ph::TSdlOwnedField< Owner >.

◆ required()

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

◆ saveToSdl()

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

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::TSdlOwnedField< Owner >.

◆ setValueRef()

template<typename T , typename Owner >
void ph::TSdlReference< T, Owner >::setValueRef ( Owner & owner,
std::shared_ptr< T > value ) const
inline

◆ valueToString()

template<typename T , typename Owner >
std::string ph::TSdlReference< T, Owner >::valueToString ( const Owner & owner) const
inlineoverridevirtual

Convert the value of the field to human-readable string.

Implements ph::TSdlOwnedField< Owner >.

◆ withImportance()

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

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