Re: Move from {Array,List,Slist}Handle to std::vector.



2011/1/19 Murray Cumming <murrayc murrayc com>:
> On Tue, 2011-01-18 at 23:10 +0100, Krzesimir Nowak wrote:
>> Hi,
>>
>> I pushed to Glibmm repository my own branch called `vector'
>
> Thanks.
>
> Here's a link for others:
> http://git.gnome.org/browse/glibmm/log/?h=vector
>
>> The downside of current API is that methods using
>> {Array,List,SList}Handle could take both C++ containers and C arrays as
>> a parameter. Now methods can take only std::vector,
> [snip]
>
> I think that's acceptable.
>
>> But I still have some doubts. Some intro first:
>> Most common functions are the ones returning a container and the ones
>> taking container as a parameter. A function can have three types of
>> ownership transfer: deep, shallow and none. So in the end there are six
>> types:
>> 1. function returning a container with full ownership transfer - that
>> means that caller owns both container and data it holds.
>> 2. function returning a container with shallow ownership transfer- that
>> means that caller owns only container, data belongs to the function.
>> 3. function returning a container with no ownership transfer - that
>> means that caller owns nothing.
>> 4. function taking a container as a parameter with full ownership
>> transfer - that means that function takes ownership of both container
>> and data.
>> 5. function taking a container as a parameter with shallow ownership
>> transfer - that means that function takes ownership of data only,
>> container still belongs to caller.
>> 6. function taking a container as a parameter with no ownership transfer
>> - that means that function takes no ownership, both container and data
>> still belongs to caller.
>
> In practice, we have only needed 3 varieties so far: OWNERSHIP_NONE,
> OWNERSHIP_SHALLOW, and OWNERSHIP_DEEP.
>
> Why do you need more now? That seems to be making your task harder for
> no actual gain.
>

What I meant there is that functions returning a container (1st to 3rd points)
like the one below indeed do not pose a problem:

GList* get_something ();

Problem is with functions taking a container (4th to 6th points):

void set_something (GList* list);

Is there a possibility that there is a set_something (), that takes
deep or shallow
ownership of passed data instead of none? For now I commented such functions
in vector test as buggy by design and such probably will need wrapping by hand.

Also, I read more carefully the ListHandle code (especially ListSourceTraits)
and I noticed that when we are passing STL container then ListHandle always
assumes shallow ownership. Well, this probably answers my question, so
this should be also reflected in my vector code. That way I can simplify the
vector_to_* () methods, so they don't take ownership parameter, but
hardcodes the shallow ownership.

>> There are also functions that take parameter, but treat it as a return
>> value - these are best wrapped by hand and are not covered here.
>
> You mean output parameters, I think. Yes, let's ignore that for now.
>
> --
> murrayc murrayc com
> www.murrayc.com
> www.openismus.com
>
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]