LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
ObjC/Class.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_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}
36class LIEF_API Class {
39 public:
40 class LIEF_API Iterator {
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
62 Iterator(const Iterator&);
63 Iterator(Iterator&&) noexcept;
64 Iterator(std::unique_ptr<details::ClassIt> impl);
65 ~Iterator();
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
73 Iterator& operator++();
74 Iterator& operator--();
75
76 Iterator operator--(int) {
77 Iterator tmp = *static_cast<Iterator*>(this);
78 --*static_cast<Iterator *>(this);
79 return tmp;
80 }
81
82 Iterator operator++(int) {
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
90 PointerProxy operator->() const {
91 return static_cast<const Iterator*>(this)->operator*();
92 }
93
94 private:
95 std::unique_ptr<details::ClassIt> impl_;
96 };
97
98 public: using methods_t = iterator_range<Method::Iterator>;
101 using protocols_t = iterator_range<Protocol::Iterator>;
104 using properties_t = iterator_range<Property::Iterator>;
107 using ivars_t = iterator_range<IVar::Iterator>;
110
111 Class(std::unique_ptr<details::Class> impl);
112 std::string name() const;
115 std::string demangled_name() const;
118 std::unique_ptr<Class> super_class() const;
121
122 bool is_meta() const;
123 methods_t methods() const;
126 protocols_t protocols() const;
129 properties_t properties() const;
132 ivars_t ivars() const;
135 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
pointer operator->() const
Definition ObjC/Class.hpp:53
std::unique_ptr< Class > operator*() const
Iterator operator--(int)
Definition ObjC/Class.hpp:76
PointerProxy operator->() const
Definition ObjC/Class.hpp:90
Iterator(const Iterator &)
Iterator operator++(int)
Definition ObjC/Class.hpp:82
Iterator(Iterator &&) noexcept
This class represents an Objective-C class (@interface)
Definition ObjC/Class.hpp:38
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.
ivars_t ivars() const
Iterator over the different instance variables defined in this class.
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:36
#define LIEF_API
Definition visibility.h:41