Deprecated readString() method so it is always clear if you want to read a binary encoded string or the file as string. Also added possibility to open a memory stream from any span.
This commit is contained in:
@@ -137,14 +137,25 @@ public:
|
||||
return writeSpan(std::span(std::forward<TItBegin>(begin), std::forward<TItEnd>(end)));
|
||||
}
|
||||
|
||||
StreamError readString(std::string& outString);
|
||||
StreamError writeString(std::string_view str);
|
||||
StreamError readBinaryString(std::string& outString);
|
||||
StreamError writeBinaryString(std::string_view str);
|
||||
|
||||
[[deprecated("Use readBinaryString() or readAsString() instead.")]]
|
||||
inline StreamError readString(std::string& outString) { return readBinaryString(outString); }
|
||||
|
||||
[[deprecated("Use writeBinaryString() or writeText() instead.")]]
|
||||
inline StreamError writeString(std::string_view str) { return writeBinaryString(str); }
|
||||
|
||||
StreamError getTotalLength(std::size_t& outLength);
|
||||
StreamError readRest(TypelessBuffer& outBuffer);
|
||||
|
||||
template<typename TChar = char>
|
||||
StreamError readAsString(std::basic_string<TChar>& outString);
|
||||
|
||||
inline StreamError writeText(std::string_view str)
|
||||
{
|
||||
return writeSpan(str);
|
||||
}
|
||||
};
|
||||
|
||||
class FileStream : public Stream
|
||||
@@ -181,7 +192,14 @@ private:
|
||||
bool canWrite_ = false;
|
||||
public:
|
||||
void openRW(std::span<std::uint8_t> data);
|
||||
void openRO(std::span<const std::uint8_t> data);
|
||||
template<typename T>
|
||||
void openRO(std::span<T> data) {
|
||||
openROImpl(data.data(), data.size_bytes());
|
||||
}
|
||||
template<typename TChar>
|
||||
inline void openRO(std::basic_string_view<TChar> stringView) {
|
||||
openROImpl(stringView.data(), stringView.size() * sizeof(TChar));
|
||||
}
|
||||
void close();
|
||||
[[nodiscard]] inline bool isOpen() const { return data_.data() != nullptr; }
|
||||
[[nodiscard]] inline std::size_t availableBytes() const {
|
||||
@@ -196,6 +214,8 @@ public:
|
||||
StreamError seek(std::intptr_t pos, SeekMode seekMode = SeekMode::ABSOLUTE) override;
|
||||
bool isAtEnd() override;
|
||||
StreamFeatures getFeatures() override;
|
||||
private:
|
||||
void openROImpl(const void* data, std::size_t bytes);
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user