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

Re: object-model: Wrapping Subversion C-structs in C++

From: Stefan Fuhrmann <stefanfuhrmann_at_alice-dsl.de>
Date: Sun, 26 Sep 2010 15:56:54 +0200

Hyrum K. Wright <hyrum_wright_at_mail.utexas.edu
<mailto:hyrum_wright_at_mail.utexas.edu?Subject=Re:%20object-model:%20Wrapping%20Subversion%20C-structs%20in%20C%2B%2B>>
wrote:

> For the C++ folks out there, I've got a question about an approach to
> take on the object-model branch. At issue is how to wrap the various
> C structures returned to callers, particularly in a backward
> compatible manner. Currently, I'm looking at svn_wc_notify_t *. As I
> see it, there are a few options:
>
> 1) Just wrap the pointer to the C struct as a member of the wrapper
> class.
> Pros: Easy to implement; lightweight constructor.
> Cons: Getters would need to translate to C++ types; would need to
> implement a copy constructor which deep copies the C struct; would
> also introduce pools, since creating and duplicating C structs
> requires them.
>
> 2) Wrap each C struct member individually
> Pros: C->C++ complexity is constrained to the constructor,
> everything else is C++ types
> Cons: Hard to extend for future compatibility
>
> 3) Just pass the C-struct pointer around; don't even bother with a class
> Pros: Dead simple.
> Cons: Requires more memory management thought by consumers; not
> C++-y enough; may introduce wrapping difficulties.
>
> I'd like to come up with something consistent, which would be used
> throughout the C++ bindings. I'm also interested in a solution which
> ensures the C++ bindings can be used as the basis for other
> object-oriented bindings models (Python, Perl, etc.)
>
> Thoughts?

One issue that has not been talked about in this thread
is strong typing. If you remember the problems with
Johan's diff / blame optimizations, the reason behind
it was a confusion of type semantics. Some ints were
line numbers, others were file offsets. But there was / is
no formal way to tell them apart.

Since you decided to use templates in your code, I
thought I would give it a try and design a simple template
class that allows you to define any number of int-like
types that are mutually distinct and require explicit
conversion.

It would be nice to have the C++ wrappers use these
types instead of plain ints etc. in their signatures.

-- Stefan^2.

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=757&dsMessageId=2664769

To unsubscribe from this discussion, e-mail: [dev-unsubscribe_at_tortoisesvn.tigris.org].

Received on 2010-09-26 15:57:23 CEST

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

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