From 1f0bc6db0d23a9f1edd1918b3cb68e0ffba2cb9d Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Wed, 14 Nov 2012 13:37:55 -0800 Subject: [PATCH] Add bindings for most CFSet methods, and static new() for the wrapper. --- set.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/set.rs b/set.rs index a00d061..8a3d68b 100644 --- a/set.rs +++ b/set.rs @@ -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> { obj: CFSetRef, drop { @@ -41,18 +44,39 @@ pub struct CFSet { } } -pub impl CFSet : AbstractCFType { +pub impl> + CFSet { + static fn new(elems: &[ElemType]) -> CFSet { + 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> + CFSet : AbstractCFType { pure fn get_ref() -> CFSetRef { self.obj } - static fn wrap(obj: CFSetRef) -> CFSet { + static fn wrap(obj: CFSetRef) -> CFSet { CFSet { obj: obj } } - static fn unwrap(wrapper: CFSet) -> CFSetRef { + static fn unwrap(wrapper: CFSet) -> 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; }