[ 
https://issues.apache.org/jira/browse/PROTON-1288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15446616#comment-15446616
 ] 

Alan Conway commented on PROTON-1288:
-------------------------------------

That also addresses the "null vs. default value" issue in a consistent way 
which is good, I'm almost sold. Here's my conflict:

- Performance-wise it would be nice to return a scalar rather than a value for 
properties that are scalars. Actually in practice the underlying C has 
pn_data_t's and we can return a ref but if it's assigned to a new value that's 
a needless allocatin.
- Type-safety wise it would be nice to return restricted scalars, like a 
proton::string_scalar which can only be std::string or null - similar to how we 
handle message_id.
- but API wise it would be nice to have consistent names like foo_value() 
rather than foo_scalar(), bar_value() etc. :(

We could combine both like this:

    proton::string_scalar message::reply_to_value();

Now the following works since scalars can be assigned to a value:

    value rt = m.reply_to_value();
    if (m.reply_to_value().empty()) ...
    if (m.reply_to_value()type() == ) ...

But so does this, and is more type-safe efficient:

    string_scalar rt = m.reply_to_value();

I think that might be the best of both worlds. We could provide a uniform 
setter that takes a value:

    void message::reply_to(const value& v);

That willl accept scalar_string or a value containing a string. That allows you 
to efficiently set a missing value since an proton::value()  is just null 
pointer. We could add a const string_scalar& setter if we really cared but I 
suspect we never will.


> c++ provide access to message maps as proton::value
> ---------------------------------------------------
>
>                 Key: PROTON-1288
>                 URL: https://issues.apache.org/jira/browse/PROTON-1288
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: cpp-binding
>    Affects Versions: 0.14.0
>            Reporter: Alan Conway
>            Assignee: Alan Conway
>             Fix For: 0.15.0
>
>
> We need to provide access to the message property maps as a proton::value. 
> Given
> {code}
>     std::map<string, scalar> my_map;
>     proton::message m;
> {code}
> Here are some options:
> 1. Add new message accessor: proton::value& properties_value()
>    proton::get(m.properties_value(), my_map)
> 2. Add value() accessor to cached_map
>    proton::get(m.properties().value(), my_map)
> 3. Make cached_map : public proton::value()
>    proton::get(m.properties(), my_map)
> 3 is neatest, 1 provides a clearer separation between the case where you want 
> a convenient cached map vs. you want to decode to your own C++ map, work on 
> it, and possibly re-encode it later. I lean towards 3. but open to persuasion.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to