Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
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
rapidjson
Commits
43737ef3
Commit
43737ef3
authored
Jul 03, 2014
by
Philipp A. Hartmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GenericValue::FindMember: return MemberEnd, if member doesn't exist
parent
17a8804c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
21 deletions
+37
-21
document.h
include/rapidjson/document.h
+37
-21
No files found.
include/rapidjson/document.h
View file @
43737ef3
...
...
@@ -420,7 +420,8 @@ public:
A better approach is to use the now public FindMember().
*/
GenericValue
&
operator
[](
const
Ch
*
name
)
{
if
(
MemberIterator
member
=
FindMember
(
name
))
MemberIterator
member
=
FindMember
(
name
);
if
(
member
!=
MemberEnd
())
return
member
->
value
;
else
{
RAPIDJSON_ASSERT
(
false
);
// see above note
...
...
@@ -433,7 +434,8 @@ public:
// This version is faster because it does not need a StrLen().
// It can also handle string with null character.
GenericValue
&
operator
[](
const
GenericValue
&
name
)
{
if
(
Member
*
member
=
FindMember
(
name
))
MemberIterator
member
=
FindMember
(
name
);
if
(
member
!=
MemberEnd
())
return
member
->
value
;
else
{
RAPIDJSON_ASSERT
(
false
);
// see above note
...
...
@@ -443,37 +445,51 @@ public:
}
const
GenericValue
&
operator
[](
const
GenericValue
&
name
)
const
{
return
const_cast
<
GenericValue
&>
(
*
this
)[
name
];
}
//! Member iterators.
ConstMemberIterator
MemberBegin
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
members
;
}
ConstMemberIterator
MemberEnd
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
members
+
data_
.
o
.
size
;
}
MemberIterator
MemberBegin
()
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
members
;
}
MemberIterator
MemberEnd
()
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
members
+
data_
.
o
.
size
;
}
//! Const member iterator
/*! \pre IsObject() == true */
ConstMemberIterator
MemberBegin
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
ConstMemberIterator
(
data_
.
o
.
members
);
}
//! Const \em past-the-end member iterator
/*! \pre IsObject() == true */
ConstMemberIterator
MemberEnd
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
ConstMemberIterator
(
data_
.
o
.
members
+
data_
.
o
.
size
);
}
//! Member iterator
/*! \pre IsObject() == true */
MemberIterator
MemberBegin
()
{
RAPIDJSON_ASSERT
(
IsObject
());
return
MemberIterator
(
data_
.
o
.
members
);
}
//! \em Past-the-end member iterator
/*! \pre IsObject() == true */
MemberIterator
MemberEnd
()
{
RAPIDJSON_ASSERT
(
IsObject
());
return
MemberIterator
(
data_
.
o
.
members
+
data_
.
o
.
size
);
}
//! Check whether a member exists in the object.
/*!
\note It is better to use FindMember() directly if you need the obtain the value as well.
*/
bool
HasMember
(
const
Ch
*
name
)
const
{
return
FindMember
(
name
)
!=
0
;
}
bool
HasMember
(
const
Ch
*
name
)
const
{
return
FindMember
(
name
)
!=
MemberEnd
()
;
}
// This version is faster because it does not need a StrLen().
// It can also handle string with null character.
bool
HasMember
(
const
GenericValue
&
name
)
const
{
return
FindMember
(
name
)
!=
0
;
}
bool
HasMember
(
const
GenericValue
&
name
)
const
{
return
FindMember
(
name
)
!=
MemberEnd
()
;
}
//! Find member by name.
/*!
\return Return the member if exists. Otherwise returns null pointer.
\pre IsObject() == true
\return Iterator to member, if it exists.
Otherwise returns \ref MemberEnd().
\note Earlier versions of Rapidjson returned a \c NULL pointer, in case
the requested member doesn't exist. For consistency with e.g.
\c std::map, this has been changed to MemberEnd() now.
*/
MemberIterator
FindMember
(
const
Ch
*
name
)
{
RAPIDJSON_ASSERT
(
name
);
RAPIDJSON_ASSERT
(
IsObject
());
SizeType
len
=
internal
::
StrLen
(
name
);
for
(
MemberIterator
member
=
MemberBegin
();
member
!=
MemberEnd
();
++
member
)
MemberIterator
member
=
MemberBegin
();
for
(;
member
!=
MemberEnd
();
++
member
)
if
(
member
->
name
.
data_
.
s
.
length
==
len
&&
memcmp
(
member
->
name
.
data_
.
s
.
str
,
name
,
len
*
sizeof
(
Ch
))
==
0
)
return
member
;
return
0
;
break
;
return
member
;
}
ConstMemberIterator
FindMember
(
const
Ch
*
name
)
const
{
return
const_cast
<
GenericValue
&>
(
*
this
).
FindMember
(
name
);
}
// This version is faster because it does not need a StrLen().
...
...
@@ -482,11 +498,11 @@ public:
RAPIDJSON_ASSERT
(
IsObject
());
RAPIDJSON_ASSERT
(
name
.
IsString
());
SizeType
len
=
name
.
data_
.
s
.
length
;
for
(
MemberIterator
member
=
MemberBegin
();
member
!=
MemberEnd
();
++
member
)
MemberIterator
member
=
MemberBegin
();
for
(
;
member
!=
MemberEnd
();
++
member
)
if
(
member
->
name
.
data_
.
s
.
length
==
len
&&
memcmp
(
member
->
name
.
data_
.
s
.
str
,
name
.
data_
.
s
.
str
,
len
*
sizeof
(
Ch
))
==
0
)
return
member
;
return
0
;
break
;
return
member
;
}
ConstMemberIterator
FindMember
(
const
GenericValue
&
name
)
const
{
return
const_cast
<
GenericValue
&>
(
*
this
).
FindMember
(
name
);
}
...
...
@@ -543,7 +559,7 @@ public:
*/
bool
RemoveMember
(
const
Ch
*
name
)
{
MemberIterator
m
=
FindMember
(
name
);
if
(
m
)
{
if
(
m
!=
MemberEnd
()
)
{
RemoveMember
(
m
);
return
true
;
}
...
...
@@ -553,7 +569,7 @@ public:
bool
RemoveMember
(
const
GenericValue
&
name
)
{
MemberIterator
m
=
FindMember
(
name
);
if
(
m
)
{
if
(
m
!=
MemberEnd
()
)
{
RemoveMember
(
m
);
return
true
;
}
...
...
@@ -572,7 +588,7 @@ public:
RAPIDJSON_ASSERT
(
data_
.
o
.
members
!=
0
);
RAPIDJSON_ASSERT
(
m
>=
MemberBegin
()
&&
m
<
MemberEnd
());
MemberIterator
last
=
data_
.
o
.
members
+
(
data_
.
o
.
size
-
1
);
MemberIterator
last
(
data_
.
o
.
members
+
(
data_
.
o
.
size
-
1
)
);
if
(
data_
.
o
.
size
>
1
&&
m
!=
last
)
{
// Move the last one to this place
m
->
name
=
last
->
name
;
...
...
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