J
jacob navia
In my book of about the C++ stl (Plauger/Stepanov/Lee/Musser) there is
nothing about saving a container to disk or loading it from a
file/stream.
Probably because you overload the << and >> operators for that,
I do not know.
In any case I think the container library in C should have at least
the following additional methods for
(1) Saving a whole container into a stream in text mode
(2) The same in binary mode
(3) Loading a whole container from a stream in text mode
(4) The same in binary mode.
Now, the prototype for Save/Load could be:
container->Vtable->Save(container, Stream, ApplyFunction, arg);
container->Vtable->Load(container, Stream, ApplyFunction, arg);
where:
container: The container we are saving or loading. Should
be empty in the case of load. The library will
call anyway Clear() before loading anything.
Stream: The file where we are reading/writing from/to.
ApplyFunction: Function called for each element in the container.
It defaults to a function that writes the bytes in
the container either in ascii or in binary form.
A value of NULL means default.
arg: Argument to pass to each call of the callback. Can
be NULL.
The prototype for the ApplyFunction is:
int ApplyFn(void *element, void * arg, FILE *stream);
element: Points to the element to be saved/read
arg: Argument passed to the Save or Load function.
stream: File where the data is read or written.
What do you think?
Did I forget something?
Thanks
nothing about saving a container to disk or loading it from a
file/stream.
Probably because you overload the << and >> operators for that,
I do not know.
In any case I think the container library in C should have at least
the following additional methods for
(1) Saving a whole container into a stream in text mode
(2) The same in binary mode
(3) Loading a whole container from a stream in text mode
(4) The same in binary mode.
Now, the prototype for Save/Load could be:
container->Vtable->Save(container, Stream, ApplyFunction, arg);
container->Vtable->Load(container, Stream, ApplyFunction, arg);
where:
container: The container we are saving or loading. Should
be empty in the case of load. The library will
call anyway Clear() before loading anything.
Stream: The file where we are reading/writing from/to.
ApplyFunction: Function called for each element in the container.
It defaults to a function that writes the bytes in
the container either in ascii or in binary form.
A value of NULL means default.
arg: Argument to pass to each call of the callback. Can
be NULL.
The prototype for the ApplyFunction is:
int ApplyFn(void *element, void * arg, FILE *stream);
element: Points to the element to be saved/read
arg: Argument passed to the Save or Load function.
stream: File where the data is read or written.
What do you think?
Did I forget something?
Thanks