import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'string.dart'; Pointer> optional_struct(T s) { if (s == null) { return Pointer>.fromAddress(0); } else { Pointer> opt = allocate(count: 1); opt.value = s.addressOf; return opt; } } Pointer> optional_String(String s) { if (s == null) { return Pointer>.fromAddress(0); } else { Pointer> opt = allocate(count: 1); opt.value = stringToCString(s); return opt; } } Pointer optional_bool(bool b) { if (b == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); if (b) { opt.value = 1; } else { opt.value = 0; } return opt; } } Pointer optional_char(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_duration(Duration b) { if (b == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = b.inMilliseconds; return opt; } } Pointer optional_f32(double d) { if (d == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = d; return opt; } } Pointer optional_f64(double d) { if (d == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = d; return opt; } } Pointer optional_u8(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_u16(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_u32(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_u64(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_i8(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_i16(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_i32(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } } Pointer optional_i64(int i) { if (i == null) { return Pointer.fromAddress(0); } else { Pointer opt = allocate(count: 1); opt.value = i; return opt; } }