style(InputTextStream): Use std::unique_ptr<std::ifstream> - #1425
style(InputTextStream): Use std::unique_ptr<std::ifstream>#1425N-Dekker wants to merge 1 commit into
std::unique_ptr<std::ifstream>#1425Conversation
Avoided manual memory management. Followed the C++ Rule of Zero, by removing the user declared default-constructor and destructor of `InputTextStream`.
700d33e to
6f9573b
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR modernizes the InputTextStream class by replacing manual memory management with std::unique_ptr<std::ifstream>. The changes eliminate the need for explicit destructor and constructor declarations, following the C++ Rule of Zero principle.
- Replaced raw pointer and boolean flag with
std::unique_ptr<std::ifstream> - Removed manual
new/deleteoperations and associated tracking logic - Simplified the class interface by removing user-declared constructor and destructor
| delete m_IStream; | ||
| } | ||
| m_WasmStringStream = nullptr; | ||
| m_InputFileStream = std::make_unique<std::ifstream>(fileName); |
There was a problem hiding this comment.
The file stream is created without checking if the file was successfully opened. Consider adding error handling to verify the stream state after creation, or document that callers should check the stream state via GetPointer().
| m_InputFileStream = std::make_unique<std::ifstream>(fileName); | |
| m_InputFileStream = std::make_unique<std::ifstream>(fileName); | |
| if (!m_InputFileStream->is_open()) | |
| { | |
| throw std::ios_base::failure("Failed to open file: " + fileName); | |
| } |
| delete m_IStream; | ||
| } | ||
| m_WasmStringStream = nullptr; | ||
| m_InputFileStream = std::make_unique<std::ifstream>(fileName); |
There was a problem hiding this comment.
[nitpick] Consider adding the std::ifstream::in flag for consistency with the previous implementation, even though it's the default for ifstream: std::make_unique<std::ifstream>(fileName, std::ifstream::in)
| m_InputFileStream = std::make_unique<std::ifstream>(fileName); | |
| m_InputFileStream = std::make_unique<std::ifstream>(fileName, std::ifstream::in); |
|
This pull request (#1425) is superseded by the following pull request: |
Avoided manual memory management. Followed the C++ Rule of Zero, by removing the user declared default-constructor and destructor of
InputTextStream.