LLVM  4.0.0
StreamInterface.h
Go to the documentation of this file.
1 //===- StreamInterface.h - Base interface for a stream of data --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
11 #define LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/Support/Error.h"
15 #include <cstdint>
16 
17 namespace llvm {
18 namespace msf {
19 
21 public:
22  virtual ~ReadableStream() = default;
23 
24  // Given an offset into the stream and a number of bytes, attempt to read
25  // the bytes and set the output ArrayRef to point to a reference into the
26  // stream, without copying any data.
27  virtual Error readBytes(uint32_t Offset, uint32_t Size,
28  ArrayRef<uint8_t> &Buffer) const = 0;
29 
30  // Given an offset into the stream, read as much as possible without copying
31  // any data.
33  ArrayRef<uint8_t> &Buffer) const = 0;
34 
35  virtual uint32_t getLength() const = 0;
36 };
37 
39 public:
40  ~WritableStream() override = default;
41 
42  // Attempt to write the given bytes into the stream at the desired offset.
43  // This will always necessitate a copy. Cannot shrink or grow the stream,
44  // only writes into existing allocated space.
45  virtual Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const = 0;
46 
47  virtual Error commit() const = 0;
48 };
49 
50 } // end namespace msf
51 } // end namespace llvm
52 
53 #endif // LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
virtual ~ReadableStream()=default
virtual uint32_t getLength() const =0
uint32_t Offset
virtual Error commit() const =0
~WritableStream() override=default
virtual Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef< uint8_t > &Buffer) const =0
Lightweight error class with error context and mandatory checking.
virtual Error readLongestContiguousChunk(uint32_t Offset, ArrayRef< uint8_t > &Buffer) const =0
virtual Error writeBytes(uint32_t Offset, ArrayRef< uint8_t > Data) const =0