LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
PDB/Type.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2024 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 <memory>
18
19#include "LIEF/visibility.h"
20
21namespace LIEF {
22namespace pdb {
23
24namespace details {
25class Type;
26class TypeIt;
27}
28
31 public:
33 public:
34 using iterator_category = std::forward_iterator_tag;
35 using value_type = std::unique_ptr<Type>;
36 using difference_type = std::ptrdiff_t;
37 using pointer = Type*;
38 using reference = Type&;
39 using implementation = details::TypeIt;
40
42 // Inspired from LLVM's iterator_facade_base
43 friend class Iterator;
44 public:
45 pointer operator->() const { return R.get(); }
46
47 private:
48 value_type R;
49
50 template <typename RefT>
51 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
52 };
53
55 Iterator(Iterator&&) noexcept;
56 Iterator(std::unique_ptr<details::TypeIt> impl);
58
59 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
60
61 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
62 return !(LHS == RHS);
63 }
64
66
68 Iterator tmp = *static_cast<Iterator*>(this);
69 ++*static_cast<Iterator *>(this);
70 return tmp;
71 }
72
73 std::unique_ptr<Type> operator*() const;
74
76 return static_cast<const Iterator*>(this)->operator*();
77 }
78
79 private:
80 std::unique_ptr<details::TypeIt> impl_;
81 };
82
83 enum class KIND {
84 UNKNOWN = 0,
85 CLASS,
86 POINTER,
87 SIMPLE,
88 ENUM,
89 FUNCTION,
90 MODIFIER,
91 BITFIELD,
92 ARRAY,
93 UNION,
94 STRUCTURE,
95 INTERFACE,
96 };
97
98 KIND kind() const;
99
100 template<class T>
101 const T* as() const {
102 if (T::classof(this)) {
103 return static_cast<const T*>(this);
104 }
105 return nullptr;
106 }
107
108 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
109
110 virtual ~Type();
111
112 protected:
113 Type(std::unique_ptr<details::Type> impl);
114 std::unique_ptr<details::Type> impl_;
115};
116
117}
118}
119#endif
120
Definition PDB/Type.hpp:41
pointer operator->() const
Definition PDB/Type.hpp:45
Definition PDB/Type.hpp:32
Iterator(const Iterator &)
Iterator(Iterator &&) noexcept
PointerProxy operator->() const
Definition PDB/Type.hpp:75
std::unique_ptr< Type > value_type
Definition PDB/Type.hpp:35
std::forward_iterator_tag iterator_category
Definition PDB/Type.hpp:34
std::unique_ptr< Type > operator*() const
details::TypeIt implementation
Definition PDB/Type.hpp:39
std::ptrdiff_t difference_type
Definition PDB/Type.hpp:36
Iterator operator++(int)
Definition PDB/Type.hpp:67
This is the base class for any PDB type.
Definition PDB/Type.hpp:30
const T * as() const
Definition PDB/Type.hpp:101
KIND
Definition PDB/Type.hpp:83
virtual ~Type()
static std::unique_ptr< Type > create(std::unique_ptr< details::Type > impl)
KIND kind() const
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41