Pigweed
 
Loading...
Searching...
No Matches
linker_symbol.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <cstdint>
17#include <type_traits>
18
19#include "lib/stdcompat/bit.h"
20
21namespace pw {
22
51template <class T = uintptr_t>
53 public:
54 LinkerSymbol() = delete;
55 ~LinkerSymbol() = delete;
56 LinkerSymbol(const LinkerSymbol&) = delete;
57 LinkerSymbol(const LinkerSymbol&&) = delete;
58 LinkerSymbol& operator=(const LinkerSymbol&) = delete;
59 LinkerSymbol& operator=(const LinkerSymbol&&) = delete;
60
62 T value() const {
63 static_assert(std::is_integral_v<T> || std::is_enum_v<T>);
64 static_assert(sizeof(T) <= sizeof(uintptr_t));
65 return static_cast<T>(raw_value());
66 }
67
68 private:
70 uintptr_t raw_value() const { return cpp20::bit_cast<uintptr_t>(this); }
71};
72
73} // namespace pw
Definition: linker_symbol.h:52
T value() const
Gets the value of this linker symbol, converted to the specified type.
Definition: linker_symbol.h:62
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27