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
e02ceca5
Commit
e02ceca5
authored
Jun 02, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3891 from bog-dan-ro/master
More bit fields patches
parents
7d1f372b
3e52fecd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
flatbuffers.h
include/flatbuffers/flatbuffers.h
+5
-5
idl_gen_cpp.cpp
src/idl_gen_cpp.cpp
+12
-1
No files found.
include/flatbuffers/flatbuffers.h
View file @
e02ceca5
...
...
@@ -1485,21 +1485,17 @@ volatile __attribute__((weak)) const char *flatbuffer_version_string =
#endif // !defined(_WIN32) && !defined(__CYGWIN__)
#define DEFINE_BITMASK_OPERATORS(E)\
#define DEFINE_BITMASK_OPERATORS(E
, T
)\
inline E operator | (E lhs, E rhs){\
using T = std::underlying_type<E>::type;\
return E(T(lhs) | T(rhs));\
}\
inline E operator & (E lhs, E rhs){\
using T = std::underlying_type<E>::type;\
return E(T(lhs) & T(rhs));\
}\
inline E operator ^ (E lhs, E rhs){\
using T = std::underlying_type<E>::type;\
return E(T(lhs) ^ T(rhs));\
}\
inline E operator ~ (E lhs){\
using T = std::underlying_type<E>::type;\
return E(~T(lhs));\
}\
inline E operator |= (E &lhs, E rhs){\
...
...
@@ -1513,6 +1509,10 @@ volatile __attribute__((weak)) const char *flatbuffer_version_string =
inline E operator ^= (E &lhs, E rhs){\
lhs = lhs ^ rhs;\
return lhs;\
}\
inline bool operator !(E rhs) \
{\
return !bool(T(rhs)); \
}
/// @endcond
}
// namespace flatbuffers
...
...
src/idl_gen_cpp.cpp
View file @
e02ceca5
...
...
@@ -166,6 +166,7 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
if
(
parser
.
opts
.
scoped_enums
)
code
+=
" : "
+
GenTypeBasic
(
enum_def
.
underlying_type
,
false
);
code
+=
" {
\n
"
;
int64_t
anyv
=
0
;
EnumVal
*
minv
=
nullptr
,
*
maxv
=
nullptr
;
for
(
auto
it
=
enum_def
.
vals
.
vec
.
begin
();
it
!=
enum_def
.
vals
.
vec
.
end
();
...
...
@@ -176,15 +177,25 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
code
+=
NumToString
(
ev
.
value
)
+
",
\n
"
;
minv
=
!
minv
||
minv
->
value
>
ev
.
value
?
&
ev
:
minv
;
maxv
=
!
maxv
||
maxv
->
value
<
ev
.
value
?
&
ev
:
maxv
;
anyv
|=
ev
.
value
;
}
if
(
parser
.
opts
.
scoped_enums
||
parser
.
opts
.
prefixed_enums
)
{
assert
(
minv
&&
maxv
);
if
(
enum_def
.
attributes
.
Lookup
(
"bit_flags"
))
{
if
(
minv
->
value
!=
0
)
// If the user didn't defined NONE value
code
+=
" "
+
GenEnumVal
(
enum_def
,
"NONE"
,
parser
.
opts
)
+
" = 0,
\n
"
;
if
(
maxv
->
value
!=
anyv
)
// If the user didn't defined ANY value
code
+=
" "
+
GenEnumVal
(
enum_def
,
"ANY"
,
parser
.
opts
)
+
" = "
+
NumToString
(
anyv
)
+
"
\n
"
;
}
else
{
// MIN & MAX are useless for bit_flags
code
+=
" "
+
GenEnumVal
(
enum_def
,
"MIN"
,
parser
.
opts
)
+
" = "
;
code
+=
GenEnumVal
(
enum_def
,
minv
->
name
,
parser
.
opts
)
+
",
\n
"
;
code
+=
" "
+
GenEnumVal
(
enum_def
,
"MAX"
,
parser
.
opts
)
+
" = "
;
code
+=
GenEnumVal
(
enum_def
,
maxv
->
name
,
parser
.
opts
)
+
"
\n
"
;
}
}
code
+=
"};
\n
"
;
if
(
parser
.
opts
.
scoped_enums
&&
enum_def
.
attributes
.
Lookup
(
"bit_flags"
))
code
+=
"DEFINE_BITMASK_OPERATORS("
+
enum_def
.
name
+
")
\n
"
;
code
+=
"DEFINE_BITMASK_OPERATORS("
+
enum_def
.
name
+
"
, "
+
GenTypeBasic
(
enum_def
.
underlying_type
,
false
)
+
"
)
\n
"
;
code
+=
"
\n
"
;
// Generate a generate string table for enum values.
...
...
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