Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
18e0430b
Unverified
Commit
18e0430b
authored
Jul 22, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
adding destroy function to discard values
parent
5b5f0090
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
35 deletions
+45
-35
json.hpp
src/json.hpp
+45
-35
No files found.
src/json.hpp
View file @
18e0430b
...
@@ -3172,6 +3172,7 @@ class parser
...
@@ -3172,6 +3172,7 @@ class parser
// start with a discarded value
// start with a discarded value
if
(
not
result
.
is_discarded
())
if
(
not
result
.
is_discarded
())
{
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
result
.
m_type
=
value_t
::
discarded
;
}
}
...
@@ -3194,6 +3195,7 @@ class parser
...
@@ -3194,6 +3195,7 @@ class parser
{
{
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
result
.
m_type
=
value_t
::
discarded
;
}
}
break
;
break
;
...
@@ -3227,7 +3229,8 @@ class parser
...
@@ -3227,7 +3229,8 @@ class parser
// parse and add value
// parse and add value
get_token
();
get_token
();
value
=
value_t
::
discarded
;
value
.
m_value
.
destroy
(
value
.
m_type
);
value
.
m_type
=
value_t
::
discarded
;
parse_internal
(
keep
,
value
);
parse_internal
(
keep
,
value
);
if
(
keep
and
keep_tag
and
not
value
.
is_discarded
())
if
(
keep
and
keep_tag
and
not
value
.
is_discarded
())
{
{
...
@@ -3249,6 +3252,7 @@ class parser
...
@@ -3249,6 +3252,7 @@ class parser
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
result
.
m_type
=
value_t
::
discarded
;
}
}
break
;
break
;
...
@@ -3271,6 +3275,7 @@ class parser
...
@@ -3271,6 +3275,7 @@ class parser
{
{
if
(
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
result
.
m_type
=
value_t
::
discarded
;
}
}
break
;
break
;
...
@@ -3281,7 +3286,8 @@ class parser
...
@@ -3281,7 +3286,8 @@ class parser
while
(
true
)
while
(
true
)
{
{
// parse value
// parse value
value
=
value_t
::
discarded
;
value
.
m_value
.
destroy
(
value
.
m_type
);
value
.
m_type
=
value_t
::
discarded
;
parse_internal
(
keep
,
value
);
parse_internal
(
keep
,
value
);
if
(
keep
and
not
value
.
is_discarded
())
if
(
keep
and
not
value
.
is_discarded
())
{
{
...
@@ -3303,6 +3309,7 @@ class parser
...
@@ -3303,6 +3309,7 @@ class parser
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
{
result
.
m_value
.
destroy
(
result
.
m_type
);
result
.
m_type
=
value_t
::
discarded
;
result
.
m_type
=
value_t
::
discarded
;
}
}
break
;
break
;
...
@@ -8278,6 +8285,41 @@ class basic_json
...
@@ -8278,6 +8285,41 @@ class basic_json
{
{
array
=
create
<
array_t
>
(
value
);
array
=
create
<
array_t
>
(
value
);
}
}
void
destroy
(
value_t
t
)
{
switch
(
t
)
{
case
value_t
:
:
object
:
{
AllocatorType
<
object_t
>
alloc
;
alloc
.
destroy
(
object
);
alloc
.
deallocate
(
object
,
1
);
break
;
}
case
value_t
:
:
array
:
{
AllocatorType
<
array_t
>
alloc
;
alloc
.
destroy
(
array
);
alloc
.
deallocate
(
array
,
1
);
break
;
}
case
value_t
:
:
string
:
{
AllocatorType
<
string_t
>
alloc
;
alloc
.
destroy
(
string
);
alloc
.
deallocate
(
string
,
1
);
break
;
}
default
:
{
break
;
}
}
}
};
};
/*!
/*!
...
@@ -9026,39 +9068,7 @@ class basic_json
...
@@ -9026,39 +9068,7 @@ class basic_json
~
basic_json
()
~
basic_json
()
{
{
assert_invariant
();
assert_invariant
();
m_value
.
destroy
(
m_type
);
switch
(
m_type
)
{
case
value_t
:
:
object
:
{
AllocatorType
<
object_t
>
alloc
;
alloc
.
destroy
(
m_value
.
object
);
alloc
.
deallocate
(
m_value
.
object
,
1
);
break
;
}
case
value_t
:
:
array
:
{
AllocatorType
<
array_t
>
alloc
;
alloc
.
destroy
(
m_value
.
array
);
alloc
.
deallocate
(
m_value
.
array
,
1
);
break
;
}
case
value_t
:
:
string
:
{
AllocatorType
<
string_t
>
alloc
;
alloc
.
destroy
(
m_value
.
string
);
alloc
.
deallocate
(
m_value
.
string
,
1
);
break
;
}
default
:
{
// all other types need no specific destructor
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