Boost logo

Boost :

Subject: Re: [boost] [paired ptr] Proposing a new smart pointer object for managing bidirectional relationships between objects
From: Vicente Botet Escriba (vicente.botet_at_[hidden])
Date: 2010-05-03 11:14:05


Dan Walters-2 wrote:
>
> Dear all,
>
> I have been working on a proposal for a useful utility for managing
> non hierarchal, bi-directional relationships between objects and as a
> useful tool in object composition.
>
> This utility is in the form of a type of templated smart pointer that
> can connect to one single other pointer and manage the relationship
> between the two pointers.
>
> This paired_ptr object is intended for use as a member of (or at least
> contained within) a user defined object and is conceptualized from the
> needs of object composition.
>
> Prototype source code, a usage example and brief documentation is
> available here:
>
> http://www.boostpro.com/vault/index.php?action=downloadfile&filename=paired_ptr.zip&directory=&
>
> Doumentation only is available here: (this is a google doc and is
> continually being updated)
>
> http://docs.google.com/View?id=dc33pnfx_442s22z7d6
>
> I am posting here in the hope it will generate suitable interest that
> it may be worth developing as a full library for submission.
>
> Best wishes,
>
> Dan
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
>

Hi,

I don't know why I don't like the name paired_ptr, one_to_one_ptr could be
an alternative. I will see this class as one more in a Association library
that could include other kind of associations, as one_to_many, many_to_one,
many_to_many,...

class CCat

CDog rex;
CCat kitty;

As no one side of the association is more important than the other maybe a
non-member function could be more adequate. The connection between two
objects can be established as so

connect(rex.paired_cat, kitty.paired_dog);

//connections can be severed at either end
disconnect(kitty.paired_dog);

have you think about adding a mixin paired_ptr that can be used as base
class and as such don't need to manage with the owner initialization?

class CCat;
class CDog;

class CDog : public one_to_one_ptr<CDog, CCat>
{
...
};

class CCat : public one_to_one_ptr<CCat,CDog>
{
...
};

Now the connection can be done directly
connect(rex, kitty);

one_to_one_ptr<T,U> could define a method to get the pointed U, get<U> that
can be used like

get<CCat>(rex);

or

rex.get<CCat>();

Best,
Vicente

-- 
View this message in context: http://old.nabble.com/-paired-ptr--Proposing-a-new-smart-pointer-object-for-managing-bidirectional-relationships-between-objects-tp28426033p28436346.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk