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

Make hsStream typed readers and writers type-safe #871

Merged
merged 2 commits into from
Mar 14, 2021
Merged

Conversation

zrax
Copy link
Member

@zrax zrax commented Mar 12, 2021

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.

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);
Copy link
Member

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();
Copy link
Member

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...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Comment on lines +130 to +142
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(); }
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zrax zrax merged commit 08ef0f5 into H-uru:master Mar 14, 2021
@zrax zrax deleted the streams branch March 14, 2021 04:31
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

Successfully merging this pull request may close these issues.

None yet

2 participants