Advertisement

Registering a file::write() script method

Started by June 29, 2006 02:37 PM
2 comments, last by Lbas 18 years, 4 months ago
Hi all, I would like to register a standard write file script method with a prototype like this : size_t file::write( void* ptr, size_t size ); such as you could write any kind of data in the file. How guys would you manage to register it (if possible) ? Another way would be to register dedicated write methods for each possible types (like WriteInt8, WriteInt16, etc.), but just wondered if it was possible to stay near to the standard C way to be more flexible, for example if user wants to declare a structure in its script and then write it out in a binary file (without serializing process). PS: same for file::read() of course :) Thanks in advance, Regards, Lbas
Lbas
I don't think this is directly possible atm.
The easyest way would be do define a "cast" function, like "serializable cast(classxy ∈)". You the define a class serializable that holds a pointer to the real object to be serialized. This way you have to only overload one function and you could then do "file::write(cast(classxy), size)".
Advertisement
Or you could just use function overloading.

void write(int,etc)
void write(float,etc)

etc.
Ok thanks,
That's what I done but I innocently hoped there's a more flexible way to do it (by flexible I mean being able to read/write untyped datas so that you can save non registered types, like in C...).
Hurriedly the pointer support :)
Lbas
Lbas

This topic is closed to new replies.

Advertisement