use crate::{sys, SBBreakpoint, SBTarget};
pub struct SBBreakpointList {
pub raw: sys::SBBreakpointListRef,
}
impl SBBreakpointList {
pub fn new(target: &SBTarget) -> SBBreakpointList {
SBBreakpointList::wrap(unsafe { sys::CreateSBBreakpointList(target.raw) })
}
pub(crate) fn wrap(raw: sys::SBBreakpointListRef) -> SBBreakpointList {
SBBreakpointList { raw }
}
#[allow(missing_docs)]
pub fn find_breakpoint_by_id(&self, id: i32) -> Option<SBBreakpoint> {
SBBreakpoint::maybe_wrap(unsafe { sys::SBBreakpointListFindBreakpointByID(self.raw, id) })
}
#[allow(missing_docs)]
pub fn append(&self, bkpt: &SBBreakpoint) {
unsafe { sys::SBBreakpointListAppend(self.raw, bkpt.raw) };
}
#[allow(missing_docs)]
pub fn append_by_id(&self, bkpt_id: i32) {
unsafe { sys::SBBreakpointListAppendByID(self.raw, bkpt_id) };
}
#[allow(missing_docs)]
pub fn append_if_unique(&self, bkpt: &SBBreakpoint) {
unsafe { sys::SBBreakpointListAppendIfUnique(self.raw, bkpt.raw) };
}
pub fn is_empty(&self) -> bool {
unsafe { sys::SBBreakpointListGetSize(self.raw) == 0 }
}
pub fn clear(&self) {
unsafe { sys::SBBreakpointListClear(self.raw) };
}
pub fn iter(&self) -> SBBreakpointListIter {
SBBreakpointListIter {
breakpoint_list: self,
idx: 0,
}
}
}
impl Clone for SBBreakpointList {
fn clone(&self) -> SBBreakpointList {
SBBreakpointList {
raw: unsafe { sys::CloneSBBreakpointList(self.raw) },
}
}
}
impl Drop for SBBreakpointList {
fn drop(&mut self) {
unsafe { sys::DisposeSBBreakpointList(self.raw) };
}
}
impl<'d> IntoIterator for &'d SBBreakpointList {
type IntoIter = SBBreakpointListIter<'d>;
type Item = SBBreakpoint;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
unsafe impl Send for SBBreakpointList {}
unsafe impl Sync for SBBreakpointList {}
pub struct SBBreakpointListIter<'d> {
breakpoint_list: &'d SBBreakpointList,
idx: usize,
}
impl Iterator for SBBreakpointListIter<'_> {
type Item = SBBreakpoint;
fn next(&mut self) -> Option<SBBreakpoint> {
if self.idx < unsafe { sys::SBBreakpointListGetSize(self.breakpoint_list.raw) } {
let r = SBBreakpoint::wrap(unsafe {
sys::SBBreakpointListGetBreakpointAtIndex(self.breakpoint_list.raw, self.idx)
});
self.idx += 1;
Some(r)
} else {
None
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
let sz = unsafe { sys::SBBreakpointListGetSize(self.breakpoint_list.raw) };
(sz - self.idx, Some(sz))
}
}
impl ExactSizeIterator for SBBreakpointListIter<'_> {}