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#include <type_traits>
21#include <utility>
22
23#include "LIEF/iterators.hpp"
24#include "LIEF/visibility.h"
25#include "LIEF/optional.hpp"
26#include "LIEF/DebugDeclOpt.hpp"
27
28namespace LIEF {
29namespace pdb {
30
31namespace details {
32class Type;
33class TypeIt;
34}
35
38 public:
39 class Iterator final
40 : public iterator_facade_base<Iterator, std::forward_iterator_tag, Type,
41 std::ptrdiff_t, const Type*, const Type&> {
42 public:
43 using implementation = details::TypeIt;
44 using iterator_facade_base::operator++;
45
47
48 LIEF_API Iterator(std::unique_ptr<details::TypeIt> impl);
49
52
54 LIEF_API Iterator& operator=(Iterator&&) noexcept;
55
57
58 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
59
60 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
61 return !(LHS == RHS);
62 }
63
64 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
66
67 LIEF_API const Type& operator*() const;
68
69 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
70 LIEF_API const Type* operator->() const;
71
74 LIEF_API std::unique_ptr<Type> yield();
75
76 private:
77 void load() const;
78
79 std::unique_ptr<details::TypeIt> impl_;
80 mutable std::unique_ptr<Type> cached_;
81 };
82
83 LIEF_LOCAL Type(std::unique_ptr<details::Type> impl);
84
85 enum class KIND {
86 UNKNOWN = 0,
87 CLASS,
88 POINTER,
89 SIMPLE,
90 ENUM,
91 FUNCTION,
92 MODIFIER,
93 BITFIELD,
94 ARRAY,
95 UNION,
96 STRUCTURE,
97 INTERFACE,
98 };
99
100 KIND kind() const;
101
105
108
110 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
111
112 template<class T>
113 const T* as() const {
114 if (T::classof(this)) {
115 return static_cast<const T*>(this);
116 }
117 return nullptr;
118 }
119
120 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
121
122 virtual ~Type();
123
124 protected:
125 std::unique_ptr<details::Type> impl_;
126};
127
128}
129}
130#endif
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
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:43
const T * as() const
Definition PDB/Type.hpp:113
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:85
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
Definition BuildMetadata.hpp:26
Definition BuildMetadata.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:40
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:25
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46