LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ObjC/Class.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2025 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_OBJC_CLASS_H
16#define LIEF_OBJC_CLASS_H
17
18#include <LIEF/visibility.h>
19
20#include <LIEF/ObjC/IVar.hpp>
22#include <LIEF/ObjC/Method.hpp>
24#include <LIEF/ObjC/DeclOpt.hpp>
25
26#include <memory>
27#include <string>
28
29namespace LIEF {
30namespace objc {
31
32namespace details {
33class Class;
34class ClassIt;
35}
36
39 public:
41 public:
42 using iterator_category = std::bidirectional_iterator_tag;
43 using value_type = std::unique_ptr<Class>;
44 using difference_type = std::ptrdiff_t;
45 using pointer = Class*;
46 using reference = std::unique_ptr<Class>&;
47 using implementation = details::ClassIt;
48
49 class LIEF_API PointerProxy {
50 // Inspired from LLVM's iterator_facade_base
51 friend class Iterator;
52 public:
53 pointer operator->() const { return R.get(); }
54
55 private:
56 value_type R;
57
58 template <typename RefT>
59 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
60 };
61
63 Iterator(Iterator&&) noexcept;
64 Iterator(std::unique_ptr<details::ClassIt> impl);
66
67 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
68
69 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
70 return !(LHS == RHS);
71 }
72
75
77 Iterator tmp = *static_cast<Iterator*>(this);
78 --*static_cast<Iterator *>(this);
79 return tmp;
80 }
81
83 Iterator tmp = *static_cast<Iterator*>(this);
84 ++*static_cast<Iterator *>(this);
85 return tmp;
86 }
87
88 std::unique_ptr<Class> operator*() const;
89
91 return static_cast<const Iterator*>(this)->operator*();
92 }
93
94 private:
95 std::unique_ptr<details::ClassIt> impl_;
96 };
97
98 public:
101
104
107
110
111 Class(std::unique_ptr<details::Class> impl);
112
114 std::string name() const;
115
117 std::string demangled_name() const;
118
120 std::unique_ptr<Class> super_class() const;
121
122 bool is_meta() const;
123
126
129
132
134 ivars_t ivars() const;
135
139 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
140
142 private:
143 std::unique_ptr<details::Class> impl_;
144};
145
146}
147}
148#endif
Definition iterators.hpp:486
Definition ObjC/Class.hpp:49
pointer operator->() const
Definition ObjC/Class.hpp:53
friend class Iterator
Definition ObjC/Class.hpp:51
std::unique_ptr< Class > operator*() const
details::ClassIt implementation
Definition ObjC/Class.hpp:47
Iterator operator--(int)
Definition ObjC/Class.hpp:76
PointerProxy operator->() const
Definition ObjC/Class.hpp:90
std::unique_ptr< Class > & reference
Definition ObjC/Class.hpp:46
Iterator(const Iterator &)
std::ptrdiff_t difference_type
Definition ObjC/Class.hpp:44
Iterator operator++(int)
Definition ObjC/Class.hpp:82
std::bidirectional_iterator_tag iterator_category
Definition ObjC/Class.hpp:42
Class * pointer
Definition ObjC/Class.hpp:45
Iterator(Iterator &&) noexcept
std::unique_ptr< Class > value_type
Definition ObjC/Class.hpp:43
This class represents an Objective-C class (@interface).
Definition ObjC/Class.hpp:38
iterator_range< Method::Iterator > methods_t
Iterator for the class's method.
Definition ObjC/Class.hpp:100
bool is_meta() const
std::string name() const
Name of the class.
properties_t properties() const
Iterator over the properties of this class.
Class(std::unique_ptr< details::Class > impl)
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generate a header-like string for this specific class.
std::unique_ptr< Class > super_class() const
Parent class in case of inheritance.
iterator_range< Property::Iterator > properties_t
Iterator for the properties declared by this class.
Definition ObjC/Class.hpp:106
ivars_t ivars() const
Iterator over the different instance variables defined in this class.
iterator_range< Protocol::Iterator > protocols_t
Iterator for the protocols implemented by this class.
Definition ObjC/Class.hpp:103
iterator_range< IVar::Iterator > ivars_t
Iterator for the instance variables defined by this class.
Definition ObjC/Class.hpp:109
methods_t methods() const
Iterator over the different methods defined by this class.
std::string demangled_name() const
Demangled name of the class.
protocols_t protocols() const
Iterator over the different protocols implemented by this class.
Definition ObjC/Class.hpp:32
Namespace related to ObjC metadata.
Definition MachO/Binary.hpp:41
LIEF namespace.
Definition Abstract/Binary.hpp:40
This structure wraps options to tweak the generated output of functions like LIEF::objc::Metadata::to...
Definition DeclOpt.hpp:22
#define LIEF_API
Definition visibility.h:41