WPILibC++ 2024.3.2
SmallVectorMemoryBuffer.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5//===- SmallVectorMemoryBuffer.h --------------------------------*- C++ -*-===//
6//
7// The LLVM Compiler Infrastructure
8//
9// This file is distributed under the University of Illinois Open Source
10// License. See LICENSE.TXT for details.
11//
12//===----------------------------------------------------------------------===//
13//
14// This file declares a wrapper class to hold the memory into which an
15// object will be generated.
16//
17//===----------------------------------------------------------------------===//
18
19#pragma once
20
21#include <string>
22#include <string_view>
23#include <utility>
24
25#include "wpi/MemoryBuffer.h"
26#include "wpi/SmallVector.h"
27#include "wpi/raw_ostream.h"
28
29namespace wpi {
30
31/// SmallVector-backed MemoryBuffer instance.
32///
33/// This class enables efficient construction of MemoryBuffers from SmallVector
34/// instances.
36 public:
37 /// Construct an SmallVectorMemoryBuffer from the given SmallVector
38 /// r-value.
40 : m_sv(std::move(sv)), m_bufferName("<in-memory object>") {
41 Init(this->m_sv.begin(), this->m_sv.end());
42 }
43
44 /// Construct a named SmallVectorMemoryBuffer from the given
45 /// SmallVector r-value and StringRef.
47 : m_sv(std::move(sv)), m_bufferName(name) {
48 Init(this->m_sv.begin(), this->m_sv.end());
49 }
50
51 // Key function.
53
54 std::string_view GetBufferIdentifier() const override { return m_bufferName; }
55
56 BufferKind GetBufferKind() const override { return MemoryBuffer_Malloc; }
57
58 private:
60 std::string m_bufferName;
61};
62
63} // namespace wpi
This file defines the SmallVector class.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:45
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition: MemoryBuffer.h:125
@ MemoryBuffer_Malloc
Definition: MemoryBuffer.h:125
void Init(const uint8_t *bufStart, const uint8_t *bufEnd)
SmallVector-backed MemoryBuffer instance.
Definition: SmallVectorMemoryBuffer.h:35
SmallVectorMemoryBuffer(SmallVectorImpl< uint8_t > &&sv)
Construct an SmallVectorMemoryBuffer from the given SmallVector r-value.
Definition: SmallVectorMemoryBuffer.h:39
std::string_view GetBufferIdentifier() const override
Return an identifier for this buffer, typically the filename it was read from.
Definition: SmallVectorMemoryBuffer.h:54
BufferKind GetBufferKind() const override
Return information on the memory mechanism used to support the MemoryBuffer.
Definition: SmallVectorMemoryBuffer.h:56
SmallVectorMemoryBuffer(SmallVectorImpl< uint8_t > &&sv, std::string_view name)
Construct a named SmallVectorMemoryBuffer from the given SmallVector r-value and StringRef.
Definition: SmallVectorMemoryBuffer.h:46
iterator begin()
Definition: SmallVector.h:272
basic_string_view< char > string_view
Definition: core.h:501
Definition: array.h:89
Definition: ntcore_cpp.h:26