Some Direction Needed
I am looking for someone to point me in the right direction for this c++ project I'm working on.
I have a massive C++ application that is built with the QT library. Basically, it records data during an a flight simulation and replays all the events on a time line. Here's a basic psedo example:
and all the time there is an output window that lists the planes name/speed/course/altitude, etc. from second to second. These attributes are hard coded and saved in
at 0s game start
at 1s plane created
at 10s plane accelerates at Xm/s/s
at 11s plane speed is X
at 15s plane turns Y degrees
There is a lot more to it, but you get the jist of it.
What I'm trying to do:
As of now this is all hard coded. I am going to be altering the code so that the program can record ANY user specified data and replay it. So for example: instead of the output window listing the plane name/speed/course etc, I want the user to be able to alter a configuration file (dat/xml/txt) for their own types of data, like tracking a biker, giving stuff like miles biked/bike type/rider name/speed etc.
Someone gave me a suggestion to do it in xml files, but I'm not sure. I'm trying to figure out if i can do this with a dat file too, however I am clueless.
Any suggestion will be helpful, all I'm looking for is a nudge in a direction.
thanks for your help
What you could do with for example an XML file is specify a compound type from a number of basic types. Suppose for example that your program recognizes types 'int', 'float', and 'string'. Your XML file for a biker might look something like:
Originally Posted by Bidamin
<var name="speed" type="float">This could be a descriptive string for the variable</var>
<var name="name" type="string">Idem here</var>
Your program would then parse each tag. If it specified a compound, you create a new Compound class. You then read all the subtags and everytime you encounter a variable you add the name/type pair to the list of variables contained in your Compound. You can then access each of these from your C++ program by something akin to a setVar(name, value) and getVar(name, value) members of your Compound.
As for specifying what the program should store in each of these variables you just declared, would require you to implement a system for specifying rules in your XML file. One could thing of something like an Operation class, which parses <operation> tags, similar to the Compound class for the above.
For parsing of XML you should have a look at the QtXML module, specifically the SAX classes should be of interest to you.
There is actually quite a nice and IMHO well and most of all clearly written Qt based program called NifSkope. It basically does what you want, i.e. define custom types, and to a limited extent custom operations on these types, through XML files. I suggest you have a look at their source code.
So your suggesting i create a class "Compound" that has in it a list of variable? sort of like:
and then I parse through the attribute tags and do something along the lines of
Compound biker = new Compound(name = "Biker")
or something like that? And when the record data is imported and put to the output window i can have it match up to the corresponding variables, like if in a section the biker's speed is 10, I set the "current speed" to 10 with the setVar etc.
am i understanding this right?
I think you have the basic idea, yes.