The simple way to do this is with state and tokenization. That is, you break the problem down as follows:
- Initialize your parser state. This allows you to keep track of 'where' you are, logically, in the file -- for example, when you read a header-like line ([LEVEL 0], [STATIC]) you update your parse state to reflect this somehow. This allows you to gauge how you should interpret the tokens on each line.
- You read each line -- the complete, entire line -- and break it up into tokens. This is usually done by splitting on whitespace, producing a std::vector<std::string>> or the like contain each non-whitespace token from that line.Boost has some string manipulation routines that can help with this.
- You exhaust each element of the vector you just read, handling it appropriately based on your state. This is achieved simply by some kind of switch statement based on your state (or nested if/else pairs if your state is too complex for a switch, but it doesn't look like yours needs to be, offhand) and then a loop over each item in the vector from the previous step.
For example, if you are in the [STATIC] state, you know that each line has a certain format and contains certain values in specific indices of the resulting token vector (e.g., object name is the 0th element). This also allows you some measure of error checking.
You seem to have the basic concept down, or at least partially formed, but your code could use some cleanup and reorganization. In particular, you're reading everything into locally-scoped vectors that get blown away when the scope exits. You're also not reading the line and tokenizing in favor of just using the formatted IO operators to pick everything up based on whitespace -- this is also acceptable in practice, although I personally find it annoying to maintain.
To solve your issue with respect to
Quote:
For example
I have a tile and attached to that tile is how many tiles, the image name, the image mask, its width and height.
Then when the level loads it picks the object and places it at the x and y cords.
Right now I am using a tone of vectors but there not connected in any way. I need one vector with many properties.
it sounds like you need to create yourself a Tile class or struct, and maintain a vector of Tile objects that you construct and fill as you read each tile section of the file -- similar to how you have a Sprite object.