Some Direction Needed

This is a discussion on Some Direction Needed within the C++ Programming forums, part of the General Programming Boards category; Hello all I am looking for someone to point me in the right direction for this c++ project I'm working ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Some Direction Needed

    Hello all

    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:

    Code:
    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
    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

    Code:
    struct plane{.....}
    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

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by Bidamin View Post
    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:

    <compound name="biker">
    <var name="speed" type="float">This could be a descriptive string for the variable</var>
    <var name="name" type="string">Idem here</var>
    </compound>

    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.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    2
    So your suggesting i create a class "Compound" that has in it a list of variable? sort of like:

    Code:
    Compound biker = new Compound(name = "Biker")
    and then I parse through the attribute tags and do something along the lines of

    Code:
    biker.addVar(int, "speed"); 
    biker.addVar(string, "name");
    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?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    I think you have the basic idea, yes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mouse Maze Problem
    By Furbiesandbeans in forum C++ Programming
    Replies: 13
    Last Post: 04-28-2008, 05:20 PM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  3. major help needed
    By Leeman_s in forum Windows Programming
    Replies: 5
    Last Post: 12-24-2002, 10:23 PM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM
  5. Classic problem doesn't accept direction
    By cheesehead in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2001, 06:32 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21