add GList/GSList wrappers

gui-branch
an 2019-04-03 14:17:49 -04:00
parent 116d91ef6a
commit 3b8790b442
1 changed files with 73 additions and 0 deletions

View File

@ -3,6 +3,7 @@
use cairo_sys::*;
use gdk_pixbuf_sys::*;
use gdk_sys::*;
use glib_sys::*;
use gobject_sys::*;
use gtk_sys::*;
use maraiah::{c_str,
@ -175,6 +176,64 @@ impl<T> Refc<'_, T>
pub fn own(p: *mut T) -> Self {unsafe {g_object_ref(p as _);} Self::new(p)}
}
impl ListD
{
pub fn new(head: *mut GList) -> Self {Self{head, iter: head}}
}
impl Iterator for ListD
{
type Item = gpointer;
fn next(&mut self) -> Option<gpointer> {
if self.iter != ffi::null_mut() {
let obj = unsafe {
let obj = (*self.iter).data;
self.iter = (*self.iter).next;
obj
};
Some(obj)
} else {
None
}
}
}
impl Drop for ListD
{
fn drop(&mut self) {unsafe {g_list_free(self.head);}}
}
impl ListS
{
pub fn new(head: *mut GSList) -> Self {Self{head, iter: head}}
}
impl Iterator for ListS
{
type Item = gpointer;
fn next(&mut self) -> Option<gpointer> {
if self.iter != ffi::null_mut() {
let obj = unsafe {
let obj = (*self.iter).data;
self.iter = (*self.iter).next;
obj
};
Some(obj)
} else {
None
}
}
}
impl Drop for ListS
{
fn drop(&mut self) {unsafe {g_slist_free(self.head);}}
}
/// An image for a `CrDrawArea`.
pub struct CrImage(pub *const GdkPixbuf);
@ -203,4 +262,18 @@ pub struct Refc<'a, T>
l: PhantomData<&'a *mut T>,
}
/// A GList wrapper.
pub struct ListD
{
head: *mut GList,
iter: *mut GList,
}
/// A GSList wrapper.
pub struct ListS
{
head: *mut GSList,
iter: *mut GSList,
}
// EOF