text field setters

This commit is contained in:
David Renshaw 2014-05-21 20:44:16 -04:00
parent b006a01730
commit 9f368ff3ec

View file

@ -549,9 +549,8 @@ private:
" KJ_IREQUIRE(which() == ", scope, upperCase, ",\n" " KJ_IREQUIRE(which() == ", scope, upperCase, ",\n"
" \"Must check which() before get()ing a union member.\");\n"), " \"Must check which() before get()ing a union member.\");\n"),
kj::str( kj::str(
" _builder.setDataField<", scope, "Which>(\n" spaces(indent), " _builder.setShortField(", discrimOffset, ", (short)",
" ", discrimOffset, " * ::capnp::ELEMENTS, ", scope, "Which.", upperCase, ".ordinal());\n"),
scope, upperCase, ");\n"),
kj::strTree(spaces(indent), " public final boolean is", titleCase, "() {\n", kj::strTree(spaces(indent), " public final boolean is", titleCase, "() {\n",
spaces(indent), " return which() == ", scope, "Which.", upperCase,";\n", spaces(indent), " return which() == ", scope, "Which.", upperCase,";\n",
spaces(indent), " }\n"), spaces(indent), " }\n"),
@ -592,7 +591,7 @@ private:
DiscriminantChecks unionDiscrim; DiscriminantChecks unionDiscrim;
if (hasDiscriminantValue(proto)) { if (hasDiscriminantValue(proto)) {
unionDiscrim = makeDiscriminantChecks(scope, proto.getName(), field.getContainingStruct(), indent); unionDiscrim = makeDiscriminantChecks(scope, proto.getName(), field.getContainingStruct(), indent + 1);
} }
switch (proto.which()) { switch (proto.which()) {
@ -805,6 +804,7 @@ private:
spaces(indent), " }\n") : spaces(indent), " }\n") :
kj::strTree( kj::strTree(
spaces(indent), " public final void set", titleCase, "(", type, " value) {\n", spaces(indent), " public final void set", titleCase, "(", type, " value) {\n",
unionDiscrim.set,
spaces(indent), " _builder.set", toTitleCase(type), spaces(indent), " _builder.set", toTitleCase(type),
"Field(", offset, ", value);\n", "Field(", offset, ", value);\n",
spaces(indent), " }\n"))), spaces(indent), " }\n"))),
@ -909,7 +909,8 @@ private:
spaces(indent), " throw new Error();\n", spaces(indent), " throw new Error();\n",
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n", spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
spaces(indent), " throw new Error();\n", unionDiscrim.set,
spaces(indent), " _builder.getPointerField(", offset, ").setText(value);\n",
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " public final ", type, ".Builder init", titleCase, "(int size) {\n", spaces(indent), " public final ", type, ".Builder init", titleCase, "(int size) {\n",
spaces(indent), " throw new Error();\n", spaces(indent), " throw new Error();\n",