LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
Protocol.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_PROTOCOL_H
16#define LIEF_OBJC_PROTOCOL_H
17#include <LIEF/visibility.h>
18#include <LIEF/iterators.hpp>
19
20#include <LIEF/ObjC/Method.hpp>
22#include <LIEF/ObjC/DeclOpt.hpp>
23
24#include <memory>
25#include <string>
26
27namespace LIEF {
28namespace objc {
29
30namespace details {
31class Protocol;
32class ProtocolIt;
33}
34
37 public:
39 public:
40 using iterator_category = std::bidirectional_iterator_tag;
41 using value_type = std::unique_ptr<Protocol>;
42 using difference_type = std::ptrdiff_t;
43 using pointer = Protocol*;
44 using reference = std::unique_ptr<Protocol>&;
45 using implementation = details::ProtocolIt;
46
47 class LIEF_API PointerProxy {
48 // Inspired from LLVM's iterator_facade_base
49 friend class Iterator;
50
51 public:
53 return R.get();
54 }
55
56 private:
57 value_type R;
58
59 template<typename RefT>
60 PointerProxy(RefT&& R) :
61 R(std::forward<RefT>(R)) {
62 } // NOLINT(bugprone-forwarding-reference-overload)
63 };
64
66 Iterator(Iterator&&) noexcept;
67 Iterator(std::unique_ptr<details::ProtocolIt> impl);
69
70 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
71
72 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
73 return !(LHS == RHS);
74 }
75
78
80 Iterator tmp = *static_cast<Iterator*>(this);
81 --*static_cast<Iterator*>(this);
82 return tmp;
83 }
84
86 Iterator tmp = *static_cast<Iterator*>(this);
87 ++*static_cast<Iterator*>(this);
88 return tmp;
89 }
90
91 std::unique_ptr<Protocol> operator*() const;
92
94 return static_cast<const Iterator*>(this)->operator*();
95 }
96
97 private:
98 std::unique_ptr<details::ProtocolIt> impl_;
99 };
100
101 public:
104
105 Protocol(std::unique_ptr<details::Protocol> impl);
106
108 std::string mangled_name() const;
109
112
115
118
122 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
123
125
126 private:
127 std::unique_ptr<details::Protocol> impl_;
128};
129
130}
131}
132#endif
Definition iterators.hpp:567
pointer operator->() const
Definition Protocol.hpp:52
friend class Iterator
Definition Protocol.hpp:49
std::ptrdiff_t difference_type
Definition Protocol.hpp:42
Protocol * pointer
Definition Protocol.hpp:43
std::unique_ptr< Protocol > & reference
Definition Protocol.hpp:44
std::bidirectional_iterator_tag iterator_category
Definition Protocol.hpp:40
Iterator(Iterator &&) noexcept
std::unique_ptr< Protocol > value_type
Definition Protocol.hpp:41
std::unique_ptr< Protocol > operator*() const
Iterator operator--(int)
Definition Protocol.hpp:79
Iterator operator++(int)
Definition Protocol.hpp:85
details::ProtocolIt implementation
Definition Protocol.hpp:45
PointerProxy operator->() const
Definition Protocol.hpp:93
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generate a header-like string for this specific protocol.
methods_it optional_methods() const
Iterator over the methods that could be overridden.
methods_it required_methods() const
Iterator over the methods of this protocol that must be implemented.
properties_it properties() const
Iterator over the properties defined in this protocol.
Protocol(std::unique_ptr< details::Protocol > impl)
iterator_range< Method::Iterator > methods_it
Definition Protocol.hpp:102
std::string mangled_name() const
Mangled name of the protocol.
iterator_range< Property::Iterator > properties_it
Definition Protocol.hpp:103
Definition ObjC/Class.hpp:32
Namespace related to ObjC metadata.
Definition MachO/Binary.hpp:41
LIEF namespace.
Definition Abstract/Binary.hpp:40
Definition string.h:155
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