[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: object-model: Return by value, reference or pointer? (or something else?)

From: Hyrum K. Wright <hyrum_wright_at_mail.utexas.edu>
Date: Wed, 13 Oct 2010 09:10:38 -0500

On Tue, Oct 12, 2010 at 5:06 PM, Branko ÄŒibej <brane_at_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_at_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
Received on 2010-10-13 16:11:20 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.