LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
PDB/Type.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://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,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PDB_TYPE_H
16#define LIEF_PDB_TYPE_H
17#include <cstdint>
18#include <memory>
19#include <string>
20
22#include "LIEF/iterators.hpp"
23#include "LIEF/visibility.h"
24#include "LIEF/optional.hpp"
25#include "LIEF/DebugDeclOpt.hpp"
26
27namespace LIEF {
28namespace pdb {
29
30namespace details {
31class Type;
32class TypeIt;
33}
34
37 public:
38 class Iterator final
39 : public iterator_facade_base<Iterator, std::forward_iterator_tag, Type,
40 std::ptrdiff_t, const Type*, const Type&> {
41 public:
42 using implementation = details::TypeIt;
43 using iterator_facade_base::operator++;
44
46
47 LIEF_API Iterator(std::unique_ptr<details::TypeIt> impl);
48
51
53 LIEF_API Iterator& operator=(Iterator&&) noexcept;
54
56
57 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
58
59 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
60 return !(LHS == RHS);
61 }
62
63 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
65
67
68 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
69 LIEF_API const Type* operator->() const LIEF_LIFETIMEBOUND;
70
73 LIEF_API std::unique_ptr<Type> yield();
74
75 private:
76 void load() const;
77
78 std::unique_ptr<details::TypeIt> impl_;
79 mutable std::unique_ptr<Type> cached_;
80 };
81
82 LIEF_LOCAL Type(std::unique_ptr<details::Type> impl);
83
84 enum class KIND {
85 UNKNOWN = 0,
86 CLASS,
87 POINTER,
88 SIMPLE,
89 ENUM,
90 FUNCTION,
91 MODIFIER,
92 BITFIELD,
93 ARRAY,
94 UNION,
95 STRUCTURE,
96 INTERFACE,
97 };
98
99 KIND kind() const;
100
104
107
109 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
110
111 template<class T>
112 const T* as() const {
113 if (T::classof(this)) {
114 return static_cast<const T*>(this);
115 }
116 return nullptr;
117 }
118
119 static std::unique_ptr<Type>
120 create(std::unique_ptr<details::Type> impl LIEF_LIFETIMEBOUND);
121
122 virtual ~Type();
123
124 protected:
125 std::unique_ptr<details::Type> impl_;
126};
127
128}
129}
130#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:36
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:729
Definition optional.hpp:23
Iterator(const Iterator &)
Iterator(Iterator &&) noexcept
Iterator & operator=(const Iterator &)
Iterator(std::unique_ptr< details::TypeIt > impl)
const Type & operator*() const
std::unique_ptr< Type > yield()
Transfer ownership of the type at the current position to the caller. Returns nullptr if the iterator...
details::TypeIt implementation
Definition PDB/Type.hpp:42
const T * as() const
Definition PDB/Type.hpp:112
Type(std::unique_ptr< details::Type > impl)
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generates a C/C++ definition for this type.
KIND
Definition PDB/Type.hpp:84
virtual ~Type()
static std::unique_ptr< Type > create(std::unique_ptr< details::Type > impl)
optional< uint64_t > size() const
Size of the type. This size should match the value of sizeof(...) applied to this type.
optional< std::string > name() const
Type's name (if present).
KIND kind() const
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition BuildMetadata.hpp:27
Definition BuildMetadata.hpp:25
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46