Open DanRStevens opened 5 years ago
Alternative idea:
In Issue #277, I suggested the stream code could look for a T::Write(Stream::Writer& writer)
method to automatically serialize non-trivial objects. A corresponding idea for the Reader side might be to have the stream code provide a Read<T>()
method, which looks for a static T T::Read(Stream::Reader& reader)
factory method. This might enable automatic reading with:
auto artFile = Stream::FileReader("filename.art").Read<ArtFile>();
That syntax would also make it easier to read one-off trivial types:
// int someValue;
// reader.Read(someValue);
auto someValue = reader.Read<int>();
Assuming the template parameter doesn't interfere with existing templated stream methods.
I'll handle adding RValue Reading of a bitmap file in Bitmap.h
We do not support reading a clm or vol from an arbitrary stream (they both use their constructor to read via filename). Are you wanting to add an overload for a stream, both in lvalue and rvalue form? We don't currently have a use case but I am not opposed to the idea either.
Yes, I was thinking of adding Stream overloads to both Vol and CLM files.
Any thoughts about the second alternative idea I suggested? I suppose they aren't mutually exclusive, but I suspect we would only use 1 form in any given project.
Sorry for the very late reply. I would certainly support a factory read function. This would allow easy creation of custom read functions for a class, which I have done on occasion on other C# projects.
It's convenient to be able to load objects from files in 1 line of code. This is easier to do if we are able to load from unnamed temporary stream objects.
Ex:
We should update the library to allow for more wide-spread 1 line loading of various objects from streams.