目录

OH_AbilityRuntime_ModObjDispatcher_Variant

typedef struct {...} OH_AbilityRuntime_ModObjDispatcher_Variant

Overview

Defines a variant struct that uses a union with a type tag to distinguish the actual data type, for safely passing values of multiple types during parameter passing and return value receiving.

The value of a variant is determined by the vt field, which specifies the actual stored data type and the valid member of the union.

When a variant holds heap-allocated resources (such as strings and container handles), call OH_AbilityRuntime_ModObjDispatcher_VariantClear to release them.

Simple types (boolean, integer, and floating-point) do not hold heap resources and do not need to be released by calling OH_AbilityRuntime_ModObjDispatcher_VariantClear.

Do not call OH_AbilityRuntime_ModObjDispatcher_VariantClear on a shallow copy of the variant. If Variant v2 = v1 is executed, only one of them can be cleared.

Since: 26.0.0

Related module: AbilityRuntime

File to include: modular_object_dispatcher.h

Summary

[h2]Member Variables

Name Description
OH_AbilityRuntime_ModObjDispatcher_ValueType vt

Type tag of the variant, which determines the valid member in the union.

Since: 26.0.0

uint64_t reserved1

Reserved field 1. Reserved for future version extension. The caller should initialize it to 0 and should not read or modify it.

Since: 26.0.0

uint64_t reserved2

Reserved field 2. Reserved for future version extension. The caller should initialize it to 0 and should not read or modify it.

Since: 26.0.0

uint64_t reserved3

Reserved field 3. Reserved for future version extension. The caller should initialize it to 0 and should not read or modify it.

Since: 26.0.0

union {

void* pvoidVal;

bool boolVal;

int8_t i8Val;

int16_t i16Val;

int32_t i32Val;

int64_t i64Val;

uint8_t u8Val;

uint16_t u16Val;

uint32_t u32Val;

uint64_t u64Val;

float f32Val;

double f64Val;

int32_t enumVal;

char* bstrVal;

OH_AbilityRuntime_ModObjDispatcher_ArrayHandle parrayVal;

OH_AbilityRuntime_ModObjDispatcher_VectorHandle pvectorVal;

OH_AbilityRuntime_ModObjDispatcher_SetHandle psetVal;

OH_AbilityRuntime_ModObjDispatcher_MapHandle pmapVal;

OH_AbilityRuntime_ModObjDispatcher_StructHandle pstructVal;

OHIPCRemoteProxy* premoteProxyVal;

OHIPCRemoteStub* premoteStubVal;

} u

Union of the variant value data. The valid member is determined by vt.

pvoidVal: void pointer.

boolVal: boolean value.

i8Val: 8-bit signed integer.

i16Val: 16-bit signed integer.

i32Val: 32-bit signed integer.

i64Val: 64-bit signed integer.

u8Val: 8-bit unsigned integer.

u16Val: 16-bit unsigned integer.

u32Val: 32-bit unsigned integer.

u64Val: 64-bit unsigned integer.

f32Val: 32-bit floating-point number (single precision).

f64Val: 64-bit floating-point number (double precision).

enumVal: enum value, stored as int32_t.

bstrVal: UTF-8 string handle, pointing to a heap-allocated string.

parrayVal: array handle.

pvectorVal: vector handle.

psetVal: set handle.

pmapVal: map handle.

pstructVal: struct handle.

premoteProxyVal: remote Proxy object handle.

premoteStubVal: remote Stub object handle.

Since: 26.0.0