subversion-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hyrum K. Wright" <hyrum_wri...@mail.utexas.edu>
Subject Re: object-model: Return by value, reference or pointer? (or something else?)
Date Wed, 13 Oct 2010 14:10:38 GMT
On Tue, Oct 12, 2010 at 5:06 PM, Branko Čibej <brane@xbc.nu> wrote:
>  On 12.10.2010 22:30, Hyrum K. Wright wrote:
>> On Tue, Oct 12, 2010 at 2:40 PM, Branko Čibej <brane@xbc.nu> wrote:
>>>  On 12.10.2010 20:35, Hyrum K. Wright wrote:
>>>> 1) Return everything by value
>>>>    Pros: simpler memory management, less overhead (?)
>>>>    Cons: doesn't allow the return of NULL values, need to establish
>>>> conventions to represent NULL objects (an isNull() method?)
>>> Meh.
>>>
>>>    inline operator bool() const { return (this->c_struct_pointer != 0);
}
>> That works great for our own types, but what about stuff like std::string?
>>
>> inline std::string getAuthor() const { return std::string(ptr->author); }
>>
>> doesn't go over so well when ptr->author is NULL.  If returning by
>> value, we *have* to return a string, but there just isn't any way to
>> indicate the null string.
>
> Good point ... that's a mess. But returning a pointer to an std::string
> is a bigger one ... eep.

Another option is a custom SVN::String type which looks / smells /
acts like a string, but also allows wrapping the NULL value, in a
manner you suggest above.

> So typically you'd add a hasAuthor function and throw an exception from
> getAuthor if there is no author info for a revision. However, in this
> particular case, returning an empty string is just as good, unless you
> want to make the fine distinction between a svn:author property with an
> empty value (is that even allowed?) and no svn:author property on the
> revision. This is no different than if you had a getProperty(name) and
> did a lookup in a private map of property name/value pairs.

I just used getAuthor() as an example, and while I'm not certain as to
the specifics in that particular case (ed: I see Mike has answered
this elsethread), I know there are other places where the
present-but-empty vs. not-present distinction is an important and
valid one.

-Hyrum

Mime
View raw message