Cool Config Parsing Idea

closed account (S6k9GNh0)
I came up with this while making a small configuration parser using XML. Basically, it reduces the amount of hard coding while reducing the need to parse. This may have already been made but I couldn't find it anywhere sooooo....

Basically, it does the following:
cq::Video::Settings* example = myConfig.GetVideoSettings();

to:

1
2
3
int width = cq::GetVariable<int>("video","width");
int height = cq::GetVariable<int>("video","height");
int depth = cq::GetVariable<int>("video","depth");


This increases the lines of code by quite a bit... but, this reduces the need for hardcoded functions into the configuration class and the variables called will only be parsed once.

So, there is this static map inside of the configuration class. This std::map is empty until a variable is called. When a variable fetching function is called, it parses the loaded XML and inserts the given variable into a map and then returns the value. The next time the variable is fetched, it will look in the map before parsing the loaded XML. I haven't actually implemented this since va_args is incredibly unsafe and I don't think I'm going to touch it but I figured it was a decent idea. Any feedback?
This may have already been made but I couldn't find it anywhere sooooo....

http://www.boost.org/doc/libs/1_41_0/doc/html/property_tree.html
Last edited on
Topic archived. No new replies allowed.