Comment #0 by bioinfornatics — 2013-03-14T03:45:19Z
Dear,
When you need to manage various file format and trying to fit as a phobos File it appear below feature could be really interesting.
by example you have a parser you want to construct is from various file type you can grant some methods.
-----------------------------------------------------------
template isFileType(F)
{
enum bool isFileType = is(typeof(
{
ubyte[] buf;
F f = void; // can define a FileType object
if (f.eof) {} // can test for end of file
if (f.isOpen) {} // can test for opened file
f.name; // can invoke name
f.close(); // can invoke close
r.write(); // can invoke write()
r.rawWrite( "" ); // can invoke rawWrite()
r.rawRead( buf ); // can invoke rawRead()
}));
}
struct FileType( F ) if( isFileType( F ) )
{
F _f;
this( F file ){
_f = file;
}
alias _f this;
}
Comment #1 by bioinfornatics — 2013-03-17T17:29:05Z