[C++] Fix compile failure on Object API union construction for struct member (#6923)

* Add dedicated traits to Object API version of unions.

* Add suppression for unused parameters on unions of structs.
This commit is contained in:
Taiju Tsuiki
2021-11-19 03:55:11 +09:00
committed by GitHub
parent a9c341545f
commit 587bbd49a7
29 changed files with 1990 additions and 17 deletions

View File

@@ -0,0 +1,49 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
using global::System;
using global::System.Collections.Generic;
using global::FlatBuffers;
public struct FallingTub : IFlatbufferObject
{
private Struct __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); }
public FallingTub __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public int Weight { get { return __p.bb.GetInt(__p.bb_pos + 0); } }
public void MutateWeight(int weight) { __p.bb.PutInt(__p.bb_pos + 0, weight); }
public static Offset<FallingTub> CreateFallingTub(FlatBufferBuilder builder, int Weight) {
builder.Prep(4, 4);
builder.PutInt(Weight);
return new Offset<FallingTub>(builder.Offset);
}
public FallingTubT UnPack() {
var _o = new FallingTubT();
this.UnPackTo(_o);
return _o;
}
public void UnPackTo(FallingTubT _o) {
_o.Weight = this.Weight;
}
public static Offset<FallingTub> Pack(FlatBufferBuilder builder, FallingTubT _o) {
if (_o == null) return default(Offset<FallingTub>);
return CreateFallingTub(
builder,
_o.Weight);
}
}
public class FallingTubT
{
[Newtonsoft.Json.JsonProperty("weight")]
public int Weight { get; set; }
public FallingTubT() {
this.Weight = 0;
}
}

View File

@@ -0,0 +1,44 @@
// automatically generated by the FlatBuffers compiler, do not modify
import java.nio.*;
import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
@SuppressWarnings("unused")
public final class FallingTub extends Struct {
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
public FallingTub __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public int weight() { return bb.getInt(bb_pos + 0); }
public void mutateWeight(int weight) { bb.putInt(bb_pos + 0, weight); }
public static int createFallingTub(FlatBufferBuilder builder, int weight) {
builder.prep(4, 4);
builder.putInt(weight);
return builder.offset();
}
public static final class Vector extends BaseVector {
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
public FallingTub get(int j) { return get(new FallingTub(), j); }
public FallingTub get(FallingTub obj, int j) { return obj.__assign(__element(j), bb); }
}
public FallingTubT unpack() {
FallingTubT _o = new FallingTubT();
unpackTo(_o);
return _o;
}
public void unpackTo(FallingTubT _o) {
int _oWeight = weight();
_o.setWeight(_oWeight);
}
public static int pack(FlatBufferBuilder builder, FallingTubT _o) {
if (_o == null) return 0;
return createFallingTub(
builder,
_o.getWeight());
}
}

View File

