LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
Protocol.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_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}
34class LIEF_API Protocol {
37 public:
38 class LIEF_API Iterator {
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
60 Iterator(const Iterator&);
61 Iterator(Iterator&&) noexcept;
62 Iterator(std::unique_ptr<details::ProtocolIt> impl);
63 ~Iterator();
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
71 Iterator& operator++();
72 Iterator& operator--();
73
74 Iterator operator--(int) {
75 Iterator tmp = *static_cast<Iterator*>(this);
76 --*static_cast<Iterator *>(this);
77 return tmp;
78 }
79
80 Iterator operator++(int) {
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
88 PointerProxy operator->() const {
89 return static_cast<const Iterator*>(this)->operator*();
90 }
91
92 private:
93 std::unique_ptr<details::ProtocolIt> impl_;
94 };
95
96 public:
97 using methods_it = iterator_range<Method::Iterator>;
98 using properties_it = iterator_range<Property::Iterator>;
99
100 Protocol(std::unique_ptr<details::Protocol> impl);
101 std::string mangled_name() const;
104 methods_it optional_methods() const;
107 methods_it required_methods() const;
110 properties_it properties() const;
113 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
pointer operator->() const
Definition Protocol.hpp:51
Iterator(Iterator &&) noexcept
std::unique_ptr< Protocol > operator*() const
Iterator operator--(int)
Definition Protocol.hpp:74
Iterator operator++(int)
Definition Protocol.hpp:80
PointerProxy operator->() const
Definition Protocol.hpp:88
This class represents an Objective-C @protocol
Definition Protocol.hpp:36
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)
std::string mangled_name() const
Mangled name of the protocol.
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