D styled data format, Json failed

Saaa empty at needmail.com
Tue May 5 19:56:05 PDT 2009


My first stab at the get function.
As you might see, I need help :D
Thanks!

How do I make the function take a variadic argument and get its type?

//I guess the void pointer isn't the correct way, but I don't know any other 
way
void get(in char[][] file, in char[] indentifier, void* var)
{

TypeInfo type = typeof(var);
int row;

// Is it possible to check it is an array, no matter the depth?
if ( !( type ==  typeid(int) || type == typeid(int[][])  ) ) // || etc
{
  throw new exception;
  //which kind of exception should I throw?
}

if (file.length == 0 || file.length >int.max)
{
  throw new exception;
  //ditto
}

//gets the row number of the first correct occurence for which the following 
is true
//( file[row][0..len] ==  type.stringof ~ ' ' ~ identifier )
row = getRow(file, type, identifier);
if (row < 0 || row >=line.length)
{
  throw new exception;
  //same question :)
}
//parses the file from row
//what is the prototype of a function which has a variadic return type?
var = parse(file, row, type, identifier);
//can all types hold null?
if (var == null)
{
  throw new exception;
  //again
}

return;
} 




More information about the Digitalmars-d-learn mailing list