use crate::{sys, SBAddress, SBFileSpec, SBStream};
use std::fmt;
pub struct SBLineEntry {
pub raw: sys::SBLineEntryRef,
}
impl SBLineEntry {
pub(crate) fn wrap(raw: sys::SBLineEntryRef) -> SBLineEntry {
SBLineEntry { raw }
}
pub(crate) fn maybe_wrap(raw: sys::SBLineEntryRef) -> Option<SBLineEntry> {
if unsafe { sys::SBLineEntryIsValid(raw) } {
Some(SBLineEntry { raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBLineEntryIsValid(self.raw) }
}
pub fn start_address(&self) -> SBAddress {
SBAddress::wrap(unsafe { sys::SBLineEntryGetStartAddress(self.raw) })
}
pub fn end_address(&self) -> SBAddress {
SBAddress::wrap(unsafe { sys::SBLineEntryGetEndAddress(self.raw) })
}
pub fn filespec(&self) -> SBFileSpec {
SBFileSpec::wrap(unsafe { sys::SBLineEntryGetFileSpec(self.raw) })
}
pub fn line(&self) -> u32 {
unsafe { sys::SBLineEntryGetLine(self.raw) }
}
pub fn column(&self) -> u32 {
unsafe { sys::SBLineEntryGetColumn(self.raw) }
}
}
impl Clone for SBLineEntry {
fn clone(&self) -> SBLineEntry {
SBLineEntry {
raw: unsafe { sys::CloneSBLineEntry(self.raw) },
}
}
}
impl fmt::Debug for SBLineEntry {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let stream = SBStream::new();
unsafe { sys::SBLineEntryGetDescription(self.raw, stream.raw) };
write!(fmt, "SBLineEntry {{ {} }}", stream.data())
}
}
impl Drop for SBLineEntry {
fn drop(&mut self) {
unsafe { sys::DisposeSBLineEntry(self.raw) };
}
}
unsafe impl Send for SBLineEntry {}
unsafe impl Sync for SBLineEntry {}
#[cfg(feature = "graphql")]
#[graphql_object]
impl SBLineEntry {
fn start_address() -> SBAddress {
self.start_address()
}
fn end_address() -> SBAddress {
self.end_address()
}
fn filespec() -> SBFileSpec {
self.filespec()
}
fn line() -> i32 {
self.line() as i32
}
fn column() -> i32 {
self.column() as i32
}
}