Reputation: 1273
I need to import an ascii file with a custom file-format.
Some data is stored in blocks, with a start block and end block. Other data is stored without block delimiters.
One example is:
$Sheet
S posx posy dimx dimy
List of Sheet Labels
$EndSheet
Another is:
Text Notes posx posy orientation dimension ~
Text
Now what would be the best/most generic way to import these data into some kind of structure?
Regards
Jakob Justesen
Upvotes: 0
Views: 431
Reputation: 1550
You're going to need to read a line: if it's a block start then hand off to a method that will handle a block read. If it's not, then hand off to a method that will handle a non-block read.
The most "generic" way to do that is to have a factory method that returns you the requisite Reader class. Some pseudo code might look like this:
Open [File]
while not EOF
Read [Line]
var [Reader] = ReaderFactory.GetReader([Line])
var [Record] = [Reader].Read([File])
Do what you want with record
wend
Close [File]
How you represent the different record types I leave as an exercise for you :)
Upvotes: 1