use lief_ffi as ffi;
use super::{DeclOpt, IVar, Method, Property, Protocol};
use crate::common::{FromFFI, into_optional};
use crate::declare_fwd_iterator;
use std::marker::PhantomData;
pub struct Class<'a> {
ptr: cxx::UniquePtr<ffi::ObjC_Class>,
_owner: PhantomData<&'a ()>,
}
impl FromFFI<ffi::ObjC_Class> for Class<'_> {
fn from_ffi(info: cxx::UniquePtr<ffi::ObjC_Class>) -> Self {
Self {
ptr: info,
_owner: PhantomData,
}
}
}
impl Class<'_> {
pub fn name(&self) -> String {
self.ptr.name().to_string()
}
pub fn demangled_name(&self) -> String {
self.ptr.demangled_name().to_string()
}
pub fn super_class(&self) -> Option<Class<'_>> {
into_optional(self.ptr.super_class())
}
pub fn super_name(&self) -> String {
self.ptr.super_name().to_string()
}
pub fn demangled_super_name(&self) -> String {
self.ptr.demangled_super_name().to_string()
}
pub fn is_meta(&self) -> bool {
self.ptr.is_meta()
}
pub fn methods(&self) -> Methods<'_> {
Methods::new(self.ptr.methods())
}
pub fn protocols(&self) -> Protocols<'_> {
Protocols::new(self.ptr.protocols())
}
pub fn properties(&self) -> Properties<'_> {
Properties::new(self.ptr.properties())
}
pub fn ivars(&self) -> IVars<'_> {
IVars::new(self.ptr.ivars())
}
pub fn to_decl(&self) -> String {
self.ptr.to_decl().to_string()
}
pub fn to_decl_with_opt(&self, opt: &DeclOpt) -> String {
self.ptr.to_decl_with_opt(&opt.to_ffi()).to_string()
}
}
declare_fwd_iterator!(
Methods,
Method<'a>,
ffi::ObjC_Method,
ffi::ObjC_Class,
ffi::ObjC_Class_it_methods
);
declare_fwd_iterator!(
Protocols,
Protocol<'a>,
ffi::ObjC_Protocol,
ffi::ObjC_Class,
ffi::ObjC_Class_it_protocols
);
declare_fwd_iterator!(
Properties,
Property<'a>,
ffi::ObjC_Property,
ffi::ObjC_Class,
ffi::ObjC_Class_it_properties
);
declare_fwd_iterator!(
IVars,
IVar<'a>,
ffi::ObjC_IVar,
ffi::ObjC_Class,
ffi::ObjC_Class_it_ivars
);