Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ipaaca
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ramin Yaghoubzadeh Torky
ipaaca
Commits
4ddafbbb
Commit
4ddafbbb
authored
10 years ago
by
Ramin Yaghoubzadeh Torky
Browse files
Options
Downloads
Patches
Plain Diff
read operations for standard containers OK
parent
3daf95b3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ipaacalib/cpp/include/ipaaca/ipaaca-payload.h
+25
-0
25 additions, 0 deletions
ipaacalib/cpp/include/ipaaca/ipaaca-payload.h
ipaacalib/cpp/src/ipaaca-json.cc
+72
-3
72 additions, 3 deletions
ipaacalib/cpp/src/ipaaca-json.cc
with
97 additions
and
3 deletions
ipaacalib/cpp/include/ipaaca/ipaaca-payload.h
+
25
−
0
View file @
4ddafbbb
...
...
@@ -105,6 +105,31 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
IPAACA_HEADER_EXPORT
operator
long
();
IPAACA_HEADER_EXPORT
operator
double
();
IPAACA_HEADER_EXPORT
operator
bool
();
IPAACA_HEADER_EXPORT
template
<
typename
Inner
>
operator
std
::
vector
<
Inner
>
()
{
if
((
!
json_value
)
||
(
!
json_value
->
IsArray
()))
throw
PayloadAddressingError
();
std
::
vector
<
Inner
>
result
;
for
(
auto
it
=
json_value
->
Begin
();
it
!=
json_value
->
End
();
++
it
)
{
result
.
push_back
(
json_value_cast
<
Inner
>
(
*
it
)
);
}
return
result
;
}
IPAACA_HEADER_EXPORT
template
<
typename
Inner
>
operator
std
::
list
<
Inner
>
()
{
if
((
!
json_value
)
||
(
!
json_value
->
IsArray
()))
throw
PayloadAddressingError
();
std
::
list
<
Inner
>
result
;
for
(
auto
it
=
json_value
->
Begin
();
it
!=
json_value
->
End
();
++
it
)
{
result
.
push_back
(
json_value_cast
<
Inner
>
(
*
it
)
);
}
return
result
;
}
IPAACA_HEADER_EXPORT
template
<
typename
Inner
>
operator
std
::
map
<
std
::
string
,
Inner
>
()
{
if
((
!
json_value
)
||
(
!
json_value
->
IsObject
()))
throw
PayloadAddressingError
();
std
::
map
<
std
::
string
,
Inner
>
result
;
for
(
auto
it
=
json_value
->
MemberBegin
();
it
!=
json_value
->
MemberEnd
();
++
it
)
{
result
[
std
::
string
(
it
->
name
.
GetString
())]
=
json_value_cast
<
Inner
>
(
it
->
value
);
}
return
result
;
}
// FIXME why are these needed again?
IPAACA_HEADER_EXPORT
std
::
string
to_str
();
//long to_int() { return operator long(); ;
IPAACA_HEADER_EXPORT
long
to_long
();
...
...
This diff is collapsed.
Click to expand it.
ipaacalib/cpp/src/ipaaca-json.cc
+
72
−
3
View file @
4ddafbbb
...
...
@@ -55,11 +55,80 @@ int main(int argc, char** argv) {
std
::
cout
<<
"entry as long: "
<<
(
long
)
a
<<
std
::
endl
;
std
::
cout
<<
"entry as double: "
<<
(
double
)
a
<<
std
::
endl
;
std
::
cout
<<
"entry as bool: "
<<
((
bool
)
a
?
"true"
:
"false"
)
<<
std
::
endl
;
std
::
cout
<<
"entry as list<string>: "
;
// std::vector
std
::
cout
<<
"entry as vector<string>: "
;
try
{
}
catch
{
std
::
cout
<<
"(Error)"
<<
std
::
endl
;
std
::
vector
<
std
::
string
>
v
=
a
;
std
::
for_each
(
v
.
begin
(),
v
.
end
(),
[](
std
::
string
&
s
)
{
std
::
cout
<<
s
<<
" "
;
});
std
::
cout
<<
std
::
endl
;
}
catch
(...)
{
std
::
cout
<<
"(n/a)"
<<
std
::
endl
;
}
std
::
cout
<<
"entry as vector<long>: "
;
try
{
std
::
vector
<
long
>
v
=
a
;
std
::
for_each
(
v
.
begin
(),
v
.
end
(),
[](
long
&
s
)
{
std
::
cout
<<
s
<<
" "
;
});
std
::
cout
<<
std
::
endl
;
}
catch
(...)
{
std
::
cout
<<
"(n/a)"
<<
std
::
endl
;
}
std
::
cout
<<
"entry as vector<bool>: "
;
try
{
std
::
vector
<
bool
>
v
=
a
;
std
::
for_each
(
v
.
begin
(),
v
.
end
(),
[](
bool
s
)
{
std
::
cout
<<
(
s
?
"true"
:
"false"
)
<<
" "
;
});
std
::
cout
<<
std
::
endl
;
}
catch
(...)
{
std
::
cout
<<
"(n/a)"
<<
std
::
endl
;
}
// std::map
std
::
cout
<<
"entry as map<string, string>: "
;
try
{
std
::
map
<
std
::
string
,
std
::
string
>
m
=
a
;
for
(
auto
it
=
m
.
begin
();
it
!=
m
.
end
();
++
it
)
{
std
::
cout
<<
it
->
first
<<
":"
<<
it
->
second
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
}
catch
(...)
{
std
::
cout
<<
"(n/a)"
<<
std
::
endl
;
}
std
::
cout
<<
"entry as map<string, long>: "
;
try
{
std
::
map
<
std
::
string
,
long
>
m
=
a
;
for
(
auto
it
=
m
.
begin
();
it
!=
m
.
end
();
++
it
)
{
std
::
cout
<<
it
->
first
<<
":"
<<
it
->
second
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
}
catch
(...)
{
std
::
cout
<<
"(n/a)"
<<
std
::
endl
;
}
std
::
cout
<<
"entry as map<string, double>: "
;
try
{
std
::
map
<
std
::
string
,
double
>
m
=
a
;
for
(
auto
it
=
m
.
begin
();
it
!=
m
.
end
();
++
it
)
{
std
::
cout
<<
it
->
first
<<
":"
<<
it
->
second
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
}
catch
(...)
{
std
::
cout
<<
"(n/a)"
<<
std
::
endl
;
}
std
::
cout
<<
"entry as map<string, bool>: "
;
try
{
std
::
map
<
std
::
string
,
bool
>
m
=
a
;
for
(
auto
it
=
m
.
begin
();
it
!=
m
.
end
();
++
it
)
{
std
::
cout
<<
it
->
first
<<
":"
<<
(
it
->
second
?
"true"
:
"false"
)
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
}
catch
(...)
{
std
::
cout
<<
"(n/a)"
<<
std
::
endl
;
}
// Done
return
0
;
////////////////////////////////////////////////////////////////////////////
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment