Re: [Vala] Inspecting class hierarchy



Yes, that's the intent, my question is how to inspect the class definitions
from Vala within Vala code, so that if I know I want to build a Weapon or a
Component from the keyfile, I can get access to the GLib.Type object for it.

On Mon, Mar 21, 2016 at 9:47 PM, Gergely Polonkai <gergely polonkai eu>
wrote:

Hello,

for the first sight your format looks verybsimilar to key-value files
already supported by GLib:

https://developer.gnome.org/glib/stable/glib-Key-value-file-parser.html
http://valadoc.org/#!api=glib-2.0/GLib.KeyFile

Are you sure it won't work for your problem? If it would, you may want to
subclass it.

Best,
Gergely
On Mar 21, 2016 2:26 PM, "Alan Manuel Gloria" <almkglor gmail com> wrote:

Hi Vala world,

I'm trying to make some kind of description loader.  I have a base class
like so:

class Concept : Object {
  string name { get; construct; }
  string desc { get; construct; }
}

And one or more classes, e.g.:

class Component : Concept {
  uint size { get; construct; }
  uint cost { get; construct; }
}
class Weapon : Component {
  uint damage { get; construct; }
}

My goal is to parse some text file like so:

[Blaster I]
type = Weapon
desc = A simple blaster.
size = 20
cost = 200
damage = 1

Then the parser class will provide a collection of Concept objects
indexable by name and type.

My question is, how do I best do this?  Gtk.Buildable seems to approximate
what I want, so I suppose I need to figure out how that works.

My initial research seems to suggest that I need to use GLib.Type somehow,
but my understanding is that the exact type does not get created until it
is used.  It seems to me that I'd need code like:

var p = new MyTextFileParser();
p.register(typeof(Component));
p.register(typeof(Weapon));
// ... and so on ...

Thanks in advance.

Sincerely,
AmkG
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list




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