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
ff40685b
Commit
ff40685b
authored
9 years ago
by
Ramin Yaghoubzadeh Torky
Browse files
Options
Downloads
Patches
Plain Diff
C++: implemented push_back() (=append()), and extend() for proxies
parent
a60c1b60
No related branches found
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
+39
-0
39 additions, 0 deletions
ipaacalib/cpp/include/ipaaca/ipaaca-payload.h
ipaacalib/cpp/src/ipaaca-json.cc
+14
-2
14 additions, 2 deletions
ipaacalib/cpp/src/ipaaca-json.cc
with
53 additions
and
2 deletions
ipaacalib/cpp/include/ipaaca/ipaaca-payload.h
+
39
−
0
View file @
ff40685b
...
...
@@ -494,6 +494,45 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
connect_to_existing_parents();
_payload->set(key, document_entry->document);
}*/
/// Append a supported type to a list-type payload value
IPAACA_HEADER_EXPORT
template
<
typename
T
>
void
push_back
(
T
t
)
{
if
((
!
json_value
)
||
(
!
json_value
->
IsArray
()))
throw
PayloadAddressingError
();
PayloadDocumentEntry
::
ptr
new_entry
=
document_entry
->
clone
();
// copy-on-write, no lock required
rapidjson
::
Value
&
list
=
new_entry
->
get_or_create_nested_value_from_proxy_path
(
this
);
rapidjson
::
Value
newval
;
pack_into_json_value
(
newval
,
new_entry
->
document
.
GetAllocator
(),
t
);
list
.
PushBack
(
newval
,
new_entry
->
document
.
GetAllocator
());
_payload
->
set
(
_key
,
new_entry
);
}
/// Alias for push_back() (somewhat pythonic - since we also provide extend())
IPAACA_HEADER_EXPORT
template
<
typename
T
>
void
append
(
T
t
)
{
push_back
<
T
>
(
t
);
}
/// Extend a list-type payload value with a vector containing items of a supported type
IPAACA_HEADER_EXPORT
template
<
typename
T
>
void
extend
(
const
std
::
vector
<
T
>&
ts
)
{
if
((
!
json_value
)
||
(
!
json_value
->
IsArray
()))
throw
PayloadAddressingError
();
PayloadDocumentEntry
::
ptr
new_entry
=
document_entry
->
clone
();
// copy-on-write, no lock required
rapidjson
::
Value
&
list
=
new_entry
->
get_or_create_nested_value_from_proxy_path
(
this
);
for
(
auto
&
t
:
ts
)
{
rapidjson
::
Value
newval
;
pack_into_json_value
(
newval
,
new_entry
->
document
.
GetAllocator
(),
t
);
list
.
PushBack
(
newval
,
new_entry
->
document
.
GetAllocator
());
}
_payload
->
set
(
_key
,
new_entry
);
}
/// Extend a list-type payload value with a list containing items of a supported type
IPAACA_HEADER_EXPORT
template
<
typename
T
>
void
extend
(
const
std
::
list
<
T
>&
ts
)
{
if
((
!
json_value
)
||
(
!
json_value
->
IsArray
()))
throw
PayloadAddressingError
();
PayloadDocumentEntry
::
ptr
new_entry
=
document_entry
->
clone
();
// copy-on-write, no lock required
rapidjson
::
Value
&
list
=
new_entry
->
get_or_create_nested_value_from_proxy_path
(
this
);
for
(
auto
&
t
:
ts
)
{
rapidjson
::
Value
newval
;
pack_into_json_value
(
newval
,
new_entry
->
document
.
GetAllocator
(),
t
);
list
.
PushBack
(
newval
,
new_entry
->
document
.
GetAllocator
());
}
_payload
->
set
(
_key
,
new_entry
);
}
};
// Available interpretations of payload entries (or children thereof) below.
// Usage of standard complex data structures (vector etc.) currently entails
...
...
This diff is collapsed.
Click to expand it.
ipaacalib/cpp/src/ipaaca-json.cc
+
14
−
2
View file @
ff40685b
...
...
@@ -152,6 +152,20 @@ int iterators_main(int argc, char** argv)//{{{
std
::
cout
<<
" Unexpected exception: "
<<
ex
.
what
()
<<
std
::
endl
;
}
std
::
cout
<<
std
::
endl
<<
"Appending a string item to the end of payload['a']"
<<
std
::
endl
;
iu
->
payload
()[
"a"
].
push_back
(
"appended string entry"
);
std
::
cout
<<
"Resulting entries in payload['a']:"
<<
std
::
endl
;
for
(
auto
v
:
iu
->
payload
()[
"a"
].
as_list
())
{
std
::
cout
<<
" "
<<
v
<<
std
::
endl
;
}
std
::
cout
<<
std
::
endl
<<
"Extending payload['a'] by a list of three bools"
<<
std
::
endl
;
iu
->
payload
()[
"a"
].
extend
(
std
::
list
<
bool
>
{
false
,
false
,
true
});
std
::
cout
<<
"Resulting entries in payload['a']:"
<<
std
::
endl
;
for
(
auto
v
:
iu
->
payload
()[
"a"
].
as_list
())
{
std
::
cout
<<
" "
<<
v
<<
std
::
endl
;
}
return
0
;
}
//}}}
...
...
@@ -192,7 +206,6 @@ int json_testbed_main(int argc, char** argv)//{{{
}
//}}}
/*
int
fakeiu_main
(
int
argc
,
char
**
argv
)
//{{{
{
//if (argc<2) {
...
...
@@ -318,7 +331,6 @@ int fakeiu_main(int argc, char** argv)//{{{
return
0
;
}
//}}}
*/
int
legacy_iu_main
(
int
argc
,
char
**
argv
)
//{{{
{
...
...
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