WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
SmallVectorMemoryBuffer.hpp
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
26#include "wpi/util/SmallVector.hpp"
27#include "wpi/util/raw_ostream.hpp"
28
29namespace wpi::util {
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:
59 SmallVector<uint8_t, 0> m_sv;
60 std::string m_bufferName;
61};
62
63} // namespace wpi::util
@ name
Definition base.h:690
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition MemoryBuffer.hpp:125
@ MemoryBuffer_Malloc
Definition MemoryBuffer.hpp:125
void Init(const uint8_t *bufStart, const uint8_t *bufEnd)
Definition BooleanTopic.hpp:24
BufferKind GetBufferKind() const override
Return information on the memory mechanism used to support the MemoryBuffer.
Definition SmallVectorMemoryBuffer.hpp:56
std::string_view GetBufferIdentifier() const override
Return an identifier for this buffer, typically the filename it was read from.
Definition SmallVectorMemoryBuffer.hpp:54
SmallVectorMemoryBuffer(SmallVectorImpl< uint8_t > &&sv)
Construct an SmallVectorMemoryBuffer from the given SmallVector r-value.
Definition SmallVectorMemoryBuffer.hpp:39
SmallVectorMemoryBuffer(SmallVectorImpl< uint8_t > &&sv, std::string_view name)
Construct a named SmallVectorMemoryBuffer from the given SmallVector r-value and StringRef.
Definition SmallVectorMemoryBuffer.hpp:46
Definition StringMap.hpp:773
Definition raw_os_ostream.hpp:19