]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Utility/DataBuffer.h
MFV r316873: 7233 dir_is_empty should open directory with CLOEXEC
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Utility / DataBuffer.h
1 //===-- DataBuffer.h --------------------------------------------*- 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 liblldb_DataBuffer_h_
11 #define liblldb_DataBuffer_h_
12 #if defined(__cplusplus)
13
14 #include <stdint.h>
15 #include <string.h>
16
17 #include "lldb/lldb-types.h"
18
19 #include "llvm/ADT/ArrayRef.h"
20
21 namespace lldb_private {
22
23 //----------------------------------------------------------------------
24 /// @class DataBuffer DataBuffer.h "lldb/Core/DataBuffer.h"
25 /// @brief A pure virtual protocol class for abstracted data buffers.
26 ///
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.
33 ///
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.
37 ///
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
41 /// one common way.
42 ///
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 //----------------------------------------------------------------------
48 class DataBuffer {
49 public:
50   //------------------------------------------------------------------
51   /// Destructor
52   ///
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
57   /// correctly.
58   //------------------------------------------------------------------
59   virtual ~DataBuffer() {}
60
61   //------------------------------------------------------------------
62   /// Get a pointer to the data.
63   ///
64   /// @return
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;
69
70   //------------------------------------------------------------------
71   /// Get a const pointer to the data.
72   ///
73   /// @return
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;
78
79   //------------------------------------------------------------------
80   /// Get the number of bytes in the data buffer.
81   ///
82   /// @return
83   ///     The number of bytes this object currently contains.
84   //------------------------------------------------------------------
85   virtual lldb::offset_t GetByteSize() const = 0;
86
87   llvm::ArrayRef<uint8_t> GetData() const {
88     return llvm::ArrayRef<uint8_t>(GetBytes(), GetByteSize());
89   }
90
91   llvm::MutableArrayRef<uint8_t> GetData() {
92     return llvm::MutableArrayRef<uint8_t>(GetBytes(), GetByteSize());
93   }
94 };
95
96 } // namespace lldb_private
97
98 #endif /// #if defined(__cplusplus)
99 #endif /// lldb_DataBuffer_h_