1 //===-- DataBuffer.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_DataBuffer_h_
11 #define liblldb_DataBuffer_h_
12 #if defined(__cplusplus)
17 #include "lldb/lldb-types.h"
19 #include "llvm/ADT/ArrayRef.h"
21 namespace lldb_private {
23 //----------------------------------------------------------------------
24 /// @class DataBuffer DataBuffer.h "lldb/Core/DataBuffer.h"
25 /// @brief A pure virtual protocol class for abstracted data buffers.
27 /// DataBuffer is an abstract class that gets packaged into a shared pointer
28 /// that can use to implement various ways to store data (on the heap,
29 /// memory mapped, cached inferior memory). It gets used by DataExtractor
30 /// so many DataExtractor objects can share the same data and sub-ranges
31 /// of that shared data, and the last object that contains a reference
32 /// to the shared data will free it.
34 /// Subclasses can implement as many different constructors or member
35 /// functions that allow data to be stored in the object's buffer prior
36 /// to handing the shared data to clients that use these buffers.
38 /// All subclasses must override all of the pure virtual functions as
39 /// they are used by clients to access the data. Having a common
40 /// interface allows different ways of storing data, yet using it in
43 /// This class currently expects all data to be available without any
44 /// extra calls being made, but we can modify it to optionally get
45 /// data on demand with some extra function calls to load the data
46 /// before it gets accessed.
47 //----------------------------------------------------------------------
50 //------------------------------------------------------------------
53 /// The destructor is virtual as other classes will inherit from
54 /// this class and be downcast to the DataBuffer pure virtual
55 /// interface. The virtual destructor ensures that destructing the
56 /// base class will destruct the class that inherited from it
58 //------------------------------------------------------------------
59 virtual ~DataBuffer() {}
61 //------------------------------------------------------------------
62 /// Get a pointer to the data.
65 /// A pointer to the bytes owned by this object, or NULL if the
66 /// object contains no bytes.
67 //------------------------------------------------------------------
68 virtual uint8_t *GetBytes() = 0;
70 //------------------------------------------------------------------
71 /// Get a const pointer to the data.
74 /// A const pointer to the bytes owned by this object, or NULL
75 /// if the object contains no bytes.
76 //------------------------------------------------------------------
77 virtual const uint8_t *GetBytes() const = 0;
79 //------------------------------------------------------------------
80 /// Get the number of bytes in the data buffer.
83 /// The number of bytes this object currently contains.
84 //------------------------------------------------------------------
85 virtual lldb::offset_t GetByteSize() const = 0;
87 llvm::ArrayRef<uint8_t> GetData() const {
88 return llvm::ArrayRef<uint8_t>(GetBytes(), GetByteSize());
91 llvm::MutableArrayRef<uint8_t> GetData() {
92 return llvm::MutableArrayRef<uint8_t>(GetBytes(), GetByteSize());
96 } // namespace lldb_private
98 #endif /// #if defined(__cplusplus)
99 #endif /// lldb_DataBuffer_h_