Backov
10-18-2007, 01:27 PM
I am trying to clean up my GUI library for Ogre prior to releasing it as open source. One of the cleanups I need to do is the way that controls are instantiated from XML, and I can't think of a great way to do this (in C++).
Basically the controls are in XML as you'd expect, with a "type" attribute being passed along from the control definition telling us what type of control it is. That boils down to an ugly if..then...else for each control type, even though they're all the same base type.
There's some special behavior, for instance, radio controls have to be added to their radio group after they're created, but almost everything else is the same.
What's the nice way to do this? In Java I could use reflection (I think that's what it's called) to do it pretty nicely, but I have no idea what a good way to do this in C++ is.
The other reason I want to find a nicer way to do this is because the current version of the GUI doesn't even have a way to instantiate controls into a sheet without XML, so I want to make a nice consistent interface that the loader and the coder can use at the same time.
I know there's some pattern geniuses here. Any insights?
Basically the controls are in XML as you'd expect, with a "type" attribute being passed along from the control definition telling us what type of control it is. That boils down to an ugly if..then...else for each control type, even though they're all the same base type.
There's some special behavior, for instance, radio controls have to be added to their radio group after they're created, but almost everything else is the same.
What's the nice way to do this? In Java I could use reflection (I think that's what it's called) to do it pretty nicely, but I have no idea what a good way to do this in C++ is.
The other reason I want to find a nicer way to do this is because the current version of the GUI doesn't even have a way to instantiate controls into a sheet without XML, so I want to make a nice consistent interface that the loader and the coder can use at the same time.
I know there's some pattern geniuses here. Any insights?