init StructList.Builder

This commit is contained in:
David Renshaw 2014-05-20 20:49:20 -04:00
parent 8b2655623f
commit ddbab77252
2 changed files with 18 additions and 15 deletions

View file

@ -968,23 +968,17 @@ private:
return FieldText { return FieldText {
kj::strTree( kj::strTree(
kj::mv(unionDiscrim.readerIsDecl), kj::mv(unionDiscrim.readerIsDecl),
spaces(indent), " public boolean has", titleCase, "() {\n", spaces(indent), " public final boolean has", titleCase, "() {\n",
spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n", spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n",
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " public final ", type, ".Reader<", elementReaderType, ">", spaces(indent), " public final ", type, ".Reader<", elementReaderType, ">",
" get", titleCase, "() {\n", " get", titleCase, "() {\n",
(kind == FieldKind::LIST ? spaces(indent), " return new ", type, ".Reader<",
kj::strTree(spaces(indent), elementReaderType, ">(_reader.getPointerField(", offset, ").getList(",
" return new ", type, ".Reader<", // XXX what about lists of non-structs?
elementReaderType, typeName(typeBody.getList().getElementType()),".STRUCT_SIZE.preferredListEncoding), ",
">(_reader.getPointerField(", elementReaderType, ".factory);\n",
offset, ").getList(",
// XXX what about lists of non-structs?
typeName(typeBody.getList().getElementType()),".STRUCT_SIZE.preferredListEncoding), ",
elementReaderType, ".factory);\n") :
kj::strTree(spaces(indent), "Struct\n")), // XXX
spaces(indent), " }\n", spaces(indent), " }\n",
"\n"), "\n"),
@ -1002,7 +996,10 @@ private:
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " public final ", type, ".Builder<", elementBuilderType,">", spaces(indent), " public final ", type, ".Builder<", elementBuilderType,">",
" init", titleCase, "(int size) {\n", " init", titleCase, "(int size) {\n",
spaces(indent), " throw new Error();\n", spaces(indent), " return new ", type, ".Builder<", elementBuilderType, ">",
"(_builder.getPointerField(", offset, ").initStructList(", // XXX what about non-struct lists?
"size,", typeName(typeBody.getList().getElementType()),".STRUCT_SIZE), ",
elementBuilderType, ".factory);\n",
spaces(indent), " }\n"), spaces(indent), " }\n"),
kj::strTree( kj::strTree(

View file

@ -28,7 +28,13 @@ public final class StructList {
this.factory = factory; this.factory = factory;
} }
public T get(int index) { // init
Builder(PointerBuilder builder, int size, FromStructBuilder<T> factory) {
this.builder = builder.initStructList(size, factory.structSize());
this.factory = factory;
}
public final T get(int index) {
return this.factory.fromStructBuilder(this.builder.getStructElement(index)); return this.factory.fromStructBuilder(this.builder.getStructElement(index));
} }