LLDB mainline
ByteSizedType.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLIKE_BYTESIZEDTYPE_H
10#define LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLIKE_BYTESIZEDTYPE_H
11
12#include <cstdint>
13#include <optional>
14#include <utility>
15
16namespace lldb_private {
17namespace clike {
18
19/// Represents type with a fixed byte size.
20///
21/// This is only used for types that do not derive their size from another type.
22template <typename Base> class ByteSizedType : public Base {
23public:
24 /// \p byte_size is std::nullopt if unknown.
25 ///
26 /// Any remaining arguments are forwarded to \p Base.
27 template <typename... Args>
28 explicit ByteSizedType(std::optional<uint64_t> byte_size, Args &&...args)
29 : Base(std::forward<Args>(args)...), m_byte_size(byte_size) {}
30
31 std::optional<uint64_t> GetByteSize() const override { return m_byte_size; }
32
33protected:
34 /// Used by records, whose size might only be known after completion.
35 void SetByteSize(std::optional<uint64_t> byte_size) {
36 m_byte_size = byte_size;
37 }
38
39private:
40 // TODO: We could maybe save some memory here by using a sentinel value.
41 std::optional<uint64_t> m_byte_size;
42};
43
44} // namespace clike
45} // namespace lldb_private
46
47#endif // LLDB_SOURCE_PLUGINS_TYPESYSTEM_CLIKE_BYTESIZEDTYPE_H
A command line argument class.
Definition Args.h:33
std::optional< uint64_t > GetByteSize() const override
void SetByteSize(std::optional< uint64_t > byte_size)
Used by records, whose size might only be known after completion.
std::optional< uint64_t > m_byte_size
ByteSizedType(std::optional< uint64_t > byte_size, Args &&...args)
byte_size is std::nullopt if unknown.
A class that represents a running process on the host machine.