Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alexander Lapshin
common
Commits
6a8faff0
Commit
6a8faff0
authored
Feb 17, 2021
by
Alexander Lapshin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ svalue
parent
73eac811
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
0 deletions
+125
-0
json_functions.h
json/json_functions.h
+37
-0
svalue.cpp
utils/svalue.cpp
+1
-0
svalue.h
utils/svalue.h
+87
-0
No files found.
json/json_functions.h
View file @
6a8faff0
...
...
@@ -10,6 +10,7 @@
#include "rapidjson/document.h"
#include <rapidjson/ostreamwrapper.h>
#include <rapidjson/prettywriter.h>
#include "svalue.h"
#define RAPIDJSON_HAS_STDSTRING 1
...
...
@@ -810,3 +811,39 @@ static void loadStrJson(const std::string& data, rapidjson::Document& document)
throw
Exp
()
<<
"json parse error "
<<
", code: "
<<
ok
.
Code
()
<<
", offset: "
<<
ok
.
Offset
()
<<
" at "
<<
__FILE__
<<
":"
<<
__LINE__
;
}
}
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
svalue
<
double
>&
value
,
const
bool
exist
=
true
)
{
jsonval
::
ConstMemberIterator
itr
;
bool
*
loaded
=
nullptr
;
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
return
false
;
}
const
jsonval
&
a
=
itr
->
value
;
if
(
a
.
IsDouble
())
{
value
=
a
.
GetDouble
();
}
else
if
(
a
.
IsString
())
{
std
::
string
str
=
a
.
GetString
();
if
(
str
.
empty
()
&&
!
exist
)
{
if
(
loaded
)
{
*
loaded
=
false
;
}
return
false
;
}
double
val
;
if
(
!
Converter
::
ToNumber
(
str
,
val
))
{
throw
(
Exp
()
<<
"bad value format '"
<<
str
<<
"'"
<<
" in container '"
);
}
value
=
val
;
}
else
{
throw
(
Exp
()
<<
"element '"
<<
key
<<
"'"
<<
" has unexpected format '"
);
}
return
true
;
}
utils/svalue.cpp
0 → 100644
View file @
6a8faff0
#include "svalue.h"
utils/svalue.h
0 → 100644
View file @
6a8faff0
#pragma once
template
<
typename
T
>
class
svalue
{
public
:
svalue
()
{
}
svalue
(
const
T
&
v
)
:
m_has_data
(
true
),
m_value
(
v
)
{
}
friend
bool
operator
<=
(
double
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
>=
(
double
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
==
(
double
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
!=
(
double
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
<=
(
float
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
>=
(
float
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
==
(
float
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
!=
(
float
l
,
const
svalue
&
r
)
=
delete
;
friend
bool
operator
<=
(
const
svalue
&
l
,
double
r
)
=
delete
;
friend
bool
operator
>=
(
const
svalue
&
l
,
double
r
)
=
delete
;
friend
bool
operator
==
(
const
svalue
&
l
,
double
r
)
=
delete
;
friend
bool
operator
!=
(
const
svalue
&
l
,
double
r
)
=
delete
;
friend
bool
operator
<=
(
const
svalue
&
l
,
float
r
)
=
delete
;
friend
bool
operator
>=
(
const
svalue
&
l
,
float
r
)
=
delete
;
friend
bool
operator
==
(
const
svalue
&
l
,
float
r
)
=
delete
;
friend
bool
operator
!=
(
const
svalue
&
l
,
float
r
)
=
delete
;
friend
bool
operator
!=
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
!=
r
.
get
();
}
friend
bool
operator
==
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
==
r
.
get
();
}
friend
bool
operator
<
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
<
r
.
get
();
}
friend
bool
operator
<=
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
<=
r
.
get
();
}
friend
bool
operator
>
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
>
r
.
get
();
}
friend
bool
operator
>=
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
>=
r
.
get
();
}
friend
bool
operator
*
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
*
r
.
get
();
}
friend
bool
operator
/
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
/
r
.
get
();
}
friend
bool
operator
+
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
+
r
.
get
();
}
friend
bool
operator
-
(
const
svalue
&
l
,
const
svalue
&
r
)
{
return
l
.
get
()
-
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
==
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
==
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
!=
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
!=
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
<
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
<
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
>
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
>
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
<=
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
<=
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
>=
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
>=
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
*
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
*
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
/
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
/
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
+
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
+
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
-
(
const
Tc
&
l
,
const
svalue
&
r
)
{
return
l
-
r
.
get
();
}
template
<
typename
Tc
>
friend
bool
operator
==
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
==
r
;
}
//template <typename Tc> friend bool operator!=(const svalue& l, const Tc& r) { return l.get() != r; }
template
<
typename
Tc
>
friend
bool
operator
<
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
<
r
;
}
template
<
typename
Tc
>
friend
bool
operator
>
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
>
r
;
}
template
<
typename
Tc
>
friend
bool
operator
<=
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
<=
r
;
}
template
<
typename
Tc
>
friend
bool
operator
>=
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
>=
r
;
}
template
<
typename
Tc
>
friend
bool
operator
*
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
*
r
;
}
template
<
typename
Tc
>
friend
bool
operator
/
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
/
r
;
}
template
<
typename
Tc
>
friend
bool
operator
+
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
+
r
;
}
template
<
typename
Tc
>
friend
bool
operator
-
(
const
svalue
&
l
,
const
Tc
&
r
)
{
return
l
.
get
()
-
r
;
}
bool
has_data
()
const
{
return
m_has_data
;
}
const
T
&
get
()
const
{
return
m_value
;
}
void
set
(
const
T
&
v
)
{
m_value
=
v
;
m_has_data
=
true
;
}
void
unset
()
{
m_has_data
=
false
;
}
private
:
bool
m_has_data
{
false
};
T
m_value
;
};
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