D-styled data file

Saaa empty at needmail.com
Tue Apr 28 11:46:20 PDT 2009


I changed the prototype to:

void get(in char[] varName, ...)

I'm not totally happy with it because I only need one variadic argument and 
:

How do I get the .stringof of an variadic type?
_arguments[0].stringof doesn't work :)

How do I mutate the original argument? (ref)

Please tell me if I'm on the totally wrong track here.

---
module ddata.main;

import std.file;
import std.stdio;
import std.string;


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);
}


class DData
{

 private char[][] _file;

 this(char[][] file)
 {
  _file = file.dup;
 }

 void get(in char[] varName, ...)
 {
  char[] type = _arguments[0].stringof;
  writefln (type);
  foreach(int i, char[] line; _file)
  {
   if(line[0..type.length] == type)
   {
   writefln (i);
   break;
   }
   writefln (`failed`);
  }
 }
}
--- 




More information about the Digitalmars-d-learn mailing list