SafeUnion

Constructs a SafeUnion wrapping the specified union type

Enables access of the stored value through the field names of the wrapped union.

Members

Aliases

FieldTypes
alias FieldTypes = staticMap!(extractType, fieldSpecs)
Undocumented in source.
extractName
alias extractName(alias spec) = spec.name
Undocumented in source.
extractType
alias extractType(alias spec) = spec.Type
Undocumented in source.
fieldNames
alias fieldNames = staticMap!(extractName, fieldSpecs)
Undocumented in source.
fieldSpecs
alias fieldSpecs = parseSpecs!(FieldTypeTuple!U, FieldNameTuple!U)
Undocumented in source.

Structs

SafeUnion
struct SafeUnion
Undocumented in source.

Templates

FieldSpec
template FieldSpec(T, string s)
Undocumented in source.
parseSpecs
template parseSpecs(Specs...)
Undocumented in source.

Examples

import capstone.api;
import capstone.x86;

auto cs = new CapstoneX86(ModeFlags(Mode.bit32));
auto x86reg = new X86Register(cs, X86RegisterId.eip);

SafeUnion!X86OpValue safeVal;
assertThrown(safeVal.imm);    	   // Not initialised
safeVal.reg = x86reg;
assertThrown(safeVal.imm);    	   // cannot access the `long` since a `X86Register` is currently stored
safeVal.imm = 42;
assertNotThrown(safeVal.imm);      // can access the `long` now

// Corresponding operations on a regular union go unnoticed
X86OpValue unsafeVal;
unsafeVal.reg = x86reg;
assertNotThrown(unsafeVal.imm);

Meta