Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
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
flatbuffers
Commits
2dd6ba57
Commit
2dd6ba57
authored
Feb 01, 2017
by
Benjamin Lerman
Committed by
Wouter van Oortmerssen
Feb 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add utility method to build a vector of struct in-place. (#4153)
Change-Id: I6df195cbae621cf2bf6b4f3b56f68be80dc23152
parent
6cc2307c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
flatbuffers.h
include/flatbuffers/flatbuffers.h
+21
-0
No files found.
include/flatbuffers/flatbuffers.h
View file @
2dd6ba57
...
...
@@ -1128,6 +1128,27 @@ FLATBUFFERS_FINAL_CLASS
return
Offset
<
Vector
<
const
T
*>>
(
EndVector
(
len
));
}
#ifndef FLATBUFFERS_CPP98_STL
/// @brief Serialize an array of structs into a FlatBuffer `vector`.
/// @tparam T The data type of the struct array elements.
/// @param[in] f A function that takes the current iteration 0..vector_size-1
/// and a pointer to the struct that must be filled.
/// @return Returns a typed `Offset` into the serialized data indicating
/// where the vector is stored.
/// This is mostly useful when flatbuffers are generated with mutation
/// accessors.
template
<
typename
T
>
Offset
<
Vector
<
const
T
*>>
CreateVectorOfStructs
(
size_t
vector_size
,
const
std
::
function
<
void
(
size_t
i
,
T
*
)
>
&
filler
)
{
StartVector
(
vector_size
*
sizeof
(
T
)
/
AlignOf
<
T
>
(),
AlignOf
<
T
>
());
T
*
structs
=
reinterpret_cast
<
T
*>
(
buf_
.
make_space
(
vector_size
*
sizeof
(
T
)));
for
(
size_t
i
=
0
;
i
<
vector_size
;
i
++
)
{
filler
(
i
,
structs
);
structs
++
;
}
return
Offset
<
Vector
<
const
T
*>>
(
EndVector
(
vector_size
));
}
#endif
/// @brief Serialize a `std::vector` of structs into a FlatBuffer `vector`.
/// @tparam T The data type of the `std::vector` struct elements.
/// @param[in]] v A const reference to the `std::vector` of structs to
...
...
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