[Vala] Inspecting class hierarchy



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


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