LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
ObjC/Class.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_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
53 public:
55 return R.get();
56 }
57
58 private:
59 value_type R;
60
61 template<typename RefT>
62 PointerProxy(RefT&& R) :
63 R(std::forward<RefT>(R)) {
64 } // NOLINT(bugprone-forwarding-reference-overload)
65 };
66
68 Iterator(Iterator&&) noexcept;
69 Iterator(std::unique_ptr<details::ClassIt> impl);
71
72 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
73
74 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
75 return !(LHS == RHS);
76 }
77
80
82 Iterator tmp = *static_cast<Iterator*>(this);
83 --*static_cast<Iterator*>(this);
84 return tmp;
85 }
86
88 Iterator tmp = *static_cast<Iterator*>(this);
89 ++*static_cast<Iterator*>(this);
90 return tmp;
91 }
92
93 std::unique_ptr<Class> operator*() const;
94
96 return static_cast<const Iterator*>(this)->operator*();
97 }
98
99 private:
100 std::unique_ptr<details::ClassIt> impl_;
101 };
102
103 public:
106
109
112
115
116 Class(std::unique_ptr<details::Class> impl);
117
119 std::string name() const;
120
122 std::string demangled_name() const;
123
125 std::unique_ptr<Class> super_class() const;
126
127 bool is_meta() const;
128
131
134
137
139 ivars_t ivars() const;
140
144 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
145
147
148 private:
149 std::unique_ptr<details::Class> impl_;
150};
151
152}
153}
154#endif
Definition iterators.hpp:510
Definition ObjC/Class.hpp:49
pointer operator->() const
Definition ObjC/Class.hpp:54
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:81
PointerProxy operator->() const
Definition ObjC/Class.hpp:95
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:87
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:105
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:111
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:108
iterator_range< IVar::Iterator > ivars_t
Iterator for the instance variables defined by this class.
Definition ObjC/Class.hpp:114
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:43