LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
Protocol.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_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 public:
51 pointer operator->() const { return R.get(); }
52
53 private:
54 value_type R;
55
56 template <typename RefT>
57 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
58 };
59
61 Iterator(Iterator&&) noexcept;
62 Iterator(std::unique_ptr<details::ProtocolIt> impl);
64
65 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
66
67 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
68 return !(LHS == RHS);
69 }
70
73
75 Iterator tmp = *static_cast<Iterator*>(this);
76 --*static_cast<Iterator *>(this);
77 return tmp;
78 }
79
81 Iterator tmp = *static_cast<Iterator*>(this);
82 ++*static_cast<Iterator *>(this);
83 return tmp;
84 }
85
86 std::unique_ptr<Protocol> operator*() const;
87
89 return static_cast<const Iterator*>(this)->operator*();
90 }
91
92 private:
93 std::unique_ptr<details::ProtocolIt> impl_;
94 };
95
96 public:
99
100 Protocol(std::unique_ptr<details::Protocol> impl);
101
103 std::string mangled_name() const;
104
107
110
113
117 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
118
120 private:
121 std::unique_ptr<details::Protocol> impl_;
122};
123
124}
125}
126#endif
Definition iterators.hpp:486
pointer operator->() const
Definition Protocol.hpp:51
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:74
Iterator operator++(int)
Definition Protocol.hpp:80
details::ProtocolIt implementation
Definition Protocol.hpp:45
PointerProxy operator->() const
Definition Protocol.hpp:88
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:97
std::string mangled_name() const
Mangled name of the protocol.
iterator_range< Property::Iterator > properties_it
Definition Protocol.hpp:98
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