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 /// 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, memory
29 /// mapped, cached inferior memory). It gets used by DataExtractor so many
30 /// DataExtractor objects can share the same data and sub-ranges of that
31 /// shared data, and the last object that contains a reference to the shared
32 /// 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 to
36 /// handing the shared data to clients that use these buffers.
38 /// All subclasses must override all of the pure virtual functions as they are
39 /// used by clients to access the data. Having a common interface allows
40 /// different ways of storing data, yet using it in one common way.
42 /// This class currently expects all data to be available without any extra
43 /// calls being made, but we can modify it to optionally get data on demand
44 /// with some extra function calls to load the data before it gets accessed.
45 //----------------------------------------------------------------------
48 //------------------------------------------------------------------
51 /// The destructor is virtual as other classes will inherit from this class
52 /// and be downcast to the DataBuffer pure virtual interface. The virtual
53 /// destructor ensures that destructing the base class will destruct the
54 /// class that inherited from it correctly.
55 //------------------------------------------------------------------
56 virtual ~DataBuffer() {}
58 //------------------------------------------------------------------
59 /// Get a pointer to the data.
62 /// A pointer to the bytes owned by this object, or NULL if the
63 /// object contains no bytes.
64 //------------------------------------------------------------------
65 virtual uint8_t *GetBytes() = 0;
67 //------------------------------------------------------------------
68 /// Get a const pointer to the data.
71 /// A const pointer to the bytes owned by this object, or NULL
72 /// if the object contains no bytes.
73 //------------------------------------------------------------------
74 virtual const uint8_t *GetBytes() const = 0;
76 //------------------------------------------------------------------
77 /// Get the number of bytes in the data buffer.
80 /// The number of bytes this object currently contains.
81 //------------------------------------------------------------------
82 virtual lldb::offset_t GetByteSize() const = 0;
84 llvm::ArrayRef<uint8_t> GetData() const {
85 return llvm::ArrayRef<uint8_t>(GetBytes(), GetByteSize());
88 llvm::MutableArrayRef<uint8_t> GetData() {
89 return llvm::MutableArrayRef<uint8_t>(GetBytes(), GetByteSize());
93 } // namespace lldb_private
95 #endif /// #if defined(__cplusplus)
96 #endif /// lldb_DataBuffer_h_