@@ -0,0 +1,27 @@
// automatically generated by the FlatBuffers compiler, do not modify
import java.nio.*
import kotlin.math.sign
import com.google.flatbuffers.*
@Suppress("unused")
@ExperimentalUnsignedTypes
class FallingTub : Struct() {
fun __init(_i: Int, _bb: ByteBuffer) {
__reset(_i, _bb)
}
fun __assign(_i: Int, _bb: ByteBuffer) : FallingTub {
__init(_i, _bb)
return this
}
val weight : Int get() = bb.getInt(bb_pos + 0)
fun mutateWeight(weight: Int) : ByteBuffer = bb.putInt(bb_pos + 0, weight)
companion object {
fun createFallingTub(builder: FlatBufferBuilder, weight: Int) : Int {
builder.prep(4, 4)
builder.putInt(weight)
return builder.offset()
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
// automatically generated by the FlatBuffers compiler, do not modify
use \Google\FlatBuffers\Struct;
use \Google\FlatBuffers\Table;
use \Google\FlatBuffers\ByteBuffer;
use \Google\FlatBuffers\FlatBufferBuilder;
class FallingTub extends Struct
{
/**
* @param int $_i offset
* @param ByteBuffer $_bb
* @return FallingTub
**/
public function init($_i, ByteBuffer $_bb)
{
$this->bb_pos = $_i;
$this->bb = $_bb;
return $this;
}
/**
* @return int
*/
public function GetWeight()
{
return $this->bb->getInt($this->bb_pos + 0);
}
/**
* @return int offset
*/
public static function createFallingTub(FlatBufferBuilder $builder, $weight)
{
$builder->prep(4, 4);
$builder->putInt($weight);
return $builder->offset();
}
}

View File

@@ -0,0 +1,20 @@
// automatically generated by the FlatBuffers compiler, do not modify
import java.nio.*;
import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
public class FallingTubT {
private int weight;
public int getWeight() { return weight; }
public void setWeight(int weight) { this.weight = weight; }
public FallingTubT() {
this.weight = 0;
}
}

View File

@@ -0,0 +1,78 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public enum Gadget : byte
{
NONE = 0,
FallingTub = 1,
HandFan = 2,
};
public class GadgetUnion {
public Gadget Type { get; set; }
public object Value { get; set; }
public GadgetUnion() {
this.Type = Gadget.NONE;
this.Value = null;
}
public T As<T>() where T : class { return this.Value as T; }
public FallingTubT AsFallingTub() { return this.As<FallingTubT>(); }
public static GadgetUnion FromFallingTub(FallingTubT _fallingtub) { return new GadgetUnion{ Type = Gadget.FallingTub, Value = _fallingtub }; }
public HandFanT AsHandFan() { return this.As<HandFanT>(); }
public static GadgetUnion FromHandFan(HandFanT _handfan) { return new GadgetUnion{ Type = Gadget.HandFan, Value = _handfan }; }
public static int Pack(FlatBuffers.FlatBufferBuilder builder, GadgetUnion _o) {
switch (_o.Type) {
default: return 0;
case Gadget.FallingTub: return FallingTub.Pack(builder, _o.AsFallingTub()).Value;
case Gadget.HandFan: return HandFan.Pack(builder, _o.AsHandFan()).Value;
}
}
}
public class GadgetUnion_JsonConverter : Newtonsoft.Json.JsonConverter {
public override bool CanConvert(System.Type objectType) {
return objectType == typeof(GadgetUnion) || objectType == typeof(System.Collections.Generic.List<GadgetUnion>);
}
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
var _olist = value as System.Collections.Generic.List<GadgetUnion>;
if (_olist != null) {
writer.WriteStartArray();
foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); }
writer.WriteEndArray();
} else {
this.WriteJson(writer, value as GadgetUnion, serializer);
}
}
public void WriteJson(Newtonsoft.Json.JsonWriter writer, GadgetUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
if (_o == null) return;
serializer.Serialize(writer, _o.Value);
}
public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) {
var _olist = existingValue as System.Collections.Generic.List<GadgetUnion>;
if (_olist != null) {
for (var _j = 0; _j < _olist.Count; ++_j) {
reader.Read();
_olist[_j] = this.ReadJson(reader, _olist[_j], serializer);
}
reader.Read();
return _olist;
} else {
return this.ReadJson(reader, existingValue as GadgetUnion, serializer);
}
}
public GadgetUnion ReadJson(Newtonsoft.Json.JsonReader reader, GadgetUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
if (_o == null) return null;
switch (_o.Type) {
default: break;
case Gadget.FallingTub: _o.Value = serializer.Deserialize<FallingTubT>(reader); break;
case Gadget.HandFan: _o.Value = serializer.Deserialize<HandFanT>(reader); break;
}
return _o;
}
}

View File

@@ -0,0 +1,14 @@
// automatically generated by the FlatBuffers compiler, do not modify
@SuppressWarnings("unused")
public final class Gadget {
private Gadget() { }
public static final byte NONE = 0;
public static final byte FallingTub = 1;
public static final byte HandFan = 2;
public static final String[] names = { "NONE", "FallingTub", "HandFan", };
public static String name(int e) { return names[e]; }
}

View File

@@ -0,0 +1,13 @@
// automatically generated by the FlatBuffers compiler, do not modify
@Suppress("unused")
@ExperimentalUnsignedTypes
class Gadget private constructor() {
companion object {
const val NONE: UByte = 0u
const val FallingTub: UByte = 1u
const val HandFan: UByte = 2u
val names : Array<String> = arrayOf("NONE", "FallingTub", "HandFan")
fun name(e: Int) : String = names[e]
}
}

View File

@@ -0,0 +1,23 @@
<?php
// automatically generated by the FlatBuffers compiler, do not modify
class Gadget
{
const NONE = 0;
const FallingTub = 1;
const HandFan = 2;
private static $names = array(
Gadget::NONE=>"NONE",
Gadget::FallingTub=>"FallingTub",
Gadget::HandFan=>"HandFan",
);
public static function Name($e)
{
if (!isset(self::$names[$e])) {
throw new \Exception();
}
return self::$names[$e];
}
}

View File

