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
e4784bc8
Commit
e4784bc8
authored
May 09, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various refactoring and cleanup.
parent
f017105e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
63 additions
and
38 deletions
+63
-38
generated-header-support.h
c++/src/capnproto/generated-header-support.h
+22
-11
layout.c++
c++/src/capnproto/layout.c++
+37
-21
layout.h
c++/src/capnproto/layout.h
+0
-0
list.h
c++/src/capnproto/list.h
+0
-0
message.h
c++/src/capnproto/message.h
+2
-2
type-safety.h
c++/src/capnproto/type-safety.h
+2
-2
c++-header.mustache
compiler/src/c++-header.mustache
+0
-0
c++-source.mustache
compiler/src/c++-source.mustache
+0
-2
No files found.
c++/src/capnproto/generated-header-support.h
View file @
e4784bc8
...
...
@@ -41,10 +41,10 @@ struct PointerHelpers {
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
));
return
typename
T
::
Builder
(
builder
.
getStructField
(
index
,
structSize
<
T
>
()
,
nullptr
));
}
static
inline
typename
T
::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
typename
T
::
Builder
(
builder
.
initStructField
(
index
,
T
::
STRUCT_SIZE
));
return
typename
T
::
Builder
(
builder
.
initStructField
(
index
,
structSize
<
T
>
()
));
}
};
...
...
@@ -65,36 +65,36 @@ struct PointerHelpers<List<T>> {
template
<>
struct
PointerHelpers
<
Text
>
{
static
inline
Text
::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
)
{
return
reader
.
get
TextField
(
index
,
nullptr
,
0
*
BYTES
);
return
reader
.
get
BlobField
<
Text
>
(
index
,
nullptr
,
0
*
BYTES
);
}
static
inline
Text
::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
builder
.
get
TextField
(
index
,
nullptr
,
0
*
BYTES
);
return
builder
.
get
BlobField
<
Text
>
(
index
,
nullptr
,
0
*
BYTES
);
}
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
Text
::
Reader
value
)
{
builder
.
set
TextField
(
index
,
value
);
builder
.
set
BlobField
<
Text
>
(
index
,
value
);
}
static
inline
Text
::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
,
int
size
)
{
return
builder
.
init
TextField
(
index
,
size
*
BYTES
);
return
builder
.
init
BlobField
<
Text
>
(
index
,
size
*
BYTES
);
}
};
template
<>
struct
PointerHelpers
<
Data
>
{
static
inline
Data
::
Reader
get
(
StructReader
reader
,
WireReferenceCount
index
)
{
return
reader
.
get
DataField
(
index
,
nullptr
,
0
*
BYTES
);
return
reader
.
get
BlobField
<
Data
>
(
index
,
nullptr
,
0
*
BYTES
);
}
static
inline
Data
::
Builder
get
(
StructBuilder
builder
,
WireReferenceCount
index
)
{
return
builder
.
get
DataField
(
index
,
nullptr
,
0
*
BYTES
);
return
builder
.
get
BlobField
<
Data
>
(
index
,
nullptr
,
0
*
BYTES
);
}
static
inline
void
set
(
StructBuilder
builder
,
WireReferenceCount
index
,
Data
::
Reader
value
)
{
builder
.
set
DataField
(
index
,
value
);
builder
.
set
BlobField
<
Data
>
(
index
,
value
);
}
static
inline
Data
::
Builder
init
(
StructBuilder
builder
,
WireReferenceCount
index
,
int
size
)
{
return
builder
.
init
DataField
(
index
,
size
*
BYTES
);
return
builder
.
init
BlobField
<
Data
>
(
index
,
size
*
BYTES
);
}
};
#if
def CAPNPROTO_PRIVATE
#if
defined(CAPNPROTO_PRIVATE) || defined(__CDT_PARSER__)
struct
TrustedMessage
{
typedef
const
word
*
Reader
;
...
...
@@ -116,4 +116,15 @@ struct PointerHelpers<TrustedMessage> {
}
// namespace internal
}
// namespace capnproto
#define CAPNPROTO_DECLARE_ENUM(type) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::ENUM; }
#define CAPNPROTO_DECLARE_STRUCT(type, dataWordSize, pointerCount, preferredElementEncoding) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSizeFor<type> { \
static constexpr StructSize value = StructSize( \
dataWordSize * WORDS, pointerCount * REFERENCES, FieldSize::preferredElementEncoding); \
}
#define CAPNPROTO_DECLARE_INTERFACE(type) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::INTERFACE; }
#endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_
c++/src/capnproto/layout.c++
View file @
e4784bc8
...
...
@@ -1119,25 +1119,31 @@ ListBuilder StructBuilder::getListField(
references
+
refIndex
,
segment
,
defaultValue
);
}
Text
::
Builder
StructBuilder
::
initTextField
(
WireReferenceCount
refIndex
,
ByteCount
size
)
const
{
template
<>
Text
::
Builder
StructBuilder
::
initBlobField
<
Text
>
(
WireReferenceCount
refIndex
,
ByteCount
size
)
const
{
return
WireHelpers
::
initTextReference
(
references
+
refIndex
,
segment
,
size
);
}
void
StructBuilder
::
setTextField
(
WireReferenceCount
refIndex
,
Text
::
Reader
value
)
const
{
template
<>
void
StructBuilder
::
setBlobField
<
Text
>
(
WireReferenceCount
refIndex
,
Text
::
Reader
value
)
const
{
WireHelpers
::
setTextReference
(
references
+
refIndex
,
segment
,
value
);
}
Text
::
Builder
StructBuilder
::
getTextField
(
template
<>
Text
::
Builder
StructBuilder
::
getBlobField
<
Text
>
(
WireReferenceCount
refIndex
,
const
void
*
defaultValue
,
ByteCount
defaultSize
)
const
{
return
WireHelpers
::
getWritableTextReference
(
references
+
refIndex
,
segment
,
defaultValue
,
defaultSize
);
}
Data
::
Builder
StructBuilder
::
initDataField
(
WireReferenceCount
refIndex
,
ByteCount
size
)
const
{
template
<>
Data
::
Builder
StructBuilder
::
initBlobField
<
Data
>
(
WireReferenceCount
refIndex
,
ByteCount
size
)
const
{
return
WireHelpers
::
initDataReference
(
references
+
refIndex
,
segment
,
size
);
}
void
StructBuilder
::
setDataField
(
WireReferenceCount
refIndex
,
Data
::
Reader
value
)
const
{
template
<>
void
StructBuilder
::
setBlobField
<
Data
>
(
WireReferenceCount
refIndex
,
Data
::
Reader
value
)
const
{
WireHelpers
::
setDataReference
(
references
+
refIndex
,
segment
,
value
);
}
Data
::
Builder
StructBuilder
::
getDataField
(
template
<>
Data
::
Builder
StructBuilder
::
getBlobField
<
Data
>
(
WireReferenceCount
refIndex
,
const
void
*
defaultValue
,
ByteCount
defaultSize
)
const
{
return
WireHelpers
::
getWritableDataReference
(
references
+
refIndex
,
segment
,
defaultValue
,
defaultSize
);
...
...
@@ -1148,11 +1154,6 @@ ObjectBuilder StructBuilder::getObjectField(
return
WireHelpers
::
getWritableObjectReference
(
segment
,
references
+
refIndex
,
defaultValue
);
}
const
word
*
StructBuilder
::
getTrustedPointer
(
WireReferenceCount
refIndex
)
const
{
PRECOND
(
segment
==
nullptr
,
"getTrustedPointer() only allowed on trusted messages."
);
return
reinterpret_cast
<
const
word
*>
(
references
+
refIndex
);
}
StructReader
StructBuilder
::
asReader
()
const
{
return
StructReader
(
segment
,
data
,
references
,
dataSize
,
referenceCount
,
bit0Offset
,
std
::
numeric_limits
<
int
>::
max
());
...
...
@@ -1190,13 +1191,15 @@ ListReader StructReader::getListField(
segment
,
ref
,
defaultValue
,
expectedElementSize
,
nestingLimit
);
}
Text
::
Reader
StructReader
::
getTextField
(
template
<>
Text
::
Reader
StructReader
::
getBlobField
<
Text
>
(
WireReferenceCount
refIndex
,
const
void
*
defaultValue
,
ByteCount
defaultSize
)
const
{
const
WireReference
*
ref
=
refIndex
>=
referenceCount
?
nullptr
:
references
+
refIndex
;
return
WireHelpers
::
readTextReference
(
segment
,
ref
,
defaultValue
,
defaultSize
);
}
Data
::
Reader
StructReader
::
getDataField
(
template
<>
Data
::
Reader
StructReader
::
getBlobField
<
Data
>
(
WireReferenceCount
refIndex
,
const
void
*
defaultValue
,
ByteCount
defaultSize
)
const
{
const
WireReference
*
ref
=
refIndex
>=
referenceCount
?
nullptr
:
references
+
refIndex
;
return
WireHelpers
::
readDataReference
(
segment
,
ref
,
defaultValue
,
defaultSize
);
...
...
@@ -1208,6 +1211,11 @@ ObjectReader StructReader::getObjectField(
segment
,
references
+
refIndex
,
defaultValue
,
nestingLimit
);
}
const
word
*
StructReader
::
getTrustedPointer
(
WireReferenceCount
refIndex
)
const
{
PRECOND
(
segment
==
nullptr
,
"getTrustedPointer() only allowed on trusted messages."
);
return
reinterpret_cast
<
const
word
*>
(
references
+
refIndex
);
}
// =======================================================================================
// ListBuilder
...
...
@@ -1269,28 +1277,34 @@ ListBuilder ListBuilder::getListElement(ElementCount index) const {
reinterpret_cast
<
WireReference
*>
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
segment
,
nullptr
);
}
Text
::
Builder
ListBuilder
::
initTextElement
(
ElementCount
index
,
ByteCount
size
)
const
{
template
<>
Text
::
Builder
ListBuilder
::
initBlobElement
<
Text
>
(
ElementCount
index
,
ByteCount
size
)
const
{
return
WireHelpers
::
initTextReference
(
reinterpret_cast
<
WireReference
*>
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
segment
,
size
);
}
void
ListBuilder
::
setTextElement
(
ElementCount
index
,
Text
::
Reader
value
)
const
{
template
<>
void
ListBuilder
::
setBlobElement
<
Text
>
(
ElementCount
index
,
Text
::
Reader
value
)
const
{
WireHelpers
::
setTextReference
(
reinterpret_cast
<
WireReference
*>
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
segment
,
value
);
}
Text
::
Builder
ListBuilder
::
getTextElement
(
ElementCount
index
)
const
{
template
<>
Text
::
Builder
ListBuilder
::
getBlobElement
<
Text
>
(
ElementCount
index
)
const
{
return
WireHelpers
::
getWritableTextReference
(
reinterpret_cast
<
WireReference
*>
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
segment
,
""
,
0
*
BYTES
);
}
Data
::
Builder
ListBuilder
::
initDataElement
(
ElementCount
index
,
ByteCount
size
)
const
{
template
<>
Data
::
Builder
ListBuilder
::
initBlobElement
<
Data
>
(
ElementCount
index
,
ByteCount
size
)
const
{
return
WireHelpers
::
initDataReference
(
reinterpret_cast
<
WireReference
*>
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
segment
,
size
);
}
void
ListBuilder
::
setDataElement
(
ElementCount
index
,
Data
::
Reader
value
)
const
{
template
<>
void
ListBuilder
::
setBlobElement
<
Data
>
(
ElementCount
index
,
Data
::
Reader
value
)
const
{
WireHelpers
::
setDataReference
(
reinterpret_cast
<
WireReference
*>
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
segment
,
value
);
}
Data
::
Builder
ListBuilder
::
getDataElement
(
ElementCount
index
)
const
{
template
<>
Data
::
Builder
ListBuilder
::
getBlobElement
<
Data
>
(
ElementCount
index
)
const
{
return
WireHelpers
::
getWritableDataReference
(
reinterpret_cast
<
WireReference
*>
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
segment
,
nullptr
,
0
*
BYTES
);
...
...
@@ -1375,13 +1389,15 @@ ListReader ListReader::getListElement(
nullptr
,
expectedElementSize
,
nestingLimit
);
}
Text
::
Reader
ListReader
::
getTextElement
(
ElementCount
index
)
const
{
template
<>
Text
::
Reader
ListReader
::
getBlobElement
<
Text
>
(
ElementCount
index
)
const
{
return
WireHelpers
::
readTextReference
(
segment
,
checkAlignment
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
""
,
0
*
BYTES
);
}
Data
::
Reader
ListReader
::
getDataElement
(
ElementCount
index
)
const
{
template
<>
Data
::
Reader
ListReader
::
getBlobElement
<
Data
>
(
ElementCount
index
)
const
{
return
WireHelpers
::
readDataReference
(
segment
,
checkAlignment
(
ptr
+
index
*
step
/
BITS_PER_BYTE
),
nullptr
,
0
*
BYTES
);
...
...
c++/src/capnproto/layout.h
View file @
e4784bc8
This diff is collapsed.
Click to expand it.
c++/src/capnproto/list.h
View file @
e4784bc8
This diff is collapsed.
Click to expand it.
c++/src/capnproto/message.h
View file @
e4784bc8
...
...
@@ -275,12 +275,12 @@ inline typename RootType::Reader MessageReader::getRoot() {
template
<
typename
RootType
>
inline
typename
RootType
::
Builder
MessageBuilder
::
initRoot
()
{
return
typename
RootType
::
Builder
(
initRoot
(
RootType
::
STRUCT_SIZE
));
return
typename
RootType
::
Builder
(
initRoot
(
internal
::
structSize
<
RootType
>
()
));
}
template
<
typename
RootType
>
inline
typename
RootType
::
Builder
MessageBuilder
::
getRoot
()
{
return
typename
RootType
::
Builder
(
getRoot
(
RootType
::
STRUCT_SIZE
));
return
typename
RootType
::
Builder
(
getRoot
(
internal
::
structSize
<
RootType
>
()
));
}
template
<
typename
RootType
>
...
...
c++/src/capnproto/type-safety.h
View file @
e4784bc8
...
...
@@ -81,7 +81,7 @@ T instance() noexcept;
// definition. So...
namespace
internal
{
struct
PlacementNew
{}
placementNew
;
struct
PlacementNew
{};
}
// namespace internal;
}
// namespace capnproto
...
...
@@ -93,7 +93,7 @@ namespace capnproto {
template
<
typename
T
,
typename
...
Params
>
void
constructAt
(
T
*
location
,
Params
&&
...
params
)
{
new
(
internal
::
placementNew
,
location
)
T
(
capnproto
::
forward
<
Params
>
(
params
)...);
new
(
internal
::
PlacementNew
()
,
location
)
T
(
capnproto
::
forward
<
Params
>
(
params
)...);
}
// =======================================================================================
...
...
compiler/src/c++-header.mustache
View file @
e4784bc8
This diff is collapsed.
Click to expand it.
compiler/src/c++-source.mustache
View file @
e4784bc8
...
...
@@ -34,8 +34,6 @@ namespace {{namespaceName}} {
{{#
fileTypes
}}
{{#
typeStructOrUnion
}}
{{#
typeStruct
}}
constexpr ::capnproto::internal::StructSize
{{
structFullName
}}
::STRUCT_SIZE;
{{#
structFields
}}
{{#
fieldDefaultBytes
}}
const ::capnproto::internal::AlignedData
<
{{
defaultWordCount
}}
>
...
...
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