Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use std::marker::PhantomData;
4 : use crate::common::FromFFI;
5 : use crate::declare_fwd_iterator;
6 :
7 : use super::{Property, Method, DeclOpt};
8 :
9 : /// This class represents an Objective-C `@protocol`
10 : pub struct Protocol<'a> {
11 : ptr: cxx::UniquePtr<ffi::ObjC_Protocol>,
12 : _owner: PhantomData<&'a ()>,
13 : }
14 :
15 : impl FromFFI<ffi::ObjC_Protocol> for Protocol<'_> {
16 0 : fn from_ffi(info: cxx::UniquePtr<ffi::ObjC_Protocol>) -> Self {
17 0 : Self {
18 0 : ptr: info,
19 0 : _owner: PhantomData
20 0 : }
21 0 : }
22 : }
23 :
24 : impl Protocol<'_> {
25 : /// Mangled name of the protocol
26 0 : pub fn mangled_name(&self) -> String {
27 0 : self.ptr.mangled_name().to_string()
28 0 : }
29 :
30 : /// Iterator over the methods that could be overridden
31 0 : pub fn optional_methods(&self) -> OptionalMethods {
32 0 : OptionalMethods::new(self.ptr.optional_methods())
33 0 : }
34 :
35 : /// Iterator over the methods of this protocol that must be implemented
36 0 : pub fn required_methods(&self) -> RequiredMethods {
37 0 : RequiredMethods::new(self.ptr.required_methods())
38 0 : }
39 :
40 : /// Iterator over the properties defined in this protocol
41 0 : pub fn properties(&self) -> Properties {
42 0 : Properties::new(self.ptr.properties())
43 0 : }
44 :
45 : /// Generate a header-like string for this specific class
46 0 : pub fn to_decl(&self) -> String {
47 0 : self.ptr.to_decl().to_string()
48 0 : }
49 :
50 : /// Same behavior as [`Protocol::to_decl`] but with an additional
51 : /// [`DeclOpt`] parameter to customize the output
52 0 : pub fn to_decl_with_opt(&self, opt: &DeclOpt) -> String {
53 0 : self.ptr.to_decl_with_opt(opt.to_ffi()).to_string()
54 0 : }
55 : }
56 :
57 0 : declare_fwd_iterator!(
58 0 : OptionalMethods,
59 0 : Method<'a>,
60 0 : ffi::ObjC_Method,
61 0 : ffi::ObjC_Protocol,
62 0 : ffi::ObjC_Protocol_it_opt_methods
63 0 : );
64 :
65 0 : declare_fwd_iterator!(
66 0 : RequiredMethods,
67 0 : Method<'a>,
68 0 : ffi::ObjC_Method,
69 0 : ffi::ObjC_Protocol,
70 0 : ffi::ObjC_Protocol_it_req_methods
71 0 : );
72 :
73 0 : declare_fwd_iterator!(
74 0 : Properties,
75 0 : Property<'a>,
76 0 : ffi::ObjC_Property,
77 0 : ffi::ObjC_Protocol,
78 0 : ffi::ObjC_Protocol_it_properties
79 0 : );
|