@@ -0,0 +1,33 @@
// automatically generated by the FlatBuffers compiler, do not modify
import com.google.flatbuffers.FlatBufferBuilder;
public class GadgetUnion {
private byte type;
private Object value;
public byte getType() { return type; }
public void setType(byte type) { this.type = type; }
public Object getValue() { return value; }
public void setValue(Object value) { this.value = value; }
public GadgetUnion() {
this.type = Gadget.NONE;
this.value = null;
}
public FallingTubT asFallingTub() { return (FallingTubT) value; }
public HandFanT asHandFan() { return (HandFanT) value; }
public static int pack(FlatBufferBuilder builder, GadgetUnion _o) {
switch (_o.type) {
case Gadget.FallingTub: return FallingTub.pack(builder, _o.asFallingTub());
case Gadget.HandFan: return HandFan.pack(builder, _o.asHandFan());
default: return 0;
}
}
}

View File

@@ -0,0 +1,60 @@
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
using global::System;
using global::System.Collections.Generic;
using global::FlatBuffers;
public struct HandFan : IFlatbufferObject
{
private Table __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_2_0_0(); }
public static HandFan GetRootAsHandFan(ByteBuffer _bb) { return GetRootAsHandFan(_bb, new HandFan()); }
public static HandFan GetRootAsHandFan(ByteBuffer _bb, HandFan obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
public HandFan __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public int Length { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetInt(o + __p.bb_pos) : (int)0; } }
public bool MutateLength(int length) { int o = __p.__offset(4); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, length); return true; } else { return false; } }
public static Offset<HandFan> CreateHandFan(FlatBufferBuilder builder,
int length = 0) {
builder.StartTable(1);
HandFan.AddLength(builder, length);
return HandFan.EndHandFan(builder);
}
public static void StartHandFan(FlatBufferBuilder builder) { builder.StartTable(1); }
public static void AddLength(FlatBufferBuilder builder, int length) { builder.AddInt(0, length, 0); }
public static Offset<HandFan> EndHandFan(FlatBufferBuilder builder) {
int o = builder.EndTable();
return new Offset<HandFan>(o);
}
public HandFanT UnPack() {
var _o = new HandFanT();
this.UnPackTo(_o);
return _o;
}
public void UnPackTo(HandFanT _o) {
_o.Length = this.Length;
}
public static Offset<HandFan> Pack(FlatBufferBuilder builder, HandFanT _o) {
if (_o == null) return default(Offset<HandFan>);
return CreateHandFan(
builder,
_o.Length);
}
}
public class HandFanT
{
[Newtonsoft.Json.JsonProperty("length")]
public int Length { get; set; }
public HandFanT() {
this.Length = 0;
}
}

View File

