DataBuffer.h revision fe6dc6e241c52822710380cec0931351a1d7b2d3
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
17namespace lldb_private {
18
19//----------------------------------------------------------------------
20/// @class DataBuffer DataBuffer.h "lldb/Core/DataBuffer.h"
21/// @brief A pure virtual protocol class for abstracted data buffers.
22///
23/// DataBuffer is an abtract class that gets packaged into a shared pointer
24/// that can use to implement various ways to store data (on the heap,
25/// memory mapped, cached inferior memory). It gets used by DataExtractor
26/// so many DataExtractor objects can share the same data and sub-ranges
27/// of that shared data, and the last object that contains a reference
28/// to the shared data will free it.
29///
30/// Subclasses can implement as many different constructors or member
31/// functions that allow data to be stored in the object's buffer prior
32/// to handing the shared data to clients that use these buffers.
33///
34/// All subclasses must override all of the pure virtual functions as
35/// they are used by clients to access the data. Having a common
36/// interface allows different ways of storing data, yet using it in
37/// one common way.
38///
39/// This class currently expects all data to be available without any
40/// extra calls being made, but we can modify it to optionally get
41/// data on demand with some extra function calls to load the data
42/// before it gets accessed.
43//----------------------------------------------------------------------
44class DataBuffer
45{
46public:
47    //------------------------------------------------------------------
48    /// Destructor
49    ///
50    /// The destructor is virtual as other classes will inherit from
51    /// this class and be downcast to the DataBuffer pure virtual
52    /// interface. The virtual destructor ensures that destructing the
53    /// base class will destruct the class that inherited from it
54    /// correctly.
55    //------------------------------------------------------------------
56    virtual
57    ~DataBuffer()
58    {
59    }
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 *
69    GetBytes () = 0;
70
71    //------------------------------------------------------------------
72    /// Get a const pointer to the data.
73    ///
74    /// @return
75    ///     A const pointer to the bytes owned by this object, or NULL
76    ///     if the object contains no bytes.
77    //------------------------------------------------------------------
78    virtual const uint8_t *
79    GetBytes () const = 0;
80
81    //------------------------------------------------------------------
82    /// Get the number of bytes in the data buffer.
83    ///
84    /// @return
85    ///     The number of bytes this object currently contains.
86    //------------------------------------------------------------------
87    virtual lldb::offset_t
88    GetByteSize() const = 0;
89};
90
91} // namespace lldb_private
92
93#endif  /// #if defined(__cplusplus)
94#endif  /// lldb_DataBuffer_h_
95