diff options
Diffstat (limited to 'include/llvm/Support/BinaryStreamReader.h')
-rw-r--r-- | include/llvm/Support/BinaryStreamReader.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/include/llvm/Support/BinaryStreamReader.h b/include/llvm/Support/BinaryStreamReader.h index f30d82d81b25..77738077f5ff 100644 --- a/include/llvm/Support/BinaryStreamReader.h +++ b/include/llvm/Support/BinaryStreamReader.h @@ -31,6 +31,7 @@ namespace llvm { /// are overridable. class BinaryStreamReader { public: + BinaryStreamReader() = default; explicit BinaryStreamReader(BinaryStreamRef Stream); virtual ~BinaryStreamReader() {} @@ -172,13 +173,29 @@ public: /// \returns a success error code if the data was successfully read, otherwise /// returns an appropriate error code. template <typename T, typename U> - Error - readArray(VarStreamArray<T, U> &Array, uint32_t Size, - typename VarStreamArray<T, U>::ContextType *Context = nullptr) { + Error readArray(VarStreamArray<T, U> &Array, uint32_t Size) { BinaryStreamRef S; if (auto EC = readStreamRef(S, Size)) return EC; - Array = VarStreamArray<T, U>(S, Context); + Array = VarStreamArray<T, U>(S); + return Error::success(); + } + + /// Read a VarStreamArray of size \p Size bytes and store the result into + /// \p Array. Updates the stream's offset to point after the newly read + /// array. Never causes a copy (although iterating the elements of the + /// VarStreamArray may, depending upon the implementation of the underlying + /// stream). + /// + /// \returns a success error code if the data was successfully read, otherwise + /// returns an appropriate error code. + template <typename T, typename U, typename ContextType> + Error readArray(VarStreamArray<T, U> &Array, uint32_t Size, + ContextType &&Context) { + BinaryStreamRef S; + if (auto EC = readStreamRef(S, Size)) + return EC; + Array = VarStreamArray<T, U>(S, std::move(Context)); return Error::success(); } @@ -227,6 +244,9 @@ public: /// \returns the next byte in the stream. uint8_t peek() const; + std::pair<BinaryStreamReader, BinaryStreamReader> + split(uint32_t Offset) const; + private: BinaryStreamRef Stream; uint32_t Offset; |