Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
08d73bef
Commit
08d73bef
authored
May 13, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor dynamic API using new schema API.
parent
e7b9e4da
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
238 additions
and
90 deletions
+238
-90
dynamic-test.c++
c++/src/capnproto/dynamic-test.c++
+162
-0
dynamic.c++
c++/src/capnproto/dynamic.c++
+0
-0
dynamic.h
c++/src/capnproto/dynamic.h
+0
-0
generated-header-support.h
c++/src/capnproto/generated-header-support.h
+2
-1
message.h
c++/src/capnproto/message.h
+7
-7
schema-test.c++
c++/src/capnproto/schema-test.c++
+15
-15
schema.c++
c++/src/capnproto/schema.c++
+9
-9
schema.h
c++/src/capnproto/schema.h
+16
-4
c++-header.mustache
compiler/src/c++-header.mustache
+27
-54
No files found.
c++/src/capnproto/dynamic-test.c++
0 → 100644
View file @
08d73bef
// 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
c++/src/capnproto/dynamic.c++
View file @
08d73bef
This diff is collapsed.
Click to expand it.
c++/src/capnproto/dynamic.h
View file @
08d73bef
This diff is collapsed.
Click to expand it.
c++/src/capnproto/generated-header-support.h
View file @
08d73bef
...
...
@@ -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.
...
...
c++/src/capnproto/message.h
View file @
08d73bef
...
...
@@ -37,7 +37,7 @@ namespace internal {
class
BuilderArena
;
}
class
S
chemaPool
;
class
S
tructSchema
;
// =======================================================================================
...
...
@@ -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.
...
...
c++/src/capnproto/schema-test.c++
View file @
08d73bef
...
...
@@ -67,9 +67,9 @@ TEST(Schema, Structs) {
EXPECT_ANY_THROW
(
schema
.
asEnum
());
EXPECT_ANY_THROW
(
schema
.
asInterface
());
ASSERT_EQ
(
schema
.
m
embers
().
size
(),
ASSERT_EQ
(
schema
.
getM
embers
().
size
(),
schema
.
getProto
().
getBody
().
getStructNode
().
getMembers
().
size
());
StructSchema
::
Member
member
=
schema
.
m
embers
()[
0
];
StructSchema
::
Member
member
=
schema
.
getM
embers
()[
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
.
m
embers
()[
1
]);
EXPECT_TRUE
(
*
lookup
!=
schema
.
getM
embers
()[
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
.
m
embers
()[
0
].
getProto
().
getName
());
EXPECT_EQ
(
"grault"
,
schema
.
m
embers
()[
1
].
getProto
().
getName
());
EXPECT_EQ
(
"bar"
,
schema
.
m
embers
()[
2
].
getProto
().
getName
());
EXPECT_EQ
(
"foo"
,
schema
.
m
embers
()[
3
].
getProto
().
getName
());
EXPECT_EQ
(
"corge"
,
schema
.
m
embers
()[
4
].
getProto
().
getName
());
EXPECT_EQ
(
"waldo"
,
schema
.
m
embers
()[
5
].
getProto
().
getName
());
EXPECT_EQ
(
"quux"
,
schema
.
m
embers
()[
6
].
getProto
().
getName
());
EXPECT_EQ
(
"garply"
,
schema
.
m
embers
()[
7
].
getProto
().
getName
());
EXPECT_EQ
(
"baz"
,
schema
.
m
embers
()[
8
].
getProto
().
getName
());
EXPECT_EQ
(
"qux"
,
schema
.
getM
embers
()[
0
].
getProto
().
getName
());
EXPECT_EQ
(
"grault"
,
schema
.
getM
embers
()[
1
].
getProto
().
getName
());
EXPECT_EQ
(
"bar"
,
schema
.
getM
embers
()[
2
].
getProto
().
getName
());
EXPECT_EQ
(
"foo"
,
schema
.
getM
embers
()[
3
].
getProto
().
getName
());
EXPECT_EQ
(
"corge"
,
schema
.
getM
embers
()[
4
].
getProto
().
getName
());
EXPECT_EQ
(
"waldo"
,
schema
.
getM
embers
()[
5
].
getProto
().
getName
());
EXPECT_EQ
(
"quux"
,
schema
.
getM
embers
()[
6
].
getProto
().
getName
());
EXPECT_EQ
(
"garply"
,
schema
.
getM
embers
()[
7
].
getProto
().
getName
());
EXPECT_EQ
(
"baz"
,
schema
.
getM
embers
()[
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
.
e
numerants
().
size
(),
ASSERT_EQ
(
schema
.
getE
numerants
().
size
(),
schema
.
getProto
().
getBody
().
getEnumNode
().
getEnumerants
().
size
());
EnumSchema
::
Enumerant
enumerant
=
schema
.
e
numerants
()[
0
];
EnumSchema
::
Enumerant
enumerant
=
schema
.
getE
numerants
()[
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
.
e
numerants
()[
1
]);
EXPECT_TRUE
(
*
lookup
!=
schema
.
getE
numerants
()[
1
]);
EXPECT_TRUE
(
schema
.
findEnumerantByName
(
"noSuchEnumerant"
)
==
nullptr
);
...
...
c++/src/capnproto/schema.c++
View file @
08d73bef
...
...
@@ -114,17 +114,17 @@ auto findSchemaMemberByName(const internal::RawSchema* raw, Text::Reader name,
}
// namespace
StructSchema
::
MemberList
StructSchema
::
m
embers
()
const
{
StructSchema
::
MemberList
StructSchema
::
getM
embers
()
const
{
return
MemberList
(
*
this
,
0
,
getProto
().
getBody
().
getStructNode
().
getMembers
());
}
Maybe
<
StructSchema
::
Member
>
StructSchema
::
findMemberByName
(
Text
::
Reader
name
)
const
{
return
findSchemaMemberByName
(
raw
,
name
,
0
,
m
embers
());
return
findSchemaMemberByName
(
raw
,
name
,
0
,
getM
embers
());
}
Maybe
<
StructSchema
::
Union
>
StructSchema
::
Member
::
getContainingUnion
()
const
{
if
(
unionIndex
==
0
)
return
nullptr
;
return
parent
.
m
embers
()[
unionIndex
-
1
].
asUnion
();
return
parent
.
getM
embers
()[
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
::
m
embers
()
const
{
StructSchema
::
MemberList
StructSchema
::
Union
::
getM
embers
()
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
,
m
embers
());
return
findSchemaMemberByName
(
parent
.
raw
,
name
,
index
+
1
,
getM
embers
());
}
// -------------------------------------------------------------------
EnumSchema
::
EnumerantList
EnumSchema
::
e
numerants
()
const
{
EnumSchema
::
EnumerantList
EnumSchema
::
getE
numerants
()
const
{
return
EnumerantList
(
*
this
,
getProto
().
getBody
().
getEnumNode
().
getEnumerants
());
}
Maybe
<
EnumSchema
::
Enumerant
>
EnumSchema
::
findEnumerantByName
(
Text
::
Reader
name
)
const
{
return
findSchemaMemberByName
(
raw
,
name
,
0
,
e
numerants
());
return
findSchemaMemberByName
(
raw
,
name
,
0
,
getE
numerants
());
}
// -------------------------------------------------------------------
InterfaceSchema
::
MethodList
InterfaceSchema
::
m
ethods
()
const
{
InterfaceSchema
::
MethodList
InterfaceSchema
::
getM
ethods
()
const
{
return
MethodList
(
*
this
,
getProto
().
getBody
().
getInterfaceNode
().
getMethods
());
}
Maybe
<
InterfaceSchema
::
Method
>
InterfaceSchema
::
findMethodByName
(
Text
::
Reader
name
)
const
{
return
findSchemaMemberByName
(
raw
,
name
,
0
,
m
ethods
());
return
findSchemaMemberByName
(
raw
,
name
,
0
,
getM
ethods
());
}
// =======================================================================================
...
...
c++/src/capnproto/schema.h
View file @
08d73bef
...
...
@@ -99,7 +99,7 @@ public:
class
Union
;
class
MemberList
;
MemberList
m
embers
()
const
;
MemberList
getM
embers
()
const
;
Maybe
<
Member
>
findMemberByName
(
Text
::
Reader
name
)
const
;
private
:
...
...
@@ -147,7 +147,7 @@ class StructSchema::Union: public Member {
public
:
Union
()
=
default
;
MemberList
m
embers
()
const
;
MemberList
getM
embers
()
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
e
numerants
()
const
;
EnumerantList
getE
numerants
()
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
m
ethods
()
const
;
MethodList
getM
ethods
()
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
>
());
}
...
...
compiler/src/c++-header.mustache
View file @
08d73bef
...
...
@@ -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 siz
e) {
inline
void
{{
typeFullName
}}
::Builder::set
{{
fieldTitleCase
}}
(typename T::Reader valu
e) {
{{#
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
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment