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
76d3433e
Commit
76d3433e
authored
May 10, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved some code to json_value union
parent
5ed80d30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
102 deletions
+88
-102
src/json.hpp
src/json.hpp
+44
-51
src/json.hpp.re2c
src/json.hpp.re2c
+44
-51
No files found.
src/json.hpp
View file @
76d3433e
...
...
@@ -246,6 +246,30 @@ class basic_json
}
}
}
/// constructor for strings
json_value
(
const
string_t
&
value
)
{
AllocatorType
<
string_t
>
alloc
;
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
string
,
value
);
}
/// constructor for objects
json_value
(
const
object_t
&
value
)
{
AllocatorType
<
object_t
>
alloc
;
object
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
object
,
value
);
}
/// constructor for arrays
json_value
(
const
array_t
&
value
)
{
AllocatorType
<
array_t
>
alloc
;
array
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
array
,
value
);
}
};
//////////////////////////
...
...
@@ -325,17 +349,13 @@ class basic_json
/// create a null object (explicitly)
inline
basic_json
(
std
::
nullptr_t
)
noexcept
:
m_type
(
value_t
::
null
)
:
basic_json
(
value_t
::
null
)
{}
/// create an object (explicit)
inline
basic_json
(
const
object_t
&
value
)
:
m_type
(
value_t
::
object
)
{
AllocatorType
<
object_t
>
alloc
;
m_value
.
object
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
object
,
value
);
}
:
m_type
(
value_t
::
object
),
m_value
(
value
)
{}
/// create an object (implicit)
template
<
class
V
,
typename
...
...
@@ -355,12 +375,8 @@ class basic_json
/// create an array (explicit)
inline
basic_json
(
const
array_t
&
value
)
:
m_type
(
value_t
::
array
)
{
AllocatorType
<
array_t
>
alloc
;
m_value
.
array
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
array
,
value
);
}
:
m_type
(
value_t
::
array
),
m_value
(
value
)
{}
/// create an array (implicit)
template
<
class
V
,
typename
...
...
@@ -385,21 +401,13 @@ class basic_json
/// create a string (explicit)
inline
basic_json
(
const
string_t
&
value
)
:
m_type
(
value_t
::
string
)
{
AllocatorType
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
value
);
}
:
m_type
(
value_t
::
string
),
m_value
(
value
)
{}
/// create a string (explicit)
inline
basic_json
(
const
typename
string_t
::
value_type
*
value
)
:
m_type
(
value_t
::
string
)
{
AllocatorType
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
value
);
}
:
basic_json
(
string_t
(
value
))
{}
/// create a string (implicit)
template
<
class
V
,
typename
...
...
@@ -422,7 +430,7 @@ class basic_json
/// create an int number to support enum type (implicit)
inline
basic_json
(
const
int
int_enum
)
:
m_type
(
value_t
::
number_integer
),
m_value
(
static_cast
<
number_integer_t
>
(
int_enum
))
:
basic_json
(
static_cast
<
number_integer_t
>
(
int_enum
))
{}
/// create an integer number (implicit)
...
...
@@ -432,7 +440,7 @@ class basic_json
std
::
numeric_limits
<
T
>::
is_integer
,
T
>::
type
=
0
>
inline
basic_json
(
const
T
value
)
noexcept
:
m_type
(
value_t
::
number_integer
),
m_value
(
number_integer_t
(
value
))
:
basic_json
(
number_integer_t
(
value
))
{}
/// create a floating-point number (explicit)
...
...
@@ -454,15 +462,8 @@ class basic_json
std
::
is_floating_point
<
T
>::
value
>::
type
>
inline
basic_json
(
const
T
value
)
noexcept
:
m_type
(
value_t
::
number_float
),
m_value
(
number_float_t
(
value
))
{
// replace infinity and NAN by null
if
(
not
std
::
isfinite
(
value
))
{
m_type
=
value_t
::
null
;
m_value
=
json_value
();
}
}
:
basic_json
(
number_float_t
(
value
))
{}
/// create a container (array or object) from an initializer list
inline
basic_json
(
list_init_t
init
,
bool
type_deduction
=
true
,
...
...
@@ -607,9 +608,7 @@ class basic_json
case
value_t
:
:
string
:
{
AllocatorType
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
*
first
.
m_object
->
m_value
.
string
);
m_value
=
*
first
.
m_object
->
m_value
.
string
;
break
;
}
...
...
@@ -660,43 +659,37 @@ class basic_json
case
(
value_t
:
:
object
)
:
{
AllocatorType
<
object_t
>
alloc
;
m_value
.
object
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
object
,
*
other
.
m_value
.
object
);
m_value
=
*
other
.
m_value
.
object
;
break
;
}
case
(
value_t
:
:
array
)
:
{
AllocatorType
<
array_t
>
alloc
;
m_value
.
array
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
array
,
*
other
.
m_value
.
array
);
m_value
=
*
other
.
m_value
.
array
;
break
;
}
case
(
value_t
:
:
string
)
:
{
AllocatorType
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
*
other
.
m_value
.
string
);
m_value
=
*
other
.
m_value
.
string
;
break
;
}
case
(
value_t
:
:
boolean
)
:
{
m_value
.
boolean
=
other
.
m_value
.
boolean
;
m_value
=
other
.
m_value
.
boolean
;
break
;
}
case
(
value_t
:
:
number_integer
)
:
{
m_value
.
number_integer
=
other
.
m_value
.
number_integer
;
m_value
=
other
.
m_value
.
number_integer
;
break
;
}
case
(
value_t
:
:
number_float
)
:
{
m_value
.
number_float
=
other
.
m_value
.
number_float
;
m_value
=
other
.
m_value
.
number_float
;
break
;
}
}
...
...
src/json.hpp.re2c
View file @
76d3433e
...
...
@@ -246,6 +246,30 @@ class basic_json
}
}
}
/// constructor for strings
json_value(const string_t& value)
{
AllocatorType<string_t> alloc;
string = alloc.allocate(1);
alloc.construct(string, value);
}
/// constructor for objects
json_value(const object_t& value)
{
AllocatorType<object_t> alloc;
object = alloc.allocate(1);
alloc.construct(object, value);
}
/// constructor for arrays
json_value(const array_t& value)
{
AllocatorType<array_t> alloc;
array = alloc.allocate(1);
alloc.construct(array, value);
}
};
//////////////////////////
...
...
@@ -325,17 +349,13 @@ class basic_json
/// create a null object (explicitly)
inline basic_json(std::nullptr_t) noexcept
:
m_type
(value_t::null)
:
basic_json
(value_t::null)
{}
/// create an object (explicit)
inline basic_json(const object_t& value)
: m_type(value_t::object)
{
AllocatorType<object_t> alloc;
m_value.object = alloc.allocate(1);
alloc.construct(m_value.object, value);
}
: m_type(value_t::object), m_value(value)
{}
/// create an object (implicit)
template <class V, typename
...
...
@@ -355,12 +375,8 @@ class basic_json
/// create an array (explicit)
inline basic_json(const array_t& value)
: m_type(value_t::array)
{
AllocatorType<array_t> alloc;
m_value.array = alloc.allocate(1);
alloc.construct(m_value.array, value);
}
: m_type(value_t::array), m_value(value)
{}
/// create an array (implicit)
template <class V, typename
...
...
@@ -385,21 +401,13 @@ class basic_json
/// create a string (explicit)
inline basic_json(const string_t& value)
: m_type(value_t::string)
{
AllocatorType<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, value);
}
: m_type(value_t::string), m_value(value)
{}
/// create a string (explicit)
inline basic_json(const typename string_t::value_type* value)
: m_type(value_t::string)
{
AllocatorType<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, value);
}
: basic_json(string_t(value))
{}
/// create a string (implicit)
template <class V, typename
...
...
@@ -422,7 +430,7 @@ class basic_json
/// create an int number to support enum type (implicit)
inline basic_json(const int int_enum)
:
m_type(value_t::number_integer), m_value
(static_cast<number_integer_t>(int_enum))
:
basic_json
(static_cast<number_integer_t>(int_enum))
{}
/// create an integer number (implicit)
...
...
@@ -432,7 +440,7 @@ class basic_json
std::numeric_limits<T>::is_integer, T>::type
= 0>
inline basic_json(const T value) noexcept
:
m_type(value_t::number_integer), m_value
(number_integer_t(value))
:
basic_json
(number_integer_t(value))
{}
/// create a floating-point number (explicit)
...
...
@@ -454,15 +462,8 @@ class basic_json
std::is_floating_point<T>::value>::type
>
inline basic_json(const T value) noexcept
: m_type(value_t::number_float), m_value(number_float_t(value))
{
// replace infinity and NAN by null
if (not std::isfinite(value))
{
m_type = value_t::null;
m_value = json_value();
}
}
: basic_json(number_float_t(value))
{}
/// create a container (array or object) from an initializer list
inline basic_json(list_init_t init, bool type_deduction = true,
...
...
@@ -607,9 +608,7 @@ class basic_json
case value_t::string:
{
AllocatorType<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, *first.m_object->m_value.string);
m_value = *first.m_object->m_value.string;
break;
}
...
...
@@ -660,43 +659,37 @@ class basic_json
case (value_t::object):
{
AllocatorType<object_t> alloc;
m_value.object = alloc.allocate(1);
alloc.construct(m_value.object, *other.m_value.object);
m_value = *other.m_value.object;
break;
}
case (value_t::array):
{
AllocatorType<array_t> alloc;
m_value.array = alloc.allocate(1);
alloc.construct(m_value.array, *other.m_value.array);
m_value = *other.m_value.array;
break;
}
case (value_t::string):
{
AllocatorType<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, *other.m_value.string);
m_value = *other.m_value.string;
break;
}
case (value_t::boolean):
{
m_value
.boolean
= other.m_value.boolean;
m_value = other.m_value.boolean;
break;
}
case (value_t::number_integer):
{
m_value
.number_integer
= other.m_value.number_integer;
m_value = other.m_value.number_integer;
break;
}
case (value_t::number_float):
{
m_value
.number_float
= other.m_value.number_float;
m_value = other.m_value.number_float;
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