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
b6d855c1
Commit
b6d855c1
authored
9 years ago
by
Ramin Yaghoubzadeh Torky
Browse files
Options
Downloads
Patches
Plain Diff
C++: added push_back() and extend() for proxy arguments
parent
ff40685b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+29
-2
29 additions, 2 deletions
ipaacalib/cpp/include/ipaaca/ipaaca-payload.h
ipaacalib/cpp/src/ipaaca-json.cc
+9
-0
9 additions, 0 deletions
ipaacalib/cpp/src/ipaaca-json.cc
with
38 additions
and
2 deletions
ipaacalib/cpp/include/ipaaca/ipaaca-payload.h
+
29
−
2
View file @
b6d855c1
...
@@ -505,8 +505,20 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
...
@@ -505,8 +505,20 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
list
.
PushBack
(
newval
,
new_entry
->
document
.
GetAllocator
());
list
.
PushBack
(
newval
,
new_entry
->
document
.
GetAllocator
());
_payload
->
set
(
_key
,
new_entry
);
_payload
->
set
(
_key
,
new_entry
);
}
}
/// Alias for push_back() (somewhat pythonic - since we also provide extend())
/// Append the value of another proxy (or a null value) to a list-type value
IPAACA_HEADER_EXPORT
template
<
typename
T
>
void
append
(
T
t
)
{
push_back
<
T
>
(
t
);
}
IPAACA_HEADER_EXPORT
void
push_back
(
const
PayloadEntryProxy
&
otherproxy
)
{
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
;
auto
valueptr
=
otherproxy
.
json_value
;
if
(
valueptr
)
{
// only set if value is valid, keep default null value otherwise
newval
.
CopyFrom
(
*
valueptr
,
new_entry
->
document
.
GetAllocator
());
}
list
.
PushBack
(
newval
,
new_entry
->
document
.
GetAllocator
());
_payload
->
set
(
_key
,
new_entry
);
}
/// Extend a list-type payload value with a vector containing items of a supported type
/// 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
)
IPAACA_HEADER_EXPORT
template
<
typename
T
>
void
extend
(
const
std
::
vector
<
T
>&
ts
)
{
{
...
@@ -533,6 +545,21 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
...
@@ -533,6 +545,21 @@ IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
}
}
_payload
->
set
(
_key
,
new_entry
);
_payload
->
set
(
_key
,
new_entry
);
}
}
/// Extend a list-type payload value with items (copies) from another list-type value
IPAACA_HEADER_EXPORT
void
extend
(
const
PayloadEntryProxy
&
otherproxy
)
{
if
((
!
json_value
)
||
(
!
json_value
->
IsArray
()))
throw
PayloadAddressingError
();
if
((
!
otherproxy
.
json_value
)
||
(
!
(
otherproxy
.
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
(
size_t
i
=
0
;
i
<
otherproxy
.
json_value
->
Size
();
++
i
)
{
rapidjson
::
Value
newval
;
rapidjson
::
Value
&
value
=
(
*
(
otherproxy
.
json_value
))[
i
];
newval
.
CopyFrom
(
value
,
new_entry
->
document
.
GetAllocator
());
list
.
PushBack
(
newval
,
new_entry
->
document
.
GetAllocator
());
}
_payload
->
set
(
_key
,
new_entry
);
}
};
};
// Available interpretations of payload entries (or children thereof) below.
// Available interpretations of payload entries (or children thereof) below.
// Usage of standard complex data structures (vector etc.) currently entails
// Usage of standard complex data structures (vector etc.) currently entails
...
...
This diff is collapsed.
Click to expand it.
ipaacalib/cpp/src/ipaaca-json.cc
+
9
−
0
View file @
b6d855c1
...
@@ -66,6 +66,7 @@ int iterators_main(int argc, char** argv)//{{{
...
@@ -66,6 +66,7 @@ int iterators_main(int argc, char** argv)//{{{
iu
->
payload
()[
"d"
]
=
100
;
iu
->
payload
()[
"d"
]
=
100
;
iu
->
payload
()[
"e"
]
=
3l
;
iu
->
payload
()[
"e"
]
=
3l
;
iu
->
payload
()[
"f"
]
=
"12.5000"
;
iu
->
payload
()[
"f"
]
=
"12.5000"
;
iu
->
payload
()[
"g"
]
=
std
::
vector
<
std
::
string
>
{
"g1"
,
"g2"
};
std
::
cout
<<
std
::
endl
<<
"Iterate over payload"
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
"Iterate over payload"
<<
std
::
endl
;
for
(
auto
it
=
iu
->
payload
().
begin
();
it
!=
iu
->
payload
().
end
();
++
it
)
{
for
(
auto
it
=
iu
->
payload
().
begin
();
it
!=
iu
->
payload
().
end
();
++
it
)
{
...
@@ -166,6 +167,14 @@ int iterators_main(int argc, char** argv)//{{{
...
@@ -166,6 +167,14 @@ int iterators_main(int argc, char** argv)//{{{
std
::
cout
<<
" "
<<
v
<<
std
::
endl
;
std
::
cout
<<
" "
<<
v
<<
std
::
endl
;
}
}
std
::
cout
<<
std
::
endl
<<
"Extending payload['a'] by payload['g'] and appending payload['f']"
<<
std
::
endl
;
iu
->
payload
()[
"a"
].
extend
(
iu
->
payload
()[
"g"
]);
iu
->
payload
()[
"a"
].
push_back
(
iu
->
payload
()[
"f"
]);
std
::
cout
<<
"Resulting entries in payload['a']:"
<<
std
::
endl
;
for
(
auto
v
:
iu
->
payload
()[
"a"
].
as_list
())
{
std
::
cout
<<
" "
<<
v
<<
std
::
endl
;
}
return
0
;
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