Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
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
protobuf
Commits
241921c6
Commit
241921c6
authored
Nov 25, 2014
by
Jisi Liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:google/protobuf
parents
e9bbfbcd
6ae3bde7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
10 deletions
+54
-10
map.h
src/google/protobuf/map.h
+6
-7
map_field.h
src/google/protobuf/map_field.h
+7
-0
map_field_inl.h
src/google/protobuf/map_field_inl.h
+9
-0
map_test.cc
src/google/protobuf/map_test.cc
+21
-0
map_unittest.proto
src/google/protobuf/map_unittest.proto
+5
-0
unknown_field_set.h
src/google/protobuf/unknown_field_set.h
+6
-3
No files found.
src/google/protobuf/map.h
View file @
241921c6
...
@@ -56,7 +56,7 @@ class MapField;
...
@@ -56,7 +56,7 @@ class MapField;
template
<
typename
Key
,
typename
T
>
template
<
typename
Key
,
typename
T
>
class
MapPair
{
class
MapPair
{
public
:
public
:
typedef
Key
first_type
;
typedef
const
Key
first_type
;
typedef
T
second_type
;
typedef
T
second_type
;
MapPair
(
const
Key
&
other_first
,
const
T
&
other_second
)
MapPair
(
const
Key
&
other_first
,
const
T
&
other_second
)
...
@@ -67,14 +67,13 @@ class MapPair {
...
@@ -67,14 +67,13 @@ class MapPair {
MapPair
(
const
MapPair
&
other
)
MapPair
(
const
MapPair
&
other
)
:
first
(
other
.
first
),
second
(
other
.
second
)
{}
:
first
(
other
.
first
),
second
(
other
.
second
)
{}
MapPair
&
operator
=
(
const
MapPair
&
other
)
{
first
=
other
.
first
;
second
=
other
.
second
;
return
*
this
;
}
~
MapPair
()
{}
~
MapPair
()
{}
// Implicitly convertible to std::pair.
operator
std
::
pair
<
const
Key
,
T
>
()
const
{
return
std
::
pair
<
const
Key
,
T
>
(
first
,
second
);
}
const
Key
first
;
const
Key
first
;
T
second
;
T
second
;
...
...
src/google/protobuf/map_field.h
View file @
241921c6
...
@@ -213,6 +213,13 @@ class LIBPROTOBUF_EXPORT MapField : public MapFieldBase {
...
@@ -213,6 +213,13 @@ class LIBPROTOBUF_EXPORT MapField : public MapFieldBase {
mutable
const
EntryType
*
default_entry_
;
mutable
const
EntryType
*
default_entry_
;
};
};
// True if IsInitialized() is true for value field in all elements of t. T is
// expected to be message. It's useful to have this helper here to keep the
// protobuf compiler from ever having to emit loops in IsInitialized() methods.
// We want the C++ compiler to inline this or not as it sees fit.
template
<
typename
Key
,
typename
T
>
bool
AllAreInitialized
(
const
Map
<
Key
,
T
>&
t
);
}
// namespace internal
}
// namespace internal
}
// namespace protobuf
}
// namespace protobuf
...
...
src/google/protobuf/map_field_inl.h
View file @
241921c6
...
@@ -262,6 +262,15 @@ void MapField<Key, T, KeyProto, ValueProto,
...
@@ -262,6 +262,15 @@ void MapField<Key, T, KeyProto, ValueProto,
}
}
}
}
template
<
typename
Key
,
typename
T
>
bool
AllAreInitialized
(
const
Map
<
Key
,
T
>&
t
)
{
for
(
typename
Map
<
Key
,
T
>::
const_iterator
it
=
t
.
begin
();
it
!=
t
.
end
();
++
it
)
{
if
(
!
it
->
second
.
IsInitialized
())
return
false
;
}
return
true
;
}
}
// namespace internal
}
// namespace internal
}
// namespace protobuf
}
// namespace protobuf
...
...
src/google/protobuf/map_test.cc
View file @
241921c6
...
@@ -544,6 +544,13 @@ TEST_F(MapImplTest, EqualRange) {
...
@@ -544,6 +544,13 @@ TEST_F(MapImplTest, EqualRange) {
EXPECT_TRUE
(
const_map_
.
end
()
==
const_range
.
second
);
EXPECT_TRUE
(
const_map_
.
end
()
==
const_range
.
second
);
}
}
TEST_F
(
MapImplTest
,
ConvertToStdMap
)
{
map_
[
100
]
=
101
;
std
::
map
<
int32
,
int32
>
std_map
(
map_
.
begin
(),
map_
.
end
());
EXPECT_EQ
(
1
,
std_map
.
size
());
EXPECT_EQ
(
101
,
std_map
[
100
]);
}
// Map Field Reflection Test ========================================
// Map Field Reflection Test ========================================
static
int
Func
(
int
i
,
int
j
)
{
static
int
Func
(
int
i
,
int
j
)
{
...
@@ -1740,6 +1747,20 @@ TEST(GeneratedMapFieldTest, MessageLiteMap) {
...
@@ -1740,6 +1747,20 @@ TEST(GeneratedMapFieldTest, MessageLiteMap) {
EXPECT_EQ
(
1
,
to
.
map_field
().
at
(
1
));
EXPECT_EQ
(
1
,
to
.
map_field
().
at
(
1
));
}
}
TEST
(
GeneratedMapFieldTest
,
IsInitialized
)
{
unittest
::
TestRequiredMessageMap
map_message
;
// Add an uninitialized message.
(
*
map_message
.
mutable_map_field
())[
0
];
EXPECT_FALSE
(
map_message
.
IsInitialized
());
// Initialize uninitialized message
(
*
map_message
.
mutable_map_field
())[
0
].
set_a
(
0
);
(
*
map_message
.
mutable_map_field
())[
0
].
set_b
(
0
);
(
*
map_message
.
mutable_map_field
())[
0
].
set_c
(
0
);
EXPECT_TRUE
(
map_message
.
IsInitialized
());
}
// Generated Message Reflection Test ================================
// Generated Message Reflection Test ================================
TEST
(
GeneratedMapFieldReflectionTest
,
SpaceUsed
)
{
TEST
(
GeneratedMapFieldReflectionTest
,
SpaceUsed
)
{
...
...
src/google/protobuf/map_unittest.proto
View file @
241921c6
...
@@ -75,3 +75,8 @@ enum MapEnum {
...
@@ -75,3 +75,8 @@ enum MapEnum {
MAP_ENUM_BAR
=
1
;
MAP_ENUM_BAR
=
1
;
MAP_ENUM_BAZ
=
2
;
MAP_ENUM_BAZ
=
2
;
}
}
// Test embeded message with required fields
message
TestRequiredMessageMap
{
map
<
int32
,
TestRequired
>
map_field
=
1
;
}
src/google/protobuf/unknown_field_set.h
View file @
241921c6
...
@@ -224,13 +224,16 @@ class LIBPROTOBUF_EXPORT UnknownField {
...
@@ -224,13 +224,16 @@ class LIBPROTOBUF_EXPORT UnknownField {
uint32
number_
;
uint32
number_
;
uint32
type_
;
uint32
type_
;
union
LengthDelimited
{
string
*
string_value_
;
};
union
{
union
{
uint64
varint_
;
uint64
varint_
;
uint32
fixed32_
;
uint32
fixed32_
;
uint64
fixed64_
;
uint64
fixed64_
;
mutable
union
{
mutable
union
LengthDelimited
length_delimited_
;
string
*
string_value_
;
}
length_delimited_
;
UnknownFieldSet
*
group_
;
UnknownFieldSet
*
group_
;
};
};
};
};
...
...
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