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
c967515d
Commit
c967515d
authored
Jun 17, 2015
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small improvements to the C++ API.
Change-Id: Ib30ffbbd140a8b82fe664129fa4e8c55836267f8 Tested: on Linux.
parent
576022c6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
5 deletions
+16
-5
flatbuffers.h
include/flatbuffers/flatbuffers.h
+12
-1
reflection.h
include/flatbuffers/reflection.h
+1
-1
sample_binary.cpp
samples/sample_binary.cpp
+1
-1
idl_gen_text.cpp
src/idl_gen_text.cpp
+2
-2
No files found.
include/flatbuffers/flatbuffers.h
View file @
c967515d
...
...
@@ -273,6 +273,8 @@ public:
return
IndirectHelper
<
T
>::
Read
(
Data
(),
i
);
}
return_type
operator
[](
uoffset_t
i
)
const
{
return
Get
(
i
);
}
// If this is a Vector of enums, T will be its storage type, not the enum
// type. This function makes it convenient to retrieve value with enum
// type E.
...
...
@@ -293,7 +295,7 @@ public:
// Change elements if you have a non-const pointer to this object.
void
Mutate
(
uoffset_t
i
,
T
val
)
{
assert
(
i
<
size
());
WriteScalar
(
Data
()
+
i
*
sizeof
(
T
)
,
val
);
WriteScalar
(
data
()
+
i
,
val
);
}
// The raw data in little endian format. Use with care.
...
...
@@ -305,6 +307,10 @@ public:
return
reinterpret_cast
<
uint8_t
*>
(
&
length_
+
1
);
}
// Similarly, but typed, much like std::vector::data
const
T
*
data
()
const
{
return
reinterpret_cast
<
const
T
*>
(
Data
());
}
T
*
data
()
{
return
reinterpret_cast
<
T
*>
(
Data
());
}
template
<
typename
K
>
return_type
LookupByKey
(
K
key
)
const
{
void
*
search_result
=
std
::
bsearch
(
&
key
,
Data
(),
size
(),
IndirectHelper
<
T
>::
element_stride
,
KeyCompare
<
K
>
);
...
...
@@ -345,6 +351,7 @@ template<typename T> static inline size_t VectorLength(const Vector<T> *v) {
struct
String
:
public
Vector
<
char
>
{
const
char
*
c_str
()
const
{
return
reinterpret_cast
<
const
char
*>
(
Data
());
}
std
::
string
str
()
const
{
return
c_str
();
}
bool
operator
<
(
const
String
&
o
)
const
{
return
strcmp
(
c_str
(),
o
.
c_str
())
<
0
;
...
...
@@ -509,6 +516,10 @@ class FlatBufferBuilder FLATBUFFERS_FINAL_CLASS {
// Get the released pointer to the serialized buffer.
// Don't attempt to use this FlatBufferBuilder afterwards!
// The unique_ptr returned has a special allocator that knows how to
// deallocate this pointer (since it points to the middle of an allocation).
// Thus, do not mix this pointer with other unique_ptr's, or call release() /
// reset() on it.
unique_ptr_t
ReleaseBufferPointer
()
{
return
buf_
.
release
();
}
void
ForceDefaults
(
bool
fd
)
{
force_defaults_
=
fd
;
}
...
...
include/flatbuffers/reflection.h
View file @
c967515d
...
...
@@ -313,7 +313,7 @@ class ResizeContext {
auto
enumdef
=
schema_
.
enums
()
->
Get
(
fielddef
->
type
()
->
index
());
// TODO: this is clumsy and slow, but no other way to find it?
auto
type_field
=
fielddefs
->
LookupByKey
(
(
fielddef
->
name
()
->
c_str
()
+
std
::
string
(
"_type"
)
).
c_str
());
(
fielddef
->
name
()
->
str
()
+
"_type"
).
c_str
());
assert
(
type_field
);
auto
union_type
=
GetFieldI
<
uint8_t
>
(
table
,
type_field
);
auto
enumval
=
enumdef
->
values
()
->
LookupByKey
(
union_type
);
...
...
samples/sample_binary.cpp
View file @
c967515d
...
...
@@ -49,7 +49,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
assert
(
monster
->
hp
()
==
80
);
assert
(
monster
->
mana
()
==
150
);
// default
assert
(
!
strcmp
(
monster
->
name
()
->
c_str
(),
"MyMonster"
)
);
assert
(
monster
->
name
()
->
str
()
==
"MyMonster"
);
auto
pos
=
monster
->
pos
();
assert
(
pos
);
...
...
src/idl_gen_text.cpp
View file @
c967515d
...
...
@@ -80,7 +80,7 @@ template<typename T> void PrintVector(const Vector<T> &v, Type type,
Print
(
v
.
GetStructFromOffset
(
i
*
type
.
struct_def
->
bytesize
),
type
,
indent
+
Indent
(
opts
),
nullptr
,
opts
,
_text
);
else
Print
(
v
.
Get
(
i
)
,
type
,
indent
+
Indent
(
opts
),
nullptr
,
Print
(
v
[
i
]
,
type
,
indent
+
Indent
(
opts
),
nullptr
,
opts
,
_text
);
}
text
+=
NewLine
(
opts
);
...
...
@@ -92,7 +92,7 @@ static void EscapeString(const String &s, std::string *_text) {
std
::
string
&
text
=
*
_text
;
text
+=
"
\"
"
;
for
(
uoffset_t
i
=
0
;
i
<
s
.
size
();
i
++
)
{
char
c
=
s
.
Get
(
i
)
;
char
c
=
s
[
i
]
;
switch
(
c
)
{
case
'\n'
:
text
+=
"
\\
n"
;
break
;
case
'\t'
:
text
+=
"
\\
t"
;
break
;
...
...
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