Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
8e9714fe
Unverified
Commit
8e9714fe
authored
Aug 14, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add detail/json_ref.hpp
parent
a3473fda
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
58 deletions
+69
-58
Makefile
Makefile
+2
-1
src/detail/json_ref.hpp
src/detail/json_ref.hpp
+66
-0
src/json.hpp
src/json.hpp
+1
-57
No files found.
Makefile
View file @
8e9714fe
...
...
@@ -21,7 +21,8 @@ SRCS = ${SRCDIR}/json.hpp \
${SRCDIR}
/detail/parsing/output_adapters.hpp
\
${SRCDIR}
/detail/parsing/binary_reader.hpp
\
${SRCDIR}
/detail/parsing/binary_writer.hpp
\
${SRCDIR}
/detail/serializer.hpp
${SRCDIR}
/detail/serializer.hpp
\
${SRCDIR}
/detail/json_ref.hpp
# main target
all
:
...
...
src/detail/json_ref.hpp
0 → 100644
View file @
8e9714fe
#ifndef NLOHMANN_JSON_DETAIL_JSON_REF_HPP
#define NLOHMANN_JSON_DETAIL_JSON_REF_HPP
#include <initializer_list>
#include <utility>
namespace
nlohmann
{
namespace
detail
{
template
<
typename
BasicJsonType
>
class
json_ref
{
public:
using
value_type
=
BasicJsonType
;
json_ref
(
value_type
&&
value
)
:
owned_value
(
std
::
move
(
value
)),
value_ref
(
&
owned_value
),
is_rvalue
(
true
)
{}
json_ref
(
const
value_type
&
value
)
:
value_ref
(
const_cast
<
value_type
*>
(
&
value
)),
is_rvalue
(
false
)
{}
json_ref
(
std
::
initializer_list
<
json_ref
>
init
)
:
owned_value
(
init
),
value_ref
(
&
owned_value
),
is_rvalue
(
true
)
{}
template
<
class
...
Args
>
json_ref
(
Args
&&
...
args
)
:
owned_value
(
std
::
forward
<
Args
>
(
args
)...),
value_ref
(
&
owned_value
),
is_rvalue
(
true
)
{}
// class should be movable only
json_ref
(
json_ref
&&
)
=
default
;
json_ref
(
const
json_ref
&
)
=
delete
;
json_ref
&
operator
=
(
const
json_ref
&
)
=
delete
;
value_type
moved_or_copied
()
const
{
if
(
is_rvalue
)
{
return
std
::
move
(
*
value_ref
);
}
return
*
value_ref
;
}
value_type
const
&
operator
*
()
const
{
return
*
static_cast
<
value_type
const
*>
(
value_ref
);
}
value_type
const
*
operator
->
()
const
{
return
static_cast
<
value_type
const
*>
(
value_ref
);
}
private:
mutable
value_type
owned_value
=
nullptr
;
value_type
*
value_ref
=
nullptr
;
const
bool
is_rvalue
;
};
}
}
#endif
src/json.hpp
View file @
8e9714fe
...
...
@@ -69,6 +69,7 @@ SOFTWARE.
#include "detail/parsing/binary_reader.hpp"
#include "detail/parsing/binary_writer.hpp"
#include "detail/serializer.hpp"
#include "detail/json_ref.hpp"
/*!
@brief namespace for Niels Lohmann
...
...
@@ -77,63 +78,6 @@ SOFTWARE.
*/
namespace
nlohmann
{
namespace
detail
{
template
<
typename
BasicJsonType
>
class
json_ref
{
public:
using
value_type
=
BasicJsonType
;
json_ref
(
value_type
&&
value
)
:
owned_value
(
std
::
move
(
value
)),
value_ref
(
&
owned_value
),
is_rvalue
(
true
)
{}
json_ref
(
const
value_type
&
value
)
:
value_ref
(
const_cast
<
value_type
*>
(
&
value
)),
is_rvalue
(
false
)
{}
json_ref
(
std
::
initializer_list
<
json_ref
>
init
)
:
owned_value
(
init
),
value_ref
(
&
owned_value
),
is_rvalue
(
true
)
{}
template
<
class
...
Args
>
json_ref
(
Args
&&
...
args
)
:
owned_value
(
std
::
forward
<
Args
>
(
args
)...),
value_ref
(
&
owned_value
),
is_rvalue
(
true
)
{}
// class should be movable only
json_ref
(
json_ref
&&
)
=
default
;
json_ref
(
const
json_ref
&
)
=
delete
;
json_ref
&
operator
=
(
const
json_ref
&
)
=
delete
;
value_type
moved_or_copied
()
const
{
if
(
is_rvalue
)
{
return
std
::
move
(
*
value_ref
);
}
return
*
value_ref
;
}
value_type
const
&
operator
*
()
const
{
return
*
static_cast
<
value_type
const
*>
(
value_ref
);
}
value_type
const
*
operator
->
()
const
{
return
static_cast
<
value_type
const
*>
(
value_ref
);
}
private:
mutable
value_type
owned_value
=
nullptr
;
value_type
*
value_ref
=
nullptr
;
const
bool
is_rvalue
;
};
}
// namespace detail
template
<
typename
,
typename
>
struct
adl_serializer
{
...
...
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