[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: GLib/GObject+C as the lingua franca?
From:       "koos vriezen" <koos.vriezen () gmail ! com>
Date:       2008-07-27 18:49:22
Message-ID: d4e708d60807271149k34518ee1h49e54090d1114d87 () mail ! gmail ! com
[Download RAW message or body]

2008/7/27 nf2 <nf2@scheinwelt.at>:

> I thought of really lightweight wrapping. Very minimalistic. See the example
> below. Mainly that you can put GObjects into C++ containers and for garbage
> collection...

But you also need to add a copy constructor then and think about
either implicit sharing the GFile object or copying ... GFile doesn't
seem to have ref counting only g_file_dup, so for sharing you must do
your own ref counting.
But if you can easily track the file objects, why not simply store the
pointers in the C++ containers.


> -------------------- C Code ------------------------
>
> GError * err = NULL;
> GFile * gFile = g_file_new_for_uri("ftp://user@server/file");
>      GFileInfo* gFileInfo = g_file_query_info( gFile,
>               "*",
>               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
>               NULL,
>               &err);

g_file_new_for_uri doesn't have an GError argument.

> if (err)
> {
>     printf("error %s\n", err->message);
>     g_error_free(err);
>
>     g_object_unref (gFile);
>     return;
> }
>
> ----------------- C++ Code -------------------
>
> GOError err;
> GO<GFile> gFile = g_file_new_for_uri("ftp://user@server/file");
>      GO<GFileInfo> gFileInfo = g_file_query_info( gFile.p,
>               "*",
>               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
>               NULL,
>               err.pp());

You could even add a 'operator GError *()' to the GOError class,
instead of the pp()

> if (err.hasError())
> {
>     cout << "error " << err.message();
>     return;
> }

Note that not all gfoo's use g_object_unref, eg. GFile uses
g_file_delete. Makes it rather hard to templete this.

I think you should look where exactly this saves code.

Koos
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic