Commit 567c2de2 authored by Kenton Varda's avatar Kenton Varda

Implement 'Object' field type, which can be any pointer type. The caller…

Implement 'Object' field type, which can be any pointer type.  The caller specifies the type when calling the accessors.
parent 268a2235
...@@ -133,6 +133,91 @@ TEST(Encoding, DefaultsFromEmptyMessage) { ...@@ -133,6 +133,91 @@ TEST(Encoding, DefaultsFromEmptyMessage) {
checkTestMessage(readMessageTrusted<TestDefaults>(emptyMessage.words)); checkTestMessage(readMessageTrusted<TestDefaults>(emptyMessage.words));
} }
TEST(Encoding, GenericObjects) {
MallocMessageBuilder builder;
auto root = builder.getRoot<test::TestObject>();
initTestMessage(root.initObjectField<TestAllTypes>());
checkTestMessage(root.getObjectField<TestAllTypes>());
checkTestMessage(root.asReader().getObjectField<TestAllTypes>());
root.setObjectField<Text>("foo");
EXPECT_EQ("foo", root.getObjectField<Text>());
EXPECT_EQ("foo", root.asReader().getObjectField<Text>());
root.setObjectField<Data>("foo");
EXPECT_EQ("foo", root.getObjectField<Data>());
EXPECT_EQ("foo", root.asReader().getObjectField<Data>());
{
{
List<uint32_t>::Builder list = root.initObjectField<List<uint32_t>>(3);
ASSERT_EQ(3u, list.size());
list.copyFrom({123, 456, 789});
}
{
List<uint32_t>::Builder list = root.getObjectField<List<uint32_t>>();
ASSERT_EQ(3u, list.size());
EXPECT_EQ(123u, list[0]);
EXPECT_EQ(456u, list[1]);
EXPECT_EQ(789u, list[2]);
}
{
List<uint32_t>::Reader list = root.asReader().getObjectField<List<uint32_t>>();
ASSERT_EQ(3u, list.size());
EXPECT_EQ(123u, list[0]);
EXPECT_EQ(456u, list[1]);
EXPECT_EQ(789u, list[2]);
}
}
{
{
List<Text>::Builder list = root.initObjectField<List<Text>>(2);
ASSERT_EQ(2u, list.size());
list.copyFrom({"foo", "bar"});
}
{
List<Text>::Builder list = root.getObjectField<List<Text>>();
ASSERT_EQ(2u, list.size());
EXPECT_EQ("foo", list[0]);
EXPECT_EQ("bar", list[1]);
}
{
List<Text>::Reader list = root.asReader().getObjectField<List<Text>>();
ASSERT_EQ(2u, list.size());
EXPECT_EQ("foo", list[0]);
EXPECT_EQ("bar", list[1]);
}
}
{
{
List<TestAllTypes>::Builder list = root.initObjectField<List<TestAllTypes>>(2);
ASSERT_EQ(2u, list.size());
initTestMessage(list[0]);
}
{
List<TestAllTypes>::Builder list = root.getObjectField<List<TestAllTypes>>();
ASSERT_EQ(2u, list.size());
checkTestMessage(list[0]);
checkTestMessageAllZero(list[1]);
}
{
List<TestAllTypes>::Reader list = root.asReader().getObjectField<List<TestAllTypes>>();
ASSERT_EQ(2u, list.size());
checkTestMessage(list[0]);
checkTestMessageAllZero(list[1]);
}
}
}
#ifdef NDEBUG #ifdef NDEBUG
#define EXPECT_DEBUG_ANY_THROW(EXP) #define EXPECT_DEBUG_ANY_THROW(EXP)
#else #else
......
...@@ -29,4 +29,70 @@ ...@@ -29,4 +29,70 @@
#include "layout.h" #include "layout.h"
#include "list.h" #include "list.h"
namespace capnproto {
namespace internal {
template <typename T>
struct PointerHelpers {
static inline typename T::Reader get(StructReader reader, WireReferenceCount index) {
return typename T::Reader(reader.getStructField(index, nullptr));
}
static inline typename T::Builder get(StructBuilder builder, WireReferenceCount index) {
return typename T::Builder(builder.getStructField(index, T::STRUCT_SIZE, nullptr));
}
static inline typename T::Builder init(StructBuilder builder, WireReferenceCount index) {
return typename T::Builder(builder.initStructField(index, T::STRUCT_SIZE));
}
};
template <typename T>
struct PointerHelpers<List<T>> {
static inline typename List<T>::Reader get(StructReader reader, WireReferenceCount index) {
return typename List<T>::Reader(List<T>::getAsFieldOf(reader, index));
}
static inline typename List<T>::Builder get(StructBuilder builder, WireReferenceCount index) {
return typename List<T>::Builder(List<T>::getAsFieldOf(builder, index));
}
static inline typename List<T>::Builder init(
StructBuilder builder, WireReferenceCount index, int size) {
return typename List<T>::Builder(List<T>::initAsFieldOf(builder, index, size));
}
};
template <>
struct PointerHelpers<Text> {
static inline Text::Reader get(StructReader reader, WireReferenceCount index) {
return reader.getTextField(index, nullptr, 0 * BYTES);
}
static inline Text::Builder get(StructBuilder builder, WireReferenceCount index) {
return builder.getTextField(index, nullptr, 0 * BYTES);
}
static inline void set(StructBuilder builder, WireReferenceCount index, Text::Reader value) {
builder.setTextField(index, value);
}
static inline Text::Builder init(StructBuilder builder, WireReferenceCount index, int size) {
return builder.initTextField(index, size * BYTES);
}
};
template <>
struct PointerHelpers<Data> {
static inline Data::Reader get(StructReader reader, WireReferenceCount index) {
return reader.getDataField(index, nullptr, 0 * BYTES);
}
static inline Data::Builder get(StructBuilder builder, WireReferenceCount index) {
return builder.getDataField(index, nullptr, 0 * BYTES);
}
static inline void set(StructBuilder builder, WireReferenceCount index, Data::Reader value) {
builder.setDataField(index, value);
}
static inline Data::Builder init(StructBuilder builder, WireReferenceCount index, int size) {
return builder.initDataField(index, size * BYTES);
}
};
} // namespace internal
} // namespace capnproto
#endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_ #endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_
...@@ -43,6 +43,9 @@ public: ...@@ -43,6 +43,9 @@ public:
static constexpr bool value = sizeof(test<T>(nullptr)) == sizeof(yes); static constexpr bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
}; };
template <typename t>
struct PointerHelpers;
} // namespace internal } // namespace internal
template <typename T, bool isPrimitive = internal::IsPrimitive<T>::value> template <typename T, bool isPrimitive = internal::IsPrimitive<T>::value>
...@@ -228,8 +231,24 @@ private: ...@@ -228,8 +231,24 @@ private:
internal::ListReader& reader, uint index) { internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSizeForType<T>::value); return reader.getListElement(index * ELEMENTS, internal::FieldSizeForType<T>::value);
} }
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initListField(index, internal::FieldSizeForType<T>::value, size * ELEMENTS);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getListField(index, nullptr);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getListField(index, internal::FieldSizeForType<T>::value, nullptr);
}
template <typename U, bool b> template <typename U, bool b>
friend class List; friend class List;
template <typename U>
friend struct internal::PointerHelpers;
}; };
template <typename T> template <typename T>
...@@ -291,8 +310,24 @@ private: ...@@ -291,8 +310,24 @@ private:
internal::ListReader& reader, uint index) { internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::INLINE_COMPOSITE); return reader.getListElement(index * ELEMENTS, internal::FieldSize::INLINE_COMPOSITE);
} }
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initStructListField(index, size * ELEMENTS, T::STRUCT_SIZE);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getListField(index, nullptr);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getListField(index, internal::FieldSize::INLINE_COMPOSITE, nullptr);
}
template <typename U, bool b> template <typename U, bool b>
friend class List; friend class List;
template <typename U>
friend struct internal::PointerHelpers;
}; };
template <typename T> template <typename T>
...@@ -357,8 +392,24 @@ private: ...@@ -357,8 +392,24 @@ private:
internal::ListReader& reader, uint index) { internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE); return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE);
} }
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initListField(index, internal::FieldSize::REFERENCE, size * ELEMENTS);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getListField(index, nullptr);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getListField(index, internal::FieldSize::REFERENCE, nullptr);
}
template <typename U, bool b> template <typename U, bool b>
friend class List; friend class List;
template <typename U>
friend struct internal::PointerHelpers;
}; };
template <typename T, size_t subSize> template <typename T, size_t subSize>
...@@ -415,14 +466,30 @@ private: ...@@ -415,14 +466,30 @@ private:
} }
inline static internal::ListBuilder getAsElementOf( inline static internal::ListBuilder getAsElementOf(
internal::ListBuilder& builder, uint index) { internal::ListBuilder& builder, uint index) {
return builder.getListElement(index * ELEMENTS); return List<T>::getAsElementOf(builder, index);
} }
inline static internal::ListReader getAsElementOf( inline static internal::ListReader getAsElementOf(
internal::ListReader& reader, uint index) { internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSizeForType<T>::value); return List<T>::getAsElementOf(reader, index);
}
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return List<T>::initAsFieldOf(builder, index, size * subSize);
} }
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return List<T>::getAsFieldOf(builder, index);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return List<T>::getAsFieldOf(reader, index);
}
template <typename U, bool b> template <typename U, bool b>
friend class List; friend class List;
template <typename U>
friend struct internal::PointerHelpers;
}; };
template <> template <>
...@@ -502,13 +569,29 @@ private: ...@@ -502,13 +569,29 @@ private:
internal::ListReader& reader, uint index) { internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE); return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE);
} }
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initListField(index, internal::FieldSize::REFERENCE, size * ELEMENTS);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getListField(index, nullptr);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getListField(index, internal::FieldSize::REFERENCE, nullptr);
}
template <typename U, bool b> template <typename U, bool b>
friend class List; friend class List;
template <typename U>
friend struct internal::PointerHelpers;
}; };
template <size_t subSize> template <size_t subSize>
struct List<InlineData<subSize>, false> { struct List<InlineData<subSize>, false> {
// List of inline lists. // List of inline data.
class Reader { class Reader {
public: public:
...@@ -583,8 +666,24 @@ private: ...@@ -583,8 +666,24 @@ private:
internal::ListReader& reader, uint index) { internal::ListReader& reader, uint index) {
return reader.getDataElement(index * ELEMENTS); return reader.getDataElement(index * ELEMENTS);
} }
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initDataField(index, size * subSize * BYTES);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getDataField(index, nullptr, 0 * BYTES);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getDataField(index, nullptr, 0 * BYTES);
}
template <typename U, bool b> template <typename U, bool b>
friend class List; friend class List;
template <typename U>
friend struct internal::PointerHelpers;
}; };
template <> template <>
...@@ -664,8 +763,24 @@ private: ...@@ -664,8 +763,24 @@ private:
internal::ListReader& reader, uint index) { internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE); return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE);
} }
inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) {
return builder.initListField(index, internal::FieldSize::REFERENCE, size * ELEMENTS);
}
inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index) {
return builder.getListField(index, nullptr);
}
inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index) {
return reader.getListField(index, internal::FieldSize::REFERENCE, nullptr);
}
template <typename U, bool b> template <typename U, bool b>
friend class List; friend class List;
template <typename U>
friend struct internal::PointerHelpers;
}; };
} // namespace capnproto } // namespace capnproto
......
...@@ -158,6 +158,10 @@ struct TestDefaults { ...@@ -158,6 +158,10 @@ struct TestDefaults {
interfaceList @33 : List(Void); # TODO interfaceList @33 : List(Void); # TODO
} }
struct TestObject {
objectField @0 :Object;
}
struct TestUnion { struct TestUnion {
union0 @0 union { union0 @0 union {
# Pack union 0 under ideal conditions: there is no unused padding space prior to it. # Pack union 0 under ideal conditions: there is no unused padding space prior to it.
......
...@@ -276,10 +276,14 @@ compileValue pos (BuiltinType BuiltinFloat32) _ = makeExpectError pos "number" ...@@ -276,10 +276,14 @@ compileValue pos (BuiltinType BuiltinFloat32) _ = makeExpectError pos "number"
compileValue pos (BuiltinType BuiltinFloat64) _ = makeExpectError pos "number" compileValue pos (BuiltinType BuiltinFloat64) _ = makeExpectError pos "number"
compileValue pos (BuiltinType BuiltinText) _ = makeExpectError pos "string" compileValue pos (BuiltinType BuiltinText) _ = makeExpectError pos "string"
compileValue pos (BuiltinType BuiltinData) _ = makeExpectError pos "string" compileValue pos (BuiltinType BuiltinData) _ = makeExpectError pos "string"
compileValue pos (BuiltinType BuiltinObject) _ =
-- TODO(someday): We could arguably design a syntax where you specify the type followed by
-- the value, but it seems not worth the effort.
makeError pos "Can't specify literal value for 'Object'."
compileValue pos (EnumType _) _ = makeExpectError pos "enumerant name" compileValue pos (EnumType _) _ = makeExpectError pos "enumerant name"
compileValue pos (StructType _) _ = makeExpectError pos "parenthesized list of field assignments" compileValue pos (StructType _) _ = makeExpectError pos "parenthesized list of field assignments"
compileValue pos (InterfaceType _) _ = makeError pos "Interfaces can't have default values." compileValue pos (InterfaceType _) _ = makeError pos "Can't specify literal value for interface."
compileValue pos (ListType _) _ = makeExpectError pos "list" compileValue pos (ListType _) _ = makeExpectError pos "list"
compileValue pos (InlineListType _ _) _ = makeExpectError pos "list" compileValue pos (InlineListType _ _) _ = makeExpectError pos "list"
compileValue pos (InlineDataType _) _ = makeExpectError pos "string" compileValue pos (InlineDataType _) _ = makeExpectError pos "string"
...@@ -313,6 +317,9 @@ compileType scope (TypeExpression n params) = do ...@@ -313,6 +317,9 @@ compileType scope (TypeExpression n params) = do
\lists already inlines the elements." \lists already inlines the elements."
InlineListType (BuiltinType BuiltinBool) _ -> makeError (declNamePos n) InlineListType (BuiltinType BuiltinBool) _ -> makeError (declNamePos n)
"List(InlineList(Bool, n)) not supported due to implementation difficulty." "List(InlineList(Bool, n)) not supported due to implementation difficulty."
BuiltinType BuiltinObject -> makeError (declNamePos n)
"List(Object) not supported. Just use Object, or create a struct with \
\one field of type 'Object' and use a List of that."
_ -> return (ListType inner) _ -> return (ListType inner)
_ -> makeError (declNamePos n) "'List' requires exactly one type parameter." _ -> makeError (declNamePos n) "'List' requires exactly one type parameter."
DescBuiltinInline -> case params of DescBuiltinInline -> case params of
...@@ -342,6 +349,8 @@ compileType scope (TypeExpression n params) = do ...@@ -342,6 +349,8 @@ compileType scope (TypeExpression n params) = do
"InlineList of InlineList not currently supported." "InlineList of InlineList not currently supported."
InlineDataType _ -> makeError (declNamePos n) InlineDataType _ -> makeError (declNamePos n)
"InlineList of InlineData not currently supported." "InlineList of InlineData not currently supported."
BuiltinType BuiltinObject -> makeError (declNamePos n)
"InlineList(Object) not supported."
_ -> return $ InlineListType inner size _ -> return $ InlineListType inner size
_ -> makeError (declNamePos n) _ -> makeError (declNamePos n)
"'InlineList' requires exactly two type parameters: a type and a size." "'InlineList' requires exactly two type parameters: a type and a size."
......
...@@ -85,6 +85,7 @@ hashString str = ...@@ -85,6 +85,7 @@ hashString str =
MD5.hash $ MD5.hash $
UTF8.encode str UTF8.encode str
isPrimitive (BuiltinType BuiltinObject) = False
isPrimitive t@(BuiltinType _) = not $ isBlob t isPrimitive t@(BuiltinType _) = not $ isBlob t
isPrimitive (EnumType _) = True isPrimitive (EnumType _) = True
isPrimitive (StructType _) = False isPrimitive (StructType _) = False
...@@ -140,6 +141,9 @@ isStructList _ = False ...@@ -140,6 +141,9 @@ isStructList _ = False
isInlineList (InlineListType _ _) = True isInlineList (InlineListType _ _) = True
isInlineList _ = False isInlineList _ = False
isGenericObject (BuiltinType BuiltinObject) = True
isGenericObject _ = False
blobTypeString (BuiltinType BuiltinText) = "Text" blobTypeString (BuiltinType BuiltinText) = "Text"
blobTypeString (BuiltinType BuiltinData) = "Data" blobTypeString (BuiltinType BuiltinData) = "Data"
blobTypeString (InlineDataType _) = "Data" blobTypeString (InlineDataType _) = "Data"
...@@ -170,6 +174,7 @@ cxxTypeString (BuiltinType BuiltinFloat32) = "float" ...@@ -170,6 +174,7 @@ cxxTypeString (BuiltinType BuiltinFloat32) = "float"
cxxTypeString (BuiltinType BuiltinFloat64) = "double" cxxTypeString (BuiltinType BuiltinFloat64) = "double"
cxxTypeString (BuiltinType BuiltinText) = " ::capnproto::Text" cxxTypeString (BuiltinType BuiltinText) = " ::capnproto::Text"
cxxTypeString (BuiltinType BuiltinData) = " ::capnproto::Data" cxxTypeString (BuiltinType BuiltinData) = " ::capnproto::Data"
cxxTypeString (BuiltinType BuiltinObject) = " ::capnproto::Object"
cxxTypeString (EnumType desc) = globalName $ DescEnum desc cxxTypeString (EnumType desc) = globalName $ DescEnum desc
cxxTypeString (StructType desc) = globalName $ DescStruct desc cxxTypeString (StructType desc) = globalName $ DescStruct desc
cxxTypeString (InlineStructType desc) = globalName $ DescStruct desc cxxTypeString (InlineStructType desc) = globalName $ DescStruct desc
...@@ -293,6 +298,7 @@ fieldContext parent desc = mkStrContext context where ...@@ -293,6 +298,7 @@ fieldContext parent desc = mkStrContext context where
context "fieldIsInlineBlobList" = MuBool $ isInlineBlobList $ fieldType desc context "fieldIsInlineBlobList" = MuBool $ isInlineBlobList $ fieldType desc
context "fieldIsStructList" = MuBool $ isStructList $ fieldType desc context "fieldIsStructList" = MuBool $ isStructList $ fieldType desc
context "fieldIsInlineList" = MuBool $ isInlineList $ fieldType desc context "fieldIsInlineList" = MuBool $ isInlineList $ fieldType desc
context "fieldIsGenericObject" = MuBool $ isGenericObject $ fieldType desc
context "fieldDefaultBytes" = context "fieldDefaultBytes" =
case fieldDefaultValue desc >>= defaultValueBytes (fieldType desc) of case fieldDefaultValue desc >>= defaultValueBytes (fieldType desc) of
Just v -> muJust $ defaultBytesContext context (fieldType desc) v Just v -> muJust $ defaultBytesContext context (fieldType desc) v
......
...@@ -184,6 +184,7 @@ data BuiltinType = BuiltinVoid | BuiltinBool ...@@ -184,6 +184,7 @@ data BuiltinType = BuiltinVoid | BuiltinBool
| BuiltinUInt8 | BuiltinUInt16 | BuiltinUInt32 | BuiltinUInt64 | BuiltinUInt8 | BuiltinUInt16 | BuiltinUInt32 | BuiltinUInt64
| BuiltinFloat32 | BuiltinFloat64 | BuiltinFloat32 | BuiltinFloat64
| BuiltinText | BuiltinData | BuiltinText | BuiltinData
| BuiltinObject
deriving (Show, Enum, Bounded, Eq) deriving (Show, Enum, Bounded, Eq)
builtinTypes = [minBound::BuiltinType .. maxBound::BuiltinType] builtinTypes = [minBound::BuiltinType .. maxBound::BuiltinType]
...@@ -333,6 +334,7 @@ fieldSize (BuiltinType BuiltinFloat32) = SizeData Size32 ...@@ -333,6 +334,7 @@ fieldSize (BuiltinType BuiltinFloat32) = SizeData Size32
fieldSize (BuiltinType BuiltinFloat64) = SizeData Size64 fieldSize (BuiltinType BuiltinFloat64) = SizeData Size64
fieldSize (BuiltinType BuiltinText) = SizeReference fieldSize (BuiltinType BuiltinText) = SizeReference
fieldSize (BuiltinType BuiltinData) = SizeReference fieldSize (BuiltinType BuiltinData) = SizeReference
fieldSize (BuiltinType BuiltinObject) = SizeReference
fieldSize (EnumType _) = SizeData Size16 fieldSize (EnumType _) = SizeData Size16
fieldSize (StructType _) = SizeReference fieldSize (StructType _) = SizeReference
fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount = ps }) = fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount = ps }) =
......
...@@ -133,6 +133,9 @@ public: ...@@ -133,6 +133,9 @@ public:
{{#fieldIsList}} {{#fieldIsList}}
inline {{fieldType}}::Reader get{{fieldTitleCase}}(); inline {{fieldType}}::Reader get{{fieldTitleCase}}();
{{/fieldIsList}} {{/fieldIsList}}
{{#fieldIsGenericObject}}
template <typename T> inline typename T::Reader get{{fieldTitleCase}}();
{{/fieldIsGenericObject}}
{{/typeFields}} {{/typeFields}}
private: private:
::capnproto::internal::StructReader _reader; ::capnproto::internal::StructReader _reader;
...@@ -189,6 +192,12 @@ public: ...@@ -189,6 +192,12 @@ public:
inline void set{{fieldTitleCase}}(std::initializer_list<{{fieldElementType}}::Reader> other); inline void set{{fieldTitleCase}}(std::initializer_list<{{fieldElementType}}::Reader> other);
{{/fieldIsPrimitiveList}} {{/fieldIsPrimitiveList}}
{{/fieldIsList}} {{/fieldIsList}}
{{#fieldIsGenericObject}}
template <typename T> inline typename T::Builder get{{fieldTitleCase}}();
template <typename T> inline void set{{fieldTitleCase}}(const 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);
{{/fieldIsGenericObject}}
{{/typeFields}} {{/typeFields}}
private: private:
::capnproto::internal::StructBuilder _builder; ::capnproto::internal::StructBuilder _builder;
...@@ -636,6 +645,38 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}( ...@@ -636,6 +645,38 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(
{{/fieldIsPrimitiveList}} {{/fieldIsPrimitiveList}}
{{/fieldIsList}} {{/fieldIsList}}
{{! ------------------------------------------------------------------------------------------- }} {{! ------------------------------------------------------------------------------------------- }}
{{#fieldIsGenericObject}}
template <typename T>
inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
return ::capnproto::internal::PointerHelpers<T>::get(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES);
}
template <typename T>
inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
return ::capnproto::internal::PointerHelpers<T>::get(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES);
}
template <typename T>
inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(const typename T::Reader& value) {
return ::capnproto::internal::PointerHelpers<T>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value);
}
template <typename T>
inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}() {
return ::capnproto::internal::PointerHelpers<T>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES);
}
template <typename T>
inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(unsigned int size) {
return ::capnproto::internal::PointerHelpers<T>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, size);
}
{{/fieldIsGenericObject}}
{{/typeFields}} {{/typeFields}}
{{/typeStructOrUnion}} {{/typeStructOrUnion}}
{{/fileTypes}} {{/fileTypes}}
......
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