What it the preferred method to write a class to a file?

Charles D Hixson charleshixsn at earthlink.net
Sat Jul 22 19:15:46 PDT 2006


I'm thinking that I should build two methods, possibly
called write and print where write would export a "binary"
version of the class that is not intended to be human
readable and print would export something with, e.g.,
numbers translated into strings.

It appears as if the methods should be instance methods of
the class.  It looks as if write should be implemented
something like:
void write(Stream stream)
{  stream.writeExact(&this, this.sizeof);	}

Though probably in this version I'd want to include
delimiters, a type id, and a length to facilitate writing
the corresponding read routing (which would need to be a
class method).

It this the best approach?  Also are there any suggestions
as to a reasonable way to specify the type id, so that it
would be the same from run to run?  Should I keep track of
the ids myself (manually)?  If not, how would I know on an
attempt to read which class the type id referred to?



More information about the Digitalmars-d-learn mailing list