-
Notifications
You must be signed in to change notification settings - Fork 80
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
Make hsStream typed readers and writers type-safe #871
Conversation
This also makes the placement readers and writers type-safe. However, unfortunately the non-placement readers cannot be made type-safe since they return an element rather than accepting one as a parameter. For now, both styles are kept since both have their utility independently of each other.
break; | ||
|
||
case kFloat: | ||
stream->ReadLE(&fFloatVal); | ||
stream->ReadLEDouble(&fFloatVal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
twitch
for( ; i < kNumElements; i++ ) | ||
for (uint32_t i = count; i < kNumElements; i++) | ||
fElements[ i ].Empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point, this needs to be cleaned up. Not in this PR, though.
@@ -84,20 +84,20 @@ plFont::plCharacter::plCharacter() | |||
void plFont::plCharacter::Read( hsStream *s ) | |||
{ | |||
// Rocket science here... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
template <typename T> inline void ReadByte(T*) = delete; | ||
void ReadByte(uint8_t* v) { *v = ReadByte(); } | ||
void ReadByte(int8_t* v) { *v = (int8_t)ReadByte(); } | ||
template <typename T> inline void ReadLE16(T*) = delete; | ||
void ReadLE16(uint16_t* v) { *v = ReadLE16(); } | ||
void ReadLE16(int16_t* v) { *v = (int16_t)ReadLE16(); } | ||
template <typename T> inline void ReadLE32(T*) = delete; | ||
void ReadLE32(uint32_t* v) { *v = ReadLE32(); } | ||
void ReadLE32(int32_t* v) { *v = (int32_t)ReadLE32(); } | ||
template <typename T> inline void ReadLEFloat(T*) = delete; | ||
void ReadLEFloat(float* v) { *v = ReadLEFloat(); } | ||
template <typename T> inline void ReadLEDouble(T*) = delete; | ||
void ReadLEDouble(double* v) { *v = ReadLEDouble(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these should be marked [[nodiscard]]
? I'm assuming the reason for the (void)
when reading and throwing away with (void)s->ReadLE32();
is to silence warnings about return values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I actually did have [[nodiscard]]
at one point (hence the (void)
casts), but I later changed my mind... I could add them back in if preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should prevent future surprises when trying to change the type of a member variable which is also streamed, and also ensures compatibility with 64-bit builds.