@@ -0,0 +1,55 @@
// automatically generated by the FlatBuffers compiler, do not modify
import java.nio.*;
import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
@SuppressWarnings("unused")
public final class HandFan extends Table {
public static void ValidateVersion() { Constants.FLATBUFFERS_2_0_0(); }
public static HandFan getRootAsHandFan(ByteBuffer _bb) { return getRootAsHandFan(_bb, new HandFan()); }
public static HandFan getRootAsHandFan(ByteBuffer _bb, HandFan obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
public HandFan __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public int length() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public boolean mutateLength(int length) { int o = __offset(4); if (o != 0) { bb.putInt(o + bb_pos, length); return true; } else { return false; } }
public static int createHandFan(FlatBufferBuilder builder,
int length) {
builder.startTable(1);
HandFan.addLength(builder, length);
return HandFan.endHandFan(builder);
}
public static void startHandFan(FlatBufferBuilder builder) { builder.startTable(1); }
public static void addLength(FlatBufferBuilder builder, int length) { builder.addInt(0, length, 0); }
public static int endHandFan(FlatBufferBuilder builder) {
int o = builder.endTable();
return o;
}
public static final class Vector extends BaseVector {
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
public HandFan get(int j) { return get(new HandFan(), j); }
public HandFan get(HandFan obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
}
public HandFanT unpack() {
HandFanT _o = new HandFanT();
unpackTo(_o);
return _o;
}
public void unpackTo(HandFanT _o) {
int _oLength = length();
_o.setLength(_oLength);
}
public static int pack(FlatBufferBuilder builder, HandFanT _o) {
if (_o == null) return 0;
return createHandFan(
builder,
_o.getLength());
}
}

View File

@@ -0,0 +1,51 @@
// automatically generated by the FlatBuffers compiler, do not modify
import java.nio.*
import kotlin.math.sign
import com.google.flatbuffers.*
@Suppress("unused")
@ExperimentalUnsignedTypes
class HandFan : Table() {
fun __init(_i: Int, _bb: ByteBuffer) {
__reset(_i, _bb)
}
fun __assign(_i: Int, _bb: ByteBuffer) : HandFan {
__init(_i, _bb)
return this
}
val length : Int
get() {
val o = __offset(4)
return if(o != 0) bb.getInt(o + bb_pos) else 0
}
fun mutateLength(length: Int) : Boolean {
val o = __offset(4)
return if (o != 0) {
bb.putInt(o + bb_pos, length)
true
} else {
false
}
}
companion object {
fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
fun getRootAsHandFan(_bb: ByteBuffer): HandFan = getRootAsHandFan(_bb, HandFan())
fun getRootAsHandFan(_bb: ByteBuffer, obj: HandFan): HandFan {
_bb.order(ByteOrder.LITTLE_ENDIAN)
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
}
fun createHandFan(builder: FlatBufferBuilder, length: Int) : Int {
builder.startTable(1)
addLength(builder, length)
return endHandFan(builder)
}
fun startHandFan(builder: FlatBufferBuilder) = builder.startTable(1)
fun addLength(builder: FlatBufferBuilder, length: Int) = builder.addInt(0, length, 0)
fun endHandFan(builder: FlatBufferBuilder) : Int {
val o = builder.endTable()
return o
}
}
}

View File

@@ -0,0 +1,92 @@
<?php
// automatically generated by the FlatBuffers compiler, do not modify
use \Google\FlatBuffers\Struct;
use \Google\FlatBuffers\Table;
use \Google\FlatBuffers\ByteBuffer;
use \Google\FlatBuffers\FlatBufferBuilder;
class HandFan extends Table
{
/**
* @param ByteBuffer $bb
* @return HandFan
*/
public static function getRootAsHandFan(ByteBuffer $bb)
{
$obj = new HandFan();
return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
}
public static function HandFanIdentifier()
{
return "MOVI";
}
public static function HandFanBufferHasIdentifier(ByteBuffer $buf)
{
return self::__has_identifier($buf, self::HandFanIdentifier());
}
/**
* @param int $_i offset
* @param ByteBuffer $_bb
* @return HandFan
**/
public function init($_i, ByteBuffer $_bb)
{
$this->bb_pos = $_i;
$this->bb = $_bb;
return $this;
}
/**
* @return int
*/
public function getLength()
{
$o = $this->__offset(4);
return $o != 0 ? $this->bb->getInt($o + $this->bb_pos) : 0;
}
/**
* @param FlatBufferBuilder $builder
* @return void
*/
public static function startHandFan(FlatBufferBuilder $builder)
{
$builder->StartObject(1);
}
/**
* @param FlatBufferBuilder $builder
* @return HandFan
*/
public static function createHandFan(FlatBufferBuilder $builder, $length)
{
$builder->startObject(1);
self::addLength($builder, $length);
$o = $builder->endObject();
return $o;
}
/**
* @param FlatBufferBuilder $builder
* @param int
* @return void
*/
public static function addLength(FlatBufferBuilder $builder, $length)
{
$builder->addIntX(0, $length, 0);
}
/**
* @param FlatBufferBuilder $builder
* @return int table offset
*/
public static function endHandFan(FlatBufferBuilder $builder)
{
$o = $builder->endObject();
return $o;
}
}

View File

@@ -0,0 +1,20 @@
// automatically generated by the FlatBuffers compiler, do not modify
import java.nio.*;
import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
public class HandFanT {
private int length;
public int getLength() { return length; }
public void setLength(int length) { this.length = length; }
public HandFanT() {
this.length = 0;
}
}

View File

@@ -0,0 +1,63 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class FallingTub {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):FallingTub {
this.bb_pos = i;
this.bb = bb;
return this;
}
weight():number {
return this.bb!.readInt32(this.bb_pos);
}
mutate_weight(value:number):boolean {
this.bb!.writeInt32(this.bb_pos + 0, value);
return true;
}
static getFullyQualifiedName():string {
return 'FallingTub';
}
static sizeOf():number {
return 4;
}
static createFallingTub(builder:flatbuffers.Builder, weight: number):flatbuffers.Offset {
builder.prep(4, 4);
builder.writeInt32(weight);
return builder.offset();
}
unpack(): FallingTubT {
return new FallingTubT(
this.weight()
);
}
unpackTo(_o: FallingTubT): void {
_o.weight = this.weight();
}
}
export class FallingTubT {
constructor(
public weight: number = 0
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return FallingTub.createFallingTub(builder,
this.weight
);
}
}

View File

@@ -0,0 +1,37 @@
// automatically generated by the FlatBuffers compiler, do not modify
import { FallingTub, FallingTubT } from './falling-tub';
import { HandFan, HandFanT } from './hand-fan';
export enum Gadget{
NONE = 0,
FallingTub = 1,
HandFan = 2
}
export function unionToGadget(
type: Gadget,
accessor: (obj:FallingTub|HandFan) => FallingTub|HandFan|null
): FallingTub|HandFan|null {
switch(Gadget[type]) {
case 'NONE': return null;
case 'FallingTub': return accessor(new FallingTub())! as FallingTub;
case 'HandFan': return accessor(new HandFan())! as HandFan;
default: return null;
}
}
export function unionListToGadget(
type: Gadget,
accessor: (index: number, obj:FallingTub|HandFan) => FallingTub|HandFan|null,
index: number
): FallingTub|HandFan|null {
switch(Gadget[type]) {
case 'NONE': return null;
case 'FallingTub': return accessor(index, new FallingTub())! as FallingTub;
case 'HandFan': return accessor(index, new HandFan())! as HandFan;
default: return null;
}
}

View File

@@ -0,0 +1,87 @@
// automatically generated by the FlatBuffers compiler, do not modify
import * as flatbuffers from 'flatbuffers';
export class HandFan {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
__init(i:number, bb:flatbuffers.ByteBuffer):HandFan {
this.bb_pos = i;
this.bb = bb;
return this;
}
static getRootAsHandFan(bb:flatbuffers.ByteBuffer, obj?:HandFan):HandFan {
return (obj || new HandFan()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
static getSizePrefixedRootAsHandFan(bb:flatbuffers.ByteBuffer, obj?:HandFan):HandFan {
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
return (obj || new HandFan()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}
length():number {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
}
mutate_length(value:number):boolean {
const offset = this.bb!.__offset(this.bb_pos, 4);
if (offset === 0) {
return false;
}
this.bb!.writeInt32(this.bb_pos + offset, value);
return true;
}
static getFullyQualifiedName():string {
return 'HandFan';
}
static startHandFan(builder:flatbuffers.Builder) {
builder.startObject(1);
}
static addLength(builder:flatbuffers.Builder, length:number) {
builder.addFieldInt32(0, length, 0);
}
static endHandFan(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}
static createHandFan(builder:flatbuffers.Builder, length:number):flatbuffers.Offset {
HandFan.startHandFan(builder);
HandFan.addLength(builder, length);
return HandFan.endHandFan(builder);
}
unpack(): HandFanT {
return new HandFanT(
this.length()
);
}
unpackTo(_o: HandFanT): void {
_o.length = this.length();
}
}
export class HandFanT {
constructor(
public length: number = 0
){}
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
return HandFan.createHandFan(builder,
this.length
);
}
}

View File

@@ -22,6 +22,19 @@ union Character {
Unused: string
}
struct FallingTub {
weight: int;
}
table HandFan {
length: int;
}
union Gadget {
FallingTub,
HandFan,
}
table Movie {
main_character: Character;
characters: [Character];

View File

@@ -1,5 +1,8 @@
export { Attacker, AttackerT } from './attacker';
export { BookReader, BookReaderT } from './book-reader';
export { Character, unionToCharacter, unionListToCharacter } from './character';
export { FallingTub, FallingTubT } from './falling-tub';
export { Gadget, unionToGadget, unionListToGadget } from './gadget';
export { HandFan, HandFanT } from './hand-fan';
export { Movie, MovieT } from './movie';
export { Rapunzel, RapunzelT } from './rapunzel';

View File

@@ -14,6 +14,12 @@ struct Rapunzel;
struct BookReader;
struct FallingTub;
struct HandFan;
struct HandFanBuilder;
struct HandFanT;
struct Movie;
struct MovieBuilder;
struct MovieT;
@@ -24,6 +30,10 @@ bool operator==(const Rapunzel &lhs, const Rapunzel &rhs);
bool operator!=(const Rapunzel &lhs, const Rapunzel &rhs);
bool operator==(const BookReader &lhs, const BookReader &rhs);
bool operator!=(const BookReader &lhs, const BookReader &rhs);
bool operator==(const FallingTub &lhs, const FallingTub &rhs);
bool operator!=(const FallingTub &lhs, const FallingTub &rhs);
bool operator==(const HandFanT &lhs, const HandFanT &rhs);
bool operator!=(const HandFanT &lhs, const HandFanT &rhs);
bool operator==(const MovieT &lhs, const MovieT &rhs);
bool operator!=(const MovieT &lhs, const MovieT &rhs);
@@ -33,6 +43,10 @@ inline const flatbuffers::TypeTable *RapunzelTypeTable();
inline const flatbuffers::TypeTable *BookReaderTypeTable();
inline const flatbuffers::TypeTable *FallingTubTypeTable();
inline const flatbuffers::TypeTable *HandFanTypeTable();
inline const flatbuffers::TypeTable *MovieTypeTable();
enum Character : uint8_t {
@@ -194,6 +208,139 @@ inline bool operator!=(const CharacterUnion &lhs, const CharacterUnion &rhs) {
bool VerifyCharacter(flatbuffers::Verifier &verifier, const void *obj, Character type);
bool VerifyCharacterVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
enum Gadget : uint8_t {
Gadget_NONE = 0,
Gadget_FallingTub = 1,
Gadget_HandFan = 2,
Gadget_MIN = Gadget_NONE,
Gadget_MAX = Gadget_HandFan
};
inline const Gadget (&EnumValuesGadget())[3] {
static const Gadget values[] = {
Gadget_NONE,
Gadget_FallingTub,
Gadget_HandFan
};
return values;
}
inline const char * const *EnumNamesGadget() {
static const char * const names[4] = {
"NONE",
"FallingTub",
"HandFan",
nullptr
};
return names;
}
inline const char *EnumNameGadget(Gadget e) {
if (flatbuffers::IsOutRange(e, Gadget_NONE, Gadget_HandFan)) return "";
const size_t index = static_cast<size_t>(e);
return EnumNamesGadget()[index];
}
template<typename T> struct GadgetTraits {
static const Gadget enum_value = Gadget_NONE;
};
template<> struct GadgetTraits<FallingTub> {
static const Gadget enum_value = Gadget_FallingTub;
};
template<> struct GadgetTraits<HandFan> {
static const Gadget enum_value = Gadget_HandFan;
};
template<typename T> struct GadgetUnionTraits {
static const Gadget enum_value = Gadget_NONE;
};
template<> struct GadgetUnionTraits<FallingTub> {
static const Gadget enum_value = Gadget_FallingTub;
};
template<> struct GadgetUnionTraits<HandFanT> {
static const Gadget enum_value = Gadget_HandFan;
};
struct GadgetUnion {
Gadget type;
void *value;
GadgetUnion() : type(Gadget_NONE), value(nullptr) {}
GadgetUnion(GadgetUnion&& u) FLATBUFFERS_NOEXCEPT :
type(Gadget_NONE), value(nullptr)
{ std::swap(type, u.type); std::swap(value, u.value); }
GadgetUnion(const GadgetUnion &);
GadgetUnion &operator=(const GadgetUnion &u)
{ GadgetUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; }
GadgetUnion &operator=(GadgetUnion &&u) FLATBUFFERS_NOEXCEPT
{ std::swap(type, u.type); std::swap(value, u.value); return *this; }
~GadgetUnion() { Reset(); }
void Reset();
template <typename T>
void Set(T&& val) {
typedef typename std::remove_reference<T>::type RT;
Reset();
type = GadgetUnionTraits<RT>::enum_value;
if (type != Gadget_NONE) {
value = new RT(std::forward<T>(val));
}
}
static void *UnPack(const void *obj, Gadget type, const flatbuffers::resolver_function_t *resolver);
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
FallingTub *AsFallingTub() {
return type == Gadget_FallingTub ?
reinterpret_cast<FallingTub *>(value) : nullptr;
}
const FallingTub *AsFallingTub() const {
return type == Gadget_FallingTub ?
reinterpret_cast<const FallingTub *>(value) : nullptr;
}
HandFanT *AsHandFan() {
return type == Gadget_HandFan ?
reinterpret_cast<HandFanT *>(value) : nullptr;
}
const HandFanT *AsHandFan() const {
return type == Gadget_HandFan ?
reinterpret_cast<const HandFanT *>(value) : nullptr;
}
};
inline bool operator==(const GadgetUnion &lhs, const GadgetUnion &rhs) {
if (lhs.type != rhs.type) return false;
switch (lhs.type) {
case Gadget_NONE: {
return true;
}
case Gadget_FallingTub: {
return *(reinterpret_cast<const FallingTub *>(lhs.value)) ==
*(reinterpret_cast<const FallingTub *>(rhs.value));
}
case Gadget_HandFan: {
return *(reinterpret_cast<const HandFanT *>(lhs.value)) ==
*(reinterpret_cast<const HandFanT *>(rhs.value));
}
default: {
return false;
}
}
}
inline bool operator!=(const GadgetUnion &lhs, const GadgetUnion &rhs) {
return !(lhs == rhs);
}
bool VerifyGadget(flatbuffers::Verifier &verifier, const void *obj, Gadget type);
bool VerifyGadgetVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Rapunzel FLATBUFFERS_FINAL_CLASS {
private:
int32_t hair_length_;
@@ -266,6 +413,42 @@ inline bool operator!=(const BookReader &lhs, const BookReader &rhs) {
}
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) FallingTub FLATBUFFERS_FINAL_CLASS {
private:
int32_t weight_;
public:
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
return FallingTubTypeTable();
}
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
return "FallingTub";
}
FallingTub()
: weight_(0) {
}
FallingTub(int32_t _weight)
: weight_(flatbuffers::EndianScalar(_weight)) {
}
int32_t weight() const {
return flatbuffers::EndianScalar(weight_);
}
void mutate_weight(int32_t _weight) {
flatbuffers::WriteScalar(&weight_, _weight);
}
};
FLATBUFFERS_STRUCT_END(FallingTub, 4);
inline bool operator==(const FallingTub &lhs, const FallingTub &rhs) {
return
(lhs.weight() == rhs.weight());
}
inline bool operator!=(const FallingTub &lhs, const FallingTub &rhs) {
return !(lhs == rhs);
}
struct AttackerT : public flatbuffers::NativeTable {
typedef Attacker TableType;
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
@@ -330,6 +513,70 @@ inline flatbuffers::Offset<Attacker> CreateAttacker(
flatbuffers::Offset<Attacker> CreateAttacker(flatbuffers::FlatBufferBuilder &_fbb, const AttackerT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
struct HandFanT : public flatbuffers::NativeTable {
typedef HandFan TableType;
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
return "HandFanT";
}
int32_t length = 0;
};
struct HandFan FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef HandFanT NativeTableType;
typedef HandFanBuilder Builder;
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
return HandFanTypeTable();
}
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
return "HandFan";
}
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_LENGTH = 4
};
int32_t length() const {
return GetField<int32_t>(VT_LENGTH, 0);
}
bool mutate_length(int32_t _length = 0) {
return SetField<int32_t>(VT_LENGTH, _length, 0);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, VT_LENGTH) &&
verifier.EndTable();
}
HandFanT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
void UnPackTo(HandFanT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
static flatbuffers::Offset<HandFan> Pack(flatbuffers::FlatBufferBuilder &_fbb, const HandFanT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
};
struct HandFanBuilder {
typedef HandFan Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_length(int32_t length) {
fbb_.AddElement<int32_t>(HandFan::VT_LENGTH, length, 0);
}
explicit HandFanBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
flatbuffers::Offset<HandFan> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<HandFan>(end);
return o;
}
};
inline flatbuffers::Offset<HandFan> CreateHandFan(
flatbuffers::FlatBufferBuilder &_fbb,
int32_t length = 0) {
HandFanBuilder builder_(_fbb);
builder_.add_length(length);
return builder_.Finish();
}
flatbuffers::Offset<HandFan> CreateHandFan(flatbuffers::FlatBufferBuilder &_fbb, const HandFanT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
struct MovieT : public flatbuffers::NativeTable {
typedef Movie TableType;
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
@@ -507,6 +754,43 @@ inline flatbuffers::Offset<Attacker> CreateAttacker(flatbuffers::FlatBufferBuild
}
inline bool operator==(const HandFanT &lhs, const HandFanT &rhs) {
return
(lhs.length == rhs.length);
}
inline bool operator!=(const HandFanT &lhs, const HandFanT &rhs) {
return !(lhs == rhs);
}
inline HandFanT *HandFan::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = std::unique_ptr<HandFanT>(new HandFanT());
UnPackTo(_o.get(), _resolver);
return _o.release();
}
inline void HandFan::UnPackTo(HandFanT *_o, const flatbuffers::resolver_function_t *_resolver) const {
(void)_o;
(void)_resolver;
{ auto _e = length(); _o->length = _e; }
}
inline flatbuffers::Offset<HandFan> HandFan::Pack(flatbuffers::FlatBufferBuilder &_fbb, const HandFanT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
return CreateHandFan(_fbb, _o, _rehasher);
}
inline flatbuffers::Offset<HandFan> CreateHandFan(flatbuffers::FlatBufferBuilder &_fbb, const HandFanT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
(void)_rehasher;
(void)_o;
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const HandFanT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
auto _length = _o->length;
return CreateHandFan(
_fbb,
_length);
}
inline bool operator==(const MovieT &lhs, const MovieT &rhs) {
return
(lhs.main_character == rhs.main_character) &&
@@ -596,6 +880,7 @@ inline bool VerifyCharacterVector(flatbuffers::Verifier &verifier, const flatbuf
}
inline void *CharacterUnion::UnPack(const void *obj, Character type, const flatbuffers::resolver_function_t *resolver) {
(void)resolver;
switch (type) {
case Character_MuLan: {
auto ptr = reinterpret_cast<const Attacker *>(obj);
@@ -626,6 +911,7 @@ inline void *CharacterUnion::UnPack(const void *obj, Character type, const flatb
}
inline flatbuffers::Offset<void> CharacterUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const {
(void)_rehasher;
switch (type) {
case Character_MuLan: {
auto ptr = reinterpret_cast<const AttackerT *>(value);
@@ -724,6 +1010,97 @@ inline void CharacterUnion::Reset() {
type = Character_NONE;
}
inline bool VerifyGadget(flatbuffers::Verifier &verifier, const void *obj, Gadget type) {
switch (type) {
case Gadget_NONE: {
return true;
}
case Gadget_FallingTub: {
return verifier.Verify<FallingTub>(static_cast<const uint8_t *>(obj), 0);
}
case Gadget_HandFan: {
auto ptr = reinterpret_cast<const HandFan *>(obj);
return verifier.VerifyTable(ptr);
}
default: return true;
}
}
inline bool VerifyGadgetVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types) {
if (!values || !types) return !values && !types;
if (values->size() != types->size()) return false;
for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
if (!VerifyGadget(
verifier, values->Get(i), types->GetEnum<Gadget>(i))) {
return false;
}
}
return true;
}
inline void *GadgetUnion::UnPack(const void *obj, Gadget type, const flatbuffers::resolver_function_t *resolver) {
(void)resolver;
switch (type) {
case Gadget_FallingTub: {
auto ptr = reinterpret_cast<const FallingTub *>(obj);
return new FallingTub(*ptr);
}
case Gadget_HandFan: {
auto ptr = reinterpret_cast<const HandFan *>(obj);
return ptr->UnPack(resolver);
}
default: return nullptr;
}
}
inline flatbuffers::Offset<void> GadgetUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const {
(void)_rehasher;
switch (type) {
case Gadget_FallingTub: {
auto ptr = reinterpret_cast<const FallingTub *>(value);
return _fbb.CreateStruct(*ptr).Union();
}
case Gadget_HandFan: {
auto ptr = reinterpret_cast<const HandFanT *>(value);
return CreateHandFan(_fbb, ptr, _rehasher).Union();
}
default: return 0;
}
}
inline GadgetUnion::GadgetUnion(const GadgetUnion &u) : type(u.type), value(nullptr) {
switch (type) {
case Gadget_FallingTub: {
value = new FallingTub(*reinterpret_cast<FallingTub *>(u.value));
break;
}
case Gadget_HandFan: {
value = new HandFanT(*reinterpret_cast<HandFanT *>(u.value));
break;
}
default:
break;
}
}
inline void GadgetUnion::Reset() {
switch (type) {
case Gadget_FallingTub: {
auto ptr = reinterpret_cast<FallingTub *>(value);
delete ptr;
break;
}
case Gadget_HandFan: {
auto ptr = reinterpret_cast<HandFanT *>(value);
delete ptr;
break;
}
default: break;
}
value = nullptr;
type = Gadget_NONE;
}
inline const flatbuffers::TypeTable *CharacterTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_SEQUENCE, 0, -1 },
@@ -754,6 +1131,27 @@ inline const flatbuffers::TypeTable *CharacterTypeTable() {
return &tt;
}
inline const flatbuffers::TypeTable *GadgetTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_SEQUENCE, 0, -1 },
{ flatbuffers::ET_SEQUENCE, 0, 0 },
{ flatbuffers::ET_SEQUENCE, 0, 1 }
};
static const flatbuffers::TypeFunction type_refs[] = {
FallingTubTypeTable,
HandFanTypeTable
};
static const char * const names[] = {
"NONE",
"FallingTub",
"HandFan"
};
static const flatbuffers::TypeTable tt = {
flatbuffers::ST_UNION, 3, type_codes, type_refs, nullptr, nullptr, names
};
return &tt;
}
inline const flatbuffers::TypeTable *AttackerTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_INT, 0, -1 }
@@ -795,6 +1193,33 @@ inline const flatbuffers::TypeTable *BookReaderTypeTable() {
return &tt;
}
inline const flatbuffers::TypeTable *FallingTubTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_INT, 0, -1 }
};
static const int64_t values[] = { 0, 4 };
static const char * const names[] = {
"weight"
};
static const flatbuffers::TypeTable tt = {
flatbuffers::ST_STRUCT, 1, type_codes, nullptr, nullptr, values, names
};
return &tt;
}
inline const flatbuffers::TypeTable *HandFanTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_INT, 0, -1 }
};
static const char * const names[] = {
"length"
};
static const flatbuffers::TypeTable tt = {
flatbuffers::ST_TABLE, 1, type_codes, nullptr, nullptr, nullptr, names
};
return &tt;
}
inline const flatbuffers::TypeTable *MovieTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_UTYPE, 0, 0 },