Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RValue Stream Loading #286

Open
DanRStevens opened this issue Mar 9, 2019 · 4 comments
Open

RValue Stream Loading #286

DanRStevens opened this issue Mar 9, 2019 · 4 comments

Comments

@DanRStevens
Copy link
Member

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:

auto artFile = ArtFile::Read(Stream::FileReader("filename.art"));

We should update the library to allow for more wide-spread 1 line loading of various objects from streams.

@DanRStevens
Copy link
Member Author

DanRStevens commented Mar 9, 2019

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.

@Brett208
Copy link
Member

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.

@DanRStevens
Copy link
Member Author

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.

@Brett208
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants