Add bindings for most CFSet methods, and static new() for the wrapper.
This commit is contained in:
@@ -6,8 +6,10 @@ use base::{
|
||||
CFIndex,
|
||||
CFRelease,
|
||||
CFTypeRef,
|
||||
CFTypeID,
|
||||
kCFAllocatorDefault,
|
||||
};
|
||||
use libc::c_char;
|
||||
use libc::{c_char, c_void};
|
||||
|
||||
pub type CFSetRetainCallBack = *u8;
|
||||
pub type CFSetReleaseCallBack = *u8;
|
||||
@@ -31,7 +33,8 @@ impl CFSetRef : AbstractCFTypeRef {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
|
||||
}
|
||||
|
||||
pub struct CFSet {
|
||||
struct CFSet<ElemRefType : AbstractCFTypeRef,
|
||||
ElemType : AbstractCFType<ElemRefType>> {
|
||||
obj: CFSetRef,
|
||||
|
||||
drop {
|
||||
@@ -41,18 +44,39 @@ pub struct CFSet {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl CFSet : AbstractCFType<CFSetRef> {
|
||||
pub impl<ElemRefType : AbstractCFTypeRef,
|
||||
ElemType : AbstractCFType<ElemRefType>>
|
||||
CFSet<ElemRefType, ElemType> {
|
||||
static fn new(elems: &[ElemType]) -> CFSet<ElemRefType, ElemType> {
|
||||
let set_ref : CFSetRef;
|
||||
let elems_refs = do vec::map(elems) |e: &ElemType| { e.get_ref().as_type_ref() };
|
||||
|
||||
unsafe {
|
||||
set_ref = CFSetCreate(kCFAllocatorDefault,
|
||||
cast::transmute(vec::raw::to_ptr(elems_refs)),
|
||||
elems.len() as CFIndex,
|
||||
ptr::to_unsafe_ptr(&kCFTypeSetCallBacks));
|
||||
}
|
||||
// return CFSet::wrap(set_ref)
|
||||
return CFSet { obj: set_ref };
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<ElemRefType : AbstractCFTypeRef,
|
||||
ElemType : AbstractCFType<ElemRefType>>
|
||||
CFSet<ElemRefType, ElemType> : AbstractCFType<CFSetRef> {
|
||||
pure fn get_ref() -> CFSetRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFSetRef) -> CFSet {
|
||||
static fn wrap(obj: CFSetRef) -> CFSet<ElemRefType, ElemType> {
|
||||
CFSet { obj: obj }
|
||||
}
|
||||
|
||||
static fn unwrap(wrapper: CFSet) -> CFSetRef {
|
||||
static fn unwrap(wrapper: CFSet<ElemRefType, ElemType>) -> CFSetRef {
|
||||
wrapper.obj
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[link_args="-framework CoreFoundation"]
|
||||
#[nolink]
|
||||
extern {
|
||||
@@ -63,15 +87,22 @@ extern {
|
||||
const kCFTypeSetCallBacks: CFSetCallBacks;
|
||||
const kCFTypeCopyStringSetCallBacks: CFSetCallBacks;
|
||||
|
||||
//fn CFSetCreate
|
||||
//fn CFSetCreateCopy
|
||||
//fn CFSetContainsValue
|
||||
//fn CFSetGetCount
|
||||
//fn CFSetGetCountOfValue
|
||||
//fn CFSetGetValue
|
||||
//fn CFSetGetValueIfPresent
|
||||
//fn CFSetGetValues
|
||||
/* Creating Sets */
|
||||
fn CFSetCreate(allocator: CFAllocatorRef, values: **c_void, numValues: CFIndex,
|
||||
callBacks: *CFSetCallBacks) -> CFSetRef;
|
||||
fn CFSetCreateCopy(allocator: CFAllocatorRef, theSet: CFSetRef) -> CFSetRef;
|
||||
|
||||
/* Examining a Set */
|
||||
fn CFSetContainsValue(theSet: CFSetRef, value: *c_void) -> Boolean;
|
||||
fn CFSetGetCount(theSet: CFSetRef) -> CFIndex;
|
||||
fn CFSetGetCountOfValue(theSet: CFSetRef, value: *c_void) -> CFIndex;
|
||||
fn CFSetGetValue(theSet: CFSetRef, value: *c_void) -> *c_void;
|
||||
fn CFSetGetValueIfPresent(theSet: CFSetRef, candidate: *c_void, value: **c_void) -> Boolean;
|
||||
fn CFSetGetValues(theSet: CFSetRef, values: **c_void);
|
||||
|
||||
/* Applying a Function to Set Members */
|
||||
//fn CFSetApplyFunction
|
||||
//fn CFSetGetTypeID
|
||||
|
||||
fn CFSetGetTypeID() -> CFTypeID;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user