Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use crate::common::{FromFFI, into_optional};
4 : use std::marker::PhantomData;
5 : use crate::pdb::types::{PdbType, Type};
6 :
7 : use crate::declare_fwd_iterator;
8 :
9 : /// This structure wraps a `LF_ENUM` PDB type
10 : pub struct Enum<'a> {
11 : ptr: cxx::UniquePtr<ffi::PDB_types_Enum>,
12 : _owner: PhantomData<&'a ()>,
13 : }
14 :
15 : impl FromFFI<ffi::PDB_types_Enum> for Enum<'_> {
16 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::PDB_types_Enum>) -> Self {
17 0 : Self {
18 0 : ptr: cmd,
19 0 : _owner: PhantomData,
20 0 : }
21 0 : }
22 : }
23 :
24 : impl Enum<'_> {
25 : /// Entries associated with this enum
26 0 : pub fn entries(&self) -> Entries<'_> {
27 0 : Entries::new(self.ptr.entries())
28 0 : }
29 :
30 : /// The underlying type that is used to encode this enum
31 0 : pub fn underlying_type(&self) -> Option<Type<'_>> {
32 0 : into_optional(self.ptr.underlying_type())
33 0 : }
34 :
35 : /// Try to find the enum entry matching the given value
36 0 : pub fn entry_by_value(&self, value: i64) -> Option<Entry<'_>> {
37 0 : into_optional(self.ptr.find_entry(value))
38 0 : }
39 : }
40 :
41 : impl PdbType for Enum<'_> {
42 0 : fn get_base(&self) -> &ffi::PDB_Type {
43 0 : self.ptr.as_ref().unwrap().as_ref()
44 0 : }
45 : }
46 :
47 : /// This struct represents an enum entry which is essentially composed of a name and its value
48 : /// (integer).
49 : pub struct Entry<'a> {
50 : ptr: cxx::UniquePtr<ffi::PDB_types_Enum_Entry>,
51 : _owner: PhantomData<&'a ()>,
52 : }
53 :
54 : impl Entry<'_> {
55 : /// Enum entry's name
56 0 : pub fn name(&self) -> String {
57 0 : self.ptr.name().to_string()
58 0 : }
59 :
60 : /// Enum entry's value
61 0 : pub fn value(&self) -> i64 {
62 0 : self.ptr.value()
63 0 : }
64 : }
65 :
66 :
67 : impl FromFFI<ffi::PDB_types_Enum_Entry> for Entry<'_> {
68 0 : fn from_ffi(cmd: cxx::UniquePtr<ffi::PDB_types_Enum_Entry>) -> Self {
69 0 : Self {
70 0 : ptr: cmd,
71 0 : _owner: PhantomData,
72 0 : }
73 0 : }
74 : }
75 :
76 0 : declare_fwd_iterator!(
77 0 : Entries,
78 0 : Entry<'a>,
79 0 : ffi::PDB_types_Enum_Entry,
80 0 : ffi::PDB_types_Enum,
81 0 : ffi::PDB_types_Enum_it_entries
82 0 : );
|