Commit 08d73bef authored by Kenton Varda's avatar Kenton Varda

Refactor dynamic API using new schema API.

parent e7b9e4da
// Copyright (c) 2013, Kenton Varda <temporal@gmail.com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Copyright (c) 2013, Kenton Varda <temporal@gmail.com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define CAPNPROTO_PRIVATE
#include "dynamic.h"
#include "message.h"
#include "logging.h"
#include <gtest/gtest.h>
#include "test-util.h"
namespace capnproto {
namespace internal {
namespace {
void dynamicInitTestmessage(DynamicStruct::Builder builder) {
builder.set("voidField", Void::VOID);
builder.set("boolField", true);
builder.set("int8Field", -123);
builder.set("int16Field", -12345);
builder.set("int32Field", -12345678);
builder.set("int64Field", -123456789012345ll);
builder.set("uInt8Field", 234u);
builder.set("uInt16Field", 45678u);
builder.set("uInt32Field", 3456789012u);
builder.set("uInt64Field", 12345678901234567890ull);
builder.set("float32Field", 1234.5);
builder.set("float64Field", -123e45);
builder.set("textField", Text::Reader("foo"));
builder.set("dataField", Data::Reader("bar"));
{
auto subBuilder = builder.init("structField").as<DynamicStruct>();
subBuilder.set("voidField", Void::VOID);
subBuilder.set("boolField", true);
subBuilder.set("int8Field", -12);
subBuilder.set("int16Field", 3456);
subBuilder.set("int32Field", -78901234);
subBuilder.set("int64Field", 56789012345678ll);
subBuilder.set("uInt8Field", 90u);
subBuilder.set("uInt16Field", 1234u);
subBuilder.set("uInt32Field", 56789012u);
subBuilder.set("uInt64Field", 345678901234567890ull);
subBuilder.set("float32Field", -1.25e-10);
subBuilder.set("float64Field", 345);
subBuilder.set("textField", Text::Reader("baz"));
subBuilder.set("dataField", Data::Reader("qux"));
{
auto subSubBuilder = subBuilder.init("structField").as<DynamicStruct>();
subSubBuilder.set("textField", Text::Reader("nested"));
subSubBuilder.init("structField").as<DynamicStruct>().set("textField", Text::Reader("really nested"));
}
subBuilder.set("enumField", toDynamic(TestEnum::BAZ));
subBuilder.set("voidList", {Void::VOID, Void::VOID, Void::VOID});
subBuilder.set("boolList", {false, true, false, true, true});
subBuilder.set("int8List", {12, -34, -0x80, 0x7f});
subBuilder.set("int16List", {1234, -5678, -0x8000, 0x7fff});
subBuilder.set("int32List", {12345678, -90123456, -0x8000000, 0x7ffffff});
// gcc warns on -0x800...ll and the only work-around I could find was to do -0x7ff...ll-1.
subBuilder.set("int64List", {123456789012345ll, -678901234567890ll, -0x7fffffffffffffffll-1, 0x7fffffffffffffffll});
subBuilder.set("uInt8List", {12u, 34u, 0u, 0xffu});
subBuilder.set("uInt16List", {1234u, 5678u, 0u, 0xffffu});
subBuilder.set("uInt32List", {12345678u, 90123456u, 0u, 0xffffffffu});
subBuilder.set("uInt64List", {123456789012345ull, 678901234567890ull, 0ull, 0xffffffffffffffffull});
subBuilder.set("float32List", {0, 1234567, 1e37, -1e37, 1e-37, -1e-37});
subBuilder.set("float64List", {0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306});
subBuilder.set("textList", {Text::Reader("quux"), Text::Reader("corge"), Text::Reader("grault")});
subBuilder.set("dataList", {Data::Reader("garply"), Data::Reader("waldo"), Data::Reader("fred")});
{
auto listBuilder = subBuilder.init("structList", 3).as<DynamicList>();
listBuilder[0].as<DynamicStruct>().set("textField", Text::Reader("x structlist 1"));
listBuilder[1].as<DynamicStruct>().set("textField", Text::Reader("x structlist 2"));
listBuilder[2].as<DynamicStruct>().set("textField", Text::Reader("x structlist 3"));
}
subBuilder.set("enumList", {toDynamic(TestEnum::QUX),
toDynamic(TestEnum::BAR),
toDynamic(TestEnum::GRAULT)});
}
builder.set("enumField", toDynamic(TestEnum::CORGE));
builder.init("voidList", 6);
builder.set("boolList", {true, false, false, true});
builder.set("int8List", {111, -111});
builder.set("int16List", {11111, -11111});
builder.set("int32List", {111111111, -111111111});
builder.set("int64List", {1111111111111111111ll, -1111111111111111111ll});
builder.set("uInt8List", {111u, 222u});
builder.set("uInt16List", {33333u, 44444u});
builder.set("uInt32List", {3333333333u});
builder.set("uInt64List", {11111111111111111111ull});
builder.set("float32List", {5555.5,
std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::quiet_NaN()});
builder.set("float64List", {7777.75,
std::numeric_limits<double>::infinity(),
-std::numeric_limits<double>::infinity(),
std::numeric_limits<double>::quiet_NaN()});
builder.set("textList", {Text::Reader("plugh"), Text::Reader("xyzzy"), Text::Reader("thud")});
builder.set("dataList", {Data::Reader("oops"), Data::Reader("exhausted"), Data::Reader("rfc3092")});
{
auto listBuilder = builder.init("structList", 3).as<DynamicList>();
listBuilder[0].as<DynamicStruct>().set("textField", Text::Reader("structlist 1"));
listBuilder[1].as<DynamicStruct>().set("textField", Text::Reader("structlist 2"));
listBuilder[2].as<DynamicStruct>().set("textField", Text::Reader("structlist 3"));
}
builder.set("enumList", {toDynamic(TestEnum::FOO), toDynamic(TestEnum::GARPLY)});
}
TEST(DynamicApi, Struct) {
MallocMessageBuilder builder;
auto root = builder.initRoot<TestAllTypes>();
dynamicInitTestmessage(toDynamic(root));
checkTestMessage(root);
}
} // namespace
} // namespace internal
} // namespace capnproto
This diff is collapsed.
This diff is collapsed.
......@@ -31,7 +31,8 @@
namespace capnproto {
class SchemaPool; // Needs to be declared for dynamic Object accessors.
template <typename T, Kind k = kind<T>()>
struct ToDynamic_; // Defined in dynamic.h, needs to be declared as everyone's friend.
class DynamicStruct; // So that it can be declared a friend.
......
......@@ -37,7 +37,7 @@ namespace internal {
class BuilderArena;
}
class SchemaPool;
class StructSchema;
// =======================================================================================
......@@ -99,8 +99,8 @@ public:
// Get the root struct of the message, interpreting it as the given struct type.
template <typename RootType>
typename RootType::Reader getRoot(const SchemaPool& pool, uint64_t typeId);
// Dynamically interpret the root struct of the message using the type with the given ID.
typename RootType::Reader getRoot(StructSchema schema);
// Dynamically interpret the root struct of the message using the given schema.
// RootType in this case must be DynamicStruct, and you must #include <capnproto/dynamic.h> to
// use this.
......@@ -138,14 +138,14 @@ public:
// Get the root struct of the message, interpreting it as the given struct type.
template <typename RootType>
typename RootType::Builder getRoot(const SchemaPool& pool, uint64_t typeId);
// Dynamically interpret the root struct of the message using the type with the given ID.
typename RootType::Builder getRoot(StructSchema schema);
// Dynamically interpret the root struct of the message using the given schema.
// RootType in this case must be DynamicStruct, and you must #include <capnproto/dynamic.h> to
// use this.
template <typename RootType>
typename RootType::Builder initRoot(const SchemaPool& pool, uint64_t typeId);
// Dynamically init the root struct of the message using the type with the given ID.
typename RootType::Builder initRoot(StructSchema schema);
// Dynamically init the root struct of the message using the given schema.
// RootType in this case must be DynamicStruct, and you must #include <capnproto/dynamic.h> to
// use this.
......
......@@ -67,9 +67,9 @@ TEST(Schema, Structs) {
EXPECT_ANY_THROW(schema.asEnum());
EXPECT_ANY_THROW(schema.asInterface());
ASSERT_EQ(schema.members().size(),
ASSERT_EQ(schema.getMembers().size(),
schema.getProto().getBody().getStructNode().getMembers().size());
StructSchema::Member member = schema.members()[0];
StructSchema::Member member = schema.getMembers()[0];
EXPECT_EQ("voidField", member.getProto().getName());
EXPECT_TRUE(member.getContainingStruct() == schema);
EXPECT_TRUE(member.getContainingUnion() == nullptr);
......@@ -79,7 +79,7 @@ TEST(Schema, Structs) {
Maybe<StructSchema::Member> lookup = schema.findMemberByName("voidField");
ASSERT_TRUE(lookup != nullptr);
EXPECT_TRUE(*lookup == member);
EXPECT_TRUE(*lookup != schema.members()[1]);
EXPECT_TRUE(*lookup != schema.getMembers()[1]);
EXPECT_TRUE(schema.findMemberByName("noSuchField") == nullptr);
......@@ -95,15 +95,15 @@ TEST(Schema, FieldLookupOutOfOrder) {
// file.
auto schema = Schema::from<test::TestOutOfOrder>().asStruct();
EXPECT_EQ("qux", schema.members()[0].getProto().getName());
EXPECT_EQ("grault", schema.members()[1].getProto().getName());
EXPECT_EQ("bar", schema.members()[2].getProto().getName());
EXPECT_EQ("foo", schema.members()[3].getProto().getName());
EXPECT_EQ("corge", schema.members()[4].getProto().getName());
EXPECT_EQ("waldo", schema.members()[5].getProto().getName());
EXPECT_EQ("quux", schema.members()[6].getProto().getName());
EXPECT_EQ("garply", schema.members()[7].getProto().getName());
EXPECT_EQ("baz", schema.members()[8].getProto().getName());
EXPECT_EQ("qux", schema.getMembers()[0].getProto().getName());
EXPECT_EQ("grault", schema.getMembers()[1].getProto().getName());
EXPECT_EQ("bar", schema.getMembers()[2].getProto().getName());
EXPECT_EQ("foo", schema.getMembers()[3].getProto().getName());
EXPECT_EQ("corge", schema.getMembers()[4].getProto().getName());
EXPECT_EQ("waldo", schema.getMembers()[5].getProto().getName());
EXPECT_EQ("quux", schema.getMembers()[6].getProto().getName());
EXPECT_EQ("garply", schema.getMembers()[7].getProto().getName());
EXPECT_EQ("baz", schema.getMembers()[8].getProto().getName());
EXPECT_EQ(3, schema.findMemberByName("foo")->getProto().getOrdinal());
EXPECT_EQ(2, schema.findMemberByName("bar")->getProto().getOrdinal());
......@@ -160,16 +160,16 @@ TEST(Schema, Enums) {
EXPECT_ANY_THROW(schema.asInterface());
EXPECT_TRUE(schema.asEnum() == schema);
ASSERT_EQ(schema.enumerants().size(),
ASSERT_EQ(schema.getEnumerants().size(),
schema.getProto().getBody().getEnumNode().getEnumerants().size());
EnumSchema::Enumerant enumerant = schema.enumerants()[0];
EnumSchema::Enumerant enumerant = schema.getEnumerants()[0];
EXPECT_EQ("foo", enumerant.getProto().getName());
EXPECT_TRUE(enumerant.getContainingEnum() == schema);
Maybe<EnumSchema::Enumerant> lookup = schema.findEnumerantByName("foo");
ASSERT_TRUE(lookup != nullptr);
EXPECT_TRUE(*lookup == enumerant);
EXPECT_TRUE(*lookup != schema.enumerants()[1]);
EXPECT_TRUE(*lookup != schema.getEnumerants()[1]);
EXPECT_TRUE(schema.findEnumerantByName("noSuchEnumerant") == nullptr);
......
......@@ -114,17 +114,17 @@ auto findSchemaMemberByName(const internal::RawSchema* raw, Text::Reader name,
} // namespace
StructSchema::MemberList StructSchema::members() const {
StructSchema::MemberList StructSchema::getMembers() const {
return MemberList(*this, 0, getProto().getBody().getStructNode().getMembers());
}
Maybe<StructSchema::Member> StructSchema::findMemberByName(Text::Reader name) const {
return findSchemaMemberByName(raw, name, 0, members());
return findSchemaMemberByName(raw, name, 0, getMembers());
}
Maybe<StructSchema::Union> StructSchema::Member::getContainingUnion() const {
if (unionIndex == 0) return nullptr;
return parent.members()[unionIndex - 1].asUnion();
return parent.getMembers()[unionIndex - 1].asUnion();
}
StructSchema::Union StructSchema::Member::asUnion() const {
......@@ -134,32 +134,32 @@ StructSchema::Union StructSchema::Member::asUnion() const {
return Union(*this);
}
StructSchema::MemberList StructSchema::Union::members() const {
StructSchema::MemberList StructSchema::Union::getMembers() const {
return MemberList(parent, index + 1, proto.getBody().getUnionMember().getMembers());
}
Maybe<StructSchema::Member> StructSchema::Union::findMemberByName(Text::Reader name) const {
return findSchemaMemberByName(parent.raw, name, index + 1, members());
return findSchemaMemberByName(parent.raw, name, index + 1, getMembers());
}
// -------------------------------------------------------------------
EnumSchema::EnumerantList EnumSchema::enumerants() const {
EnumSchema::EnumerantList EnumSchema::getEnumerants() const {
return EnumerantList(*this, getProto().getBody().getEnumNode().getEnumerants());
}
Maybe<EnumSchema::Enumerant> EnumSchema::findEnumerantByName(Text::Reader name) const {
return findSchemaMemberByName(raw, name, 0, enumerants());
return findSchemaMemberByName(raw, name, 0, getEnumerants());
}
// -------------------------------------------------------------------
InterfaceSchema::MethodList InterfaceSchema::methods() const {
InterfaceSchema::MethodList InterfaceSchema::getMethods() const {
return MethodList(*this, getProto().getBody().getInterfaceNode().getMethods());
}
Maybe<InterfaceSchema::Method> InterfaceSchema::findMethodByName(Text::Reader name) const {
return findSchemaMemberByName(raw, name, 0, methods());
return findSchemaMemberByName(raw, name, 0, getMethods());
}
// =======================================================================================
......
......@@ -99,7 +99,7 @@ public:
class Union;
class MemberList;
MemberList members() const;
MemberList getMembers() const;
Maybe<Member> findMemberByName(Text::Reader name) const;
private:
......@@ -147,7 +147,7 @@ class StructSchema::Union: public Member {
public:
Union() = default;
MemberList members() const;
MemberList getMembers() const;
Maybe<Member> findMemberByName(Text::Reader name) const;
private:
......@@ -181,10 +181,12 @@ private:
class EnumSchema: public Schema {
public:
EnumSchema() = default;
class Enumerant;
class EnumerantList;
EnumerantList enumerants() const;
EnumerantList getEnumerants() const;
Maybe<Enumerant> findEnumerantByName(Text::Reader name) const;
private:
......@@ -242,10 +244,12 @@ private:
class InterfaceSchema: public Schema {
public:
InterfaceSchema() = default;
class Method;
class MethodList;
MethodList methods() const;
MethodList getMethods() const;
Maybe<Method> findMethodByName(Text::Reader name) const;
private:
......@@ -332,6 +336,9 @@ public:
// Get the schema for complex element types. Each of these throws an exception if the element
// type is not of the requested kind.
inline bool operator==(const ListSchema& other) const;
inline bool operator!=(const ListSchema& other) const { return !(*this == other); }
private:
schema::Type::Body::Which elementType;
uint8_t nestingDepth; // 0 for T, 1 for List(T), 2 for List(List(T)), ...
......@@ -400,6 +407,11 @@ inline schema::Type::Body::Which ListSchema::whichElementType() const {
return nestingDepth == 0 ? elementType : schema::Type::Body::LIST_TYPE;
}
inline bool ListSchema::operator==(const ListSchema& other) const {
return elementType == other.elementType && nestingDepth == other.nestingDepth &&
elementSchema == other.elementSchema;
}
template <typename T>
struct ListSchema::FromImpl<List<T>> {
static inline ListSchema get() { return of(Schema::from<T>()); }
......
......@@ -166,13 +166,14 @@ public:
{{/fieldIsPrimitive}}
{{#fieldIsGenericObject}}
template <typename T> inline typename T::Reader get{{fieldTitleCase}}();
template <typename T, typename... Params> inline typename T::Reader get{{fieldTitleCase}}(
const ::capnproto::SchemaPool& pool, Params&&... params);
template <typename T, typename Param> inline typename T::Reader
get{{fieldTitleCase}}(Param&& param);
{{/fieldIsGenericObject}}
{{/typeFields}}
private:
::capnproto::internal::StructReader _reader;
friend class ::capnproto::SchemaPool;
template <typename T, ::capnproto::Kind k>
friend struct ::capnproto::ToDynamic_;
};
{{! ------------------------------------------------------------------------------------------- }}
......@@ -220,19 +221,17 @@ public:
{{/fieldIsPrimitive}}
{{#fieldIsGenericObject}}
template <typename T> inline typename T::Builder get{{fieldTitleCase}}();
template <typename T, typename Param> inline typename T::Builder
get{{fieldTitleCase}}(Param&& param);
template <typename T> inline void set{{fieldTitleCase}}(typename T::Reader value);
template <typename T> inline typename T::Builder init{{fieldTitleCase}}();
template <typename T> inline typename T::Builder init{{fieldTitleCase}}(unsigned int size);
template <typename T, typename... Params> inline typename T::Builder get{{fieldTitleCase}}(
const ::capnproto::SchemaPool& pool, Params&&... params);
template <typename T, typename... Params> inline typename T::Builder init{{fieldTitleCase}}(
const ::capnproto::SchemaPool& pool, Params&&... params);
template <typename T, typename... Params> inline typename T::Builder
init{{fieldTitleCase}}(Params&&... params);
{{/fieldIsGenericObject}}
{{/typeFields}}
private:
::capnproto::internal::StructBuilder _builder;
friend class ::capnproto::SchemaPool;
template <typename T, ::capnproto::Kind k>
friend struct ::capnproto::ToDynamic_;
};
{{/typeStructOrUnion}}
{{/fileTypes}}
......@@ -384,70 +383,44 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
_builder, {{fieldOffset}} * ::capnproto::REFERENCES);
}
template <typename T>
inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(typename T::Reader value) {
template <typename T, typename Param>
inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&& param) {
{{#fieldUnion}}
_builder.setDataField<{{unionTitleCase}}::Which>(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
CAPNPROTO_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
::capnproto::internal::PointerHelpers<T>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value);
return ::capnproto::internal::PointerHelpers<T>::getDynamic(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Param>(param));
}
template <typename T>
inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}() {
template <typename T, typename Param>
inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(Param&& param) {
{{#fieldUnion}}
_builder.setDataField<{{unionTitleCase}}::Which>(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
CAPNPROTO_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES);
return ::capnproto::internal::PointerHelpers<T>::getDynamic(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Param>(param));
}
template <typename T>
inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(unsigned int size) {
inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(typename T::Reader value) {
{{#fieldUnion}}
_builder.setDataField<{{unionTitleCase}}::Which>(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, size);
}
template <typename T, typename... Params>
inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(
const ::capnproto::SchemaPool& pool, Params&&... params) {
{{#fieldUnion}}
CAPNPROTO_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES,
pool, ::capnproto::forward<Params>(params)...);
}
template <typename T, typename... Params>
inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(
const ::capnproto::SchemaPool& pool, Params&&... params) {
{{#fieldUnion}}
CAPNPROTO_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member.");
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES,
pool, ::capnproto::forward<Params>(params)...);
::capnproto::internal::PointerHelpers<T>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value);
}
template <typename T, typename... Params>
inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
const ::capnproto::SchemaPool& pool, Params&&... params) {
inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(Params&&... params) {
{{#fieldUnion}}
_builder.setDataField<{{unionTitleCase}}::Which>(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES,
pool, ::capnproto::forward<Params>(params)...);
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Params>(params)...);
}
{{/fieldIsGenericObject}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment