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
a8e99906
Commit
a8e99906
authored
Oct 19, 2017
by
h46incon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MemberCapacity() and MemberReserve() interface for object type.
parent
7d424c0b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
11 deletions
+22
-11
document.h
include/rapidjson/document.h
+22
-11
No files found.
include/rapidjson/document.h
View file @
a8e99906
...
...
@@ -1070,6 +1070,9 @@ public:
//! Get the number of members in the object.
SizeType
MemberCount
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
size
;
}
//! Get the capacity of object.
SizeType
MemberCapacity
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
capacity
;
}
//! Check whether the object is empty.
bool
ObjectEmpty
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
size
==
0
;
}
...
...
@@ -1138,6 +1141,21 @@ public:
/*! \pre IsObject() == true */
MemberIterator
MemberEnd
()
{
RAPIDJSON_ASSERT
(
IsObject
());
return
MemberIterator
(
GetMembersPointer
()
+
data_
.
o
.
size
);
}
//! Request the object to have enough capacity to store members.
/*! \param newCapacity The capacity that the object at least need to have.
\param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
\return The value itself for fluent API.
\note Linear time complexity.
*/
GenericValue
&
MemberReserve
(
SizeType
newCapacity
,
Allocator
&
allocator
)
{
RAPIDJSON_ASSERT
(
IsObject
());
if
(
newCapacity
>
data_
.
o
.
capacity
)
{
SetMembersPointer
(
reinterpret_cast
<
Member
*>
(
allocator
.
Realloc
(
GetMembersPointer
(),
data_
.
o
.
capacity
*
sizeof
(
Member
),
newCapacity
*
sizeof
(
Member
))));
data_
.
o
.
capacity
=
newCapacity
;
}
return
*
this
;
}
//! Check whether a member exists in the object.
/*!
\param name Member name to be searched.
...
...
@@ -1243,17 +1261,8 @@ public:
RAPIDJSON_ASSERT
(
name
.
IsString
());
ObjectData
&
o
=
data_
.
o
;
if
(
o
.
size
>=
o
.
capacity
)
{
if
(
o
.
capacity
==
0
)
{
o
.
capacity
=
kDefaultObjectCapacity
;
SetMembersPointer
(
reinterpret_cast
<
Member
*>
(
allocator
.
Malloc
(
o
.
capacity
*
sizeof
(
Member
))));
}
else
{
SizeType
oldCapacity
=
o
.
capacity
;
o
.
capacity
+=
(
oldCapacity
+
1
)
/
2
;
// grow by factor 1.5
SetMembersPointer
(
reinterpret_cast
<
Member
*>
(
allocator
.
Realloc
(
GetMembersPointer
(),
oldCapacity
*
sizeof
(
Member
),
o
.
capacity
*
sizeof
(
Member
))));
}
}
if
(
o
.
size
>=
o
.
capacity
)
MemberReserve
(
o
.
capacity
==
0
?
kDefaultObjectCapacity
:
(
o
.
capacity
+
(
o
.
capacity
+
1
)
/
2
),
allocator
);
Member
*
members
=
GetMembersPointer
();
members
[
o
.
size
].
name
.
RawAssign
(
name
);
members
[
o
.
size
].
value
.
RawAssign
(
value
);
...
...
@@ -2548,6 +2557,7 @@ public:
~
GenericObject
()
{}
SizeType
MemberCount
()
const
{
return
value_
.
MemberCount
();
}
SizeType
MemberCapacity
()
const
{
return
value_
.
MemberCapacity
();
}
bool
ObjectEmpty
()
const
{
return
value_
.
ObjectEmpty
();
}
template
<
typename
T
>
ValueType
&
operator
[](
T
*
name
)
const
{
return
value_
[
name
];
}
template
<
typename
SourceAllocator
>
ValueType
&
operator
[](
const
GenericValue
<
EncodingType
,
SourceAllocator
>&
name
)
const
{
return
value_
[
name
];
}
...
...
@@ -2556,6 +2566,7 @@ public:
#endif
MemberIterator
MemberBegin
()
const
{
return
value_
.
MemberBegin
();
}
MemberIterator
MemberEnd
()
const
{
return
value_
.
MemberEnd
();
}
GenericObject
MemberReserve
(
SizeType
newCapacity
,
AllocatorType
&
allocator
)
const
{
value_
.
MemberReserve
(
newCapacity
,
allocator
);
return
*
this
;
}
bool
HasMember
(
const
Ch
*
name
)
const
{
return
value_
.
HasMember
(
name
);
}
#if RAPIDJSON_HAS_STDSTRING
bool
HasMember
(
const
std
::
basic_string
<
Ch
>&
name
)
const
{
return
value_
.
HasMember
(
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