Support binary search for struct in cpp (#4245)

* Support binary search for struct in cpp

CreateVectorOfSortedStruct is provided for convenience.

* fix continuous-integration error

* add generated files

* compile Ability.cs in csharp test

* compile Ability.cs in csharp

* modify according to code review
This commit is contained in:
tianyapiaozi
2017-03-30 00:51:12 +08:00
committed by Wouter van Oortmerssen
parent 89041a1686
commit a5cc2092a6
20 changed files with 564 additions and 17 deletions

View File

@@ -432,6 +432,89 @@ MyGame.Example.Vec3.createVec3 = function(builder, x, y, z, test1, test2, test3_
return builder.offset();
};
/**
* @constructor
*/
MyGame.Example.Ability = function() {
/**
* @type {flatbuffers.ByteBuffer}
*/
this.bb = null;
/**
* @type {number}
*/
this.bb_pos = 0;
};
/**
* @param {number} i
* @param {flatbuffers.ByteBuffer} bb
* @returns {MyGame.Example.Ability}
*/
MyGame.Example.Ability.prototype.__init = function(i, bb) {
this.bb_pos = i;
this.bb = bb;
return this;
};
/**
* @returns {number}
*/
MyGame.Example.Ability.prototype.id = function() {
return this.bb.readUint32(this.bb_pos);
};
/**
* @param {number} value
* @returns {boolean}
*/
MyGame.Example.Ability.prototype.mutate_id = function(value) {
var offset = this.bb.__offset(this.bb_pos, 0);
if (offset === 0) {
return false;
}
this.bb.writeUint32(this.bb_pos + offset, value);
return true;
};
/**
* @returns {number}
*/
MyGame.Example.Ability.prototype.distance = function() {
return this.bb.readUint32(this.bb_pos + 4);
};
/**
* @param {number} value
* @returns {boolean}
*/
MyGame.Example.Ability.prototype.mutate_distance = function(value) {
var offset = this.bb.__offset(this.bb_pos, 4);
if (offset === 0) {
return false;
}
this.bb.writeUint32(this.bb_pos + offset, value);
return true;
};
/**
* @param {flatbuffers.Builder} builder
* @param {number} id
* @param {number} distance
* @returns {flatbuffers.Offset}
*/
MyGame.Example.Ability.createAbility = function(builder, id, distance) {
builder.prep(4, 8);
builder.writeInt32(distance);
builder.writeInt32(id);
return builder.offset();
};
/**
* @constructor
*/
@@ -1170,11 +1253,29 @@ MyGame.Example.Monster.prototype.testarrayofstring2Length = function() {
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
/**
* @param {number} index
* @param {MyGame.Example.Ability=} obj
* @returns {MyGame.Example.Ability}
*/
MyGame.Example.Monster.prototype.testarrayofsortedstruct = function(index, obj) {
var offset = this.bb.__offset(this.bb_pos, 62);
return offset ? (obj || new MyGame.Example.Ability).__init(this.bb.__vector(this.bb_pos + offset) + index * 8, this.bb) : null;
};
/**
* @returns {number}
*/
MyGame.Example.Monster.prototype.testarrayofsortedstructLength = function() {
var offset = this.bb.__offset(this.bb_pos, 62);
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
};
/**
* @param {flatbuffers.Builder} builder
*/
MyGame.Example.Monster.startMonster = function(builder) {
builder.startObject(29);
builder.startObject(30);
};
/**
@@ -1535,6 +1636,22 @@ MyGame.Example.Monster.startTestarrayofstring2Vector = function(builder, numElem
builder.startVector(4, numElems, 4);
};
/**
* @param {flatbuffers.Builder} builder
* @param {flatbuffers.Offset} testarrayofsortedstructOffset
*/
MyGame.Example.Monster.addTestarrayofsortedstruct = function(builder, testarrayofsortedstructOffset) {
builder.addFieldOffset(29, testarrayofsortedstructOffset, 0);
};
/**
* @param {flatbuffers.Builder} builder
* @param {number} numElems
*/
MyGame.Example.Monster.startTestarrayofsortedstructVector = function(builder, numElems) {
builder.startVector(8, numElems, 4);
};
/**
* @param {flatbuffers.Builder} builder
* @returns {flatbuffers.Offset}