Shaka Player Embedded
Public Member Functions | Protected Member Functions | List of all members
shaka::Struct Class Reference

#include <struct.h>

Inheritance diagram for shaka::Struct:
shaka::GenericConverter shaka::memory::Traceable shaka::js::BufferedInfo shaka::js::BufferedRange shaka::js::DrmInfo shaka::js::eme::MediaKeySystemConfiguration shaka::js::eme::MediaKeySystemMediaCapability shaka::js::events::IDBVersionChangeEventInit shaka::js::events::MediaEncryptedEventInit shaka::js::events::MediaKeyMessageEventInit shaka::js::idb::IDBObjectStoreParameters shaka::js::InitDataOverride shaka::js::LanguageRole shaka::js::mse::VideoPlaybackQuality shaka::js::Request shaka::js::Response shaka::js::StateChange shaka::js::Stats shaka::js::StoredContent shaka::js::TestTypeOptions shaka::js::Track shaka::js::TrackChoice

Public Member Functions

 Struct ()
 
 ~Struct () override
 
 Struct (const Struct &)
 
 Struct (Struct &&)
 
Structoperator= (const Struct &)
 
Structoperator= (Struct &&)
 
bool TryConvert (Handle< JsValue > value) override
 
ReturnVal< JsValue > ToJsValue () const override
 
void Trace (memory::HeapTracer *tracer) const override
 
- Public Member Functions inherited from shaka::GenericConverter
virtual ~GenericConverter ()
 
- Public Member Functions inherited from shaka::memory::Traceable
virtual ~Traceable ()
 
virtual bool IsRootedAlive () const
 
virtual bool IsShortLived () const
 

Protected Member Functions

template<typename Parent , typename Field >
Field CreateFieldConverter (const std::string &name, Field Parent::*field)
 

Additional Inherited Members

- Static Public Attributes inherited from shaka::memory::Traceable
static constexpr const uint64_t kShortLiveDurationMs = 5000
 

Detailed Description

Defines the base class for struct objects. These are JavaScript objects that have specific members. Passing in any JavaScript object is valid and the respective members will be converted. Any extra members will not be copied.

This is a forgiving type, namely it will try to convert each field if possible. If it is not possible, the field will be the default. However, if the argument is not an object, it is invalid. This is non-nullable, so to accept null, use optional<Struct>.

In addition to deriving from this type, a Struct must also have a static |name| method. This is similar to BackingObjects, but you should NOT use DECLARE_TYPE_INFO. It is required to have a default (argument-less) constructor which can be implicit or user defined. If it is defined you CANNOT have member initialization (field assignments before the '{'), you MUST use assignment within the constructor body, otherwise the field will not be registered (see the macro above).

This stores the original JavaScript object this came from. ToJsValue will return that if this came from JavaScript; otherwise this creates a new JavaScript object to return. Any fields that are changed in C++ will be updated when returned back to JavaScript.

Definition at line 166 of file struct.h.

Constructor & Destructor Documentation

§ Struct() [1/3]

shaka::Struct::Struct ( )

Definition at line 21 of file struct.cc.

§ ~Struct()

shaka::Struct::~Struct ( )
override

Definition at line 22 of file struct.cc.

§ Struct() [2/3]

shaka::Struct::Struct ( const Struct )
default

§ Struct() [3/3]

shaka::Struct::Struct ( Struct &&  )
default

Member Function Documentation

§ CreateFieldConverter()

template<typename Parent , typename Field >
Field shaka::Struct::CreateFieldConverter ( const std::string &  name,
Field Parent::*  field 
)
inlineprotected

Definition at line 184 of file struct.h.

§ operator=() [1/2]

Struct & shaka::Struct::operator= ( const Struct )
default

§ operator=() [2/2]

Struct & shaka::Struct::operator= ( Struct &&  )
default

§ ToJsValue()

ReturnVal< JsValue > shaka::Struct::ToJsValue ( ) const
overridevirtual

Converts the current value into a JavaScript value.

Implements shaka::GenericConverter.

Definition at line 40 of file struct.cc.

§ Trace()

void shaka::Struct::Trace ( memory::HeapTracer tracer) const
overridevirtual

Called during a GC run. This should call HeapTracer::Trace on all Traceable members. Be sure to call the base method when overriding.

Implements shaka::memory::Traceable.

Definition at line 49 of file struct.cc.

§ TryConvert()

bool shaka::Struct::TryConvert ( Handle< JsValue >  value)
overridevirtual

Tries to convert the given value into the required type, populating the members of this object as needed.

Returns
True on success, false on error.

Implements shaka::GenericConverter.

Definition at line 29 of file struct.cc.


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