GObject question.



Hello, everyone.

I don't know if this is the right place to ask, but I tried and
couldn't find a gobject specific mail-list. Don't know where else to
ask so here it goes.

I am writing a class and would like to know if there is anyway that I
can prevent the object from being created (or deleting it right after
it, if the first alternative is impossible) when I find out problems
in the constructor.

The thing is: my class only makes sense when it is related with a
file. Let's say it's called XFileBuffer (X_FILE_BUFFER)

when a user asks for new object, like in

g_object_new(X_TYPE_FILE_BUFFER, "file-name", "myfile.txt", NULL);

I want to be able to check if "file-name" property is set to a file
that can be read and read it to an internal buffer of my object, but I
don't want it to be created when the file isn't available for some
reason.

Is it possible that I check the reasonable conditions inside my
constructor and return NULL on the g_object_new() call the user made
if they're not met ?

If, so, what would be the best way of doing it (so that derived types,
for instance, would automatically inherit such behavior).

I believe what I am trying to make is *almost* like throwing an
exception in a C++ constructor (although I don't know much C++)... and
would like to know if GObject allows me to do anything like that.

Thanks,
Alexandre Moreira.



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