c++ - Generating data structures by parsing plain text files -
I have written a file parser for the game, which I am writing to make different aspects of the game easier to change ( Characters / Stages / Things like collision data) For example, I might have such a character class:
class character {public: int x, y; // character of character; * Teammate; } I have set the data structure to read with the same syntax as a C ++ file
character sidekick {X = 12 y ==} Character Ozmuddude {X = 10 Y = 50 Teamat = Sidekick} This will create two data structures and give them a map & lt; Put std :: string in Character * & gt; , where is the key string I gave (in this case, Sidekick and OSDWd). When my parser sees an indicator in a range, such as teammate pointers, then it is smart enough to look at the map to bring the pointer to that data structure. The problem is that I can not declare Sidekick's companions as Avastdead because this character has not been kept in the map yet.
I am trying to find the best way to solve it so that the references to my data structure are objects that have not yet been added to the map. The two most easy solutions I can think of (A) add the ability to declare the data structure or (b) the parser is read through the file twice, once the pointers are made to clear the data Emptied and go through the second time and fill them. The problem with
(A) is that I can also decide which producers will call on the class, and if I say anything further, then I have to separate the constructor from the remaining data, which The problem with B (B) is that I would like to declare my files as Sidekick and Ozoddud I had to be able to take the list of files to read my parser instead of one at a time Ap- pears that it is not too bad, although they can sometimes I want to get a list of files to the file). (B) is also lacking in being unable to use the declared data structures as a producer, but I do not think this is a big deal.
How does it feel like a better approach? Do not I think of the third option? It seems that there should be some sort of clever solution with reference to the indicator context or binding or something ...: - / I think that this is something special that I want to give myself, but any input is welcome .
When you first encounter the context, save it as a reference. After that, you can put a character, or reference or anything on a list of "references that need to be resolved later".
When the file gets run, run through those whose references are and their solution.
Comments
Post a Comment