D-styled data file
Saaa
empty at needmail.com
Wed Apr 29 07:41:46 PDT 2009
>> I'm still dangling between a full parsing at load and parse on demand.
>> A parse on demand (get) would do the following steps:
>> Get the type of the variable in which the data must be stored (in string
>> format)
>> Search for this type in every line of the char[][], when found check
>> whether the name is the same
>> and then convert the chars to that type and place the data in the
>> variable.
>
> This sounds complicated. Can you decide the input file format? Or is it
> from some other program that you can't change?
The input file format would be like D
Like file.dat from the original post.
I just often have the need to save large arrays and other variables and I
thought
why not just save them like the way I would use them in my modules.
>
> Suppose you already had this get function. How would you use it? An
> example would help.
I use the get functions a few posts back, in the main:
---
void main()
{
char[] filename = `data.dat`;
char[][] file;
try{
file = splitlines( cast(char[])read(filename) );
}
catch{
throw new Exception("Couldn't load : " ~ filename);
}
DData file_dd = new DData(file);
int i;
file_dd.get(`i`, i);
}
---
The data.dat should have a line like this to work:
--- data.dat
int i = 10;
---
I hope it all makes sense :)
More information about the Digitalmars-d-learn
mailing list