@@ -19,7 +19,6 @@ use base::{
|
||||
use std::cast;
|
||||
use std::libc::c_void;
|
||||
use std::ptr;
|
||||
use std::uint;
|
||||
use std::vec;
|
||||
|
||||
pub type CFArrayRetainCallBack = *u8;
|
||||
@@ -78,7 +77,7 @@ impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
|
||||
}
|
||||
|
||||
pub fn each_ref(&self, cb: &fn(ElemRefType) -> bool) -> bool {
|
||||
for uint::range(0, self.len()) |i| {
|
||||
for i in range(0, self.len()) {
|
||||
cb(self[i]);
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
|
||||
}
|
||||
|
||||
pub fn eachi_ref(&self, cb: &fn(uint, ElemRefType) -> bool) -> bool {
|
||||
for uint::range(0, self.len()) |i| {
|
||||
for i in range(0, self.len()) {
|
||||
cb(i, self[i]);
|
||||
}
|
||||
|
||||
@@ -97,7 +96,7 @@ impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
|
||||
// Generally, when array elements are Core Foundation objects (not
|
||||
// always true), they need to be wrapped with CFWrapper::wrap_shared.
|
||||
pub fn each(&self, cb: &fn(&ElemRefType) -> bool) -> bool {
|
||||
for uint::range(0, self.len()) |i| {
|
||||
for i in range(0, self.len()) {
|
||||
cb(&self[i]);
|
||||
}
|
||||
|
||||
@@ -108,7 +107,7 @@ impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
|
||||
// Generally, when array elements are Core Foundation objects (not
|
||||
// always true), they need to be wrapped with CFWrapper::wrap_shared.
|
||||
pub fn eachi(&self, cb: &fn(uint, &ElemRefType) -> bool) -> bool{
|
||||
for uint::range(0, self.len()) |i| {
|
||||
for i in range(0, self.len()) {
|
||||
cb(i, &self[i]);
|
||||
}
|
||||
|
||||
@@ -180,13 +179,13 @@ fn should_box_and_unbox() {
|
||||
|
||||
let mut sum = 0i32;
|
||||
|
||||
for arr.each |elem: &CFNumberRef| {
|
||||
for elem in arr.iter() {
|
||||
sum += CFNumber::wrap_shared(*elem).to_i32();
|
||||
}
|
||||
|
||||
assert!(sum == 15);
|
||||
|
||||
for arr.each |elem: &CFNumberRef| {
|
||||
for elem in arr.iter() {
|
||||
sum += CFNumber::wrap_shared(*elem).to_i32();
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ impl<T,E1,E2> Drop for CFWrapper<T,E1,E2> {
|
||||
|
||||
pub type CFType = CFWrapper<CFTypeRef, (), ()>;
|
||||
|
||||
impl<'self, T:Copy + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
impl<'self, T:Clone + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
pub fn borrow_ref(&'self self) -> &'self T {
|
||||
&self.obj
|
||||
}
|
||||
@@ -111,7 +111,7 @@ impl<'self, T:Copy + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
|
||||
// Unwraps the wrapper, returning the underlying AbstractCFType.
|
||||
pub fn unwrap(wrapper: CFWrapper<T,E1,E2>) -> T {
|
||||
copy wrapper.obj
|
||||
wrapper.obj.clone()
|
||||
}
|
||||
|
||||
pub fn to_CFType(wrapper: CFWrapper<T,E1,E2>) -> CFType {
|
||||
@@ -128,7 +128,7 @@ impl<'self, T:Copy + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
}
|
||||
|
||||
pub fn clone(wrapper: &CFWrapper<T,E1,E2>) -> CFWrapper<T,E1,E2> {
|
||||
CFWrapper::wrap_shared(copy *wrapper.borrow_ref())
|
||||
CFWrapper::wrap_shared((*wrapper.borrow_ref()).clone())
|
||||
}
|
||||
|
||||
pub fn retain_count(&self) -> CFIndex {
|
||||
|
||||
+7
-5
@@ -22,7 +22,6 @@ use string::CFStringRef;
|
||||
use std::cast;
|
||||
use std::libc::c_void;
|
||||
use std::ptr;
|
||||
use std::uint;
|
||||
use std::vec;
|
||||
|
||||
pub type CFDictionaryApplierFunction = *u8;
|
||||
@@ -70,7 +69,7 @@ pub struct CFDictionary<KeyRefType, ValueRefType> {
|
||||
|
||||
pub type UntypedCFDictionary = CFDictionary<CFStringRef, CFTypeRef>;
|
||||
|
||||
impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTypeRef>
|
||||
impl<KeyRefType: Clone + AbstractCFTypeRef, ValueRefType: Clone + AbstractCFTypeRef>
|
||||
CFDictionary<KeyRefType, ValueRefType> {
|
||||
pub fn wrap_owned(dictionary: CFDictionaryRef) -> CFDictionary<KeyRefType, ValueRefType> {
|
||||
CFDictionary {
|
||||
@@ -81,7 +80,7 @@ impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTypeRe
|
||||
pub fn new(pairs: &[(KeyRefType,ValueRefType)]) -> CFDictionary<KeyRefType, ValueRefType> {
|
||||
let mut keys : ~[CFTypeRef] = ~[];
|
||||
let mut values : ~[CFTypeRef] = ~[];
|
||||
for pairs.iter().advance |pair| {
|
||||
for pair in pairs.iter() {
|
||||
// FIXME: "let" would be much nicer here, but that doesn't work yet.
|
||||
match *pair {
|
||||
(ref key, ref value) => {
|
||||
@@ -154,6 +153,7 @@ impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTypeRe
|
||||
return value.unwrap();
|
||||
}
|
||||
|
||||
// FIXME: this should be an iterator
|
||||
pub fn each(&self, blk: &fn(&KeyRefType, &ValueRefType) -> bool) -> bool {
|
||||
unsafe {
|
||||
let len = self.len();
|
||||
@@ -162,9 +162,11 @@ impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTypeRe
|
||||
let null_vals = cast::transmute::<*c_void,ValueRefType>(ptr::null());
|
||||
let values: ~[ValueRefType] = vec::from_elem(len, null_vals);
|
||||
|
||||
do uint::range(0,len) |i| {
|
||||
blk(&keys[i], &values[i])
|
||||
for i in range(0, len) {
|
||||
if !blk(&keys[i], &values[i]) { return false; }
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ impl CFNumber {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new<T:Copy + ConvertibleToCFNumber>(n: T) -> CFNumber {
|
||||
pub fn new<T:Clone + ConvertibleToCFNumber>(n: T) -> CFNumber {
|
||||
unsafe {
|
||||
let objref = CFNumberCreate(kCFAllocatorDefault,
|
||||
n.cf_number_type(),
|
||||
@@ -141,13 +141,13 @@ impl CFNumber {
|
||||
}
|
||||
}
|
||||
|
||||
priv fn has_float_type(&self) -> bool {
|
||||
fn has_float_type(&self) -> bool {
|
||||
unsafe {
|
||||
CFNumberIsFloatType(self.contents.obj) as bool
|
||||
}
|
||||
}
|
||||
|
||||
priv fn has_number_type(&self, ty: CFNumberType) -> bool {
|
||||
fn has_number_type(&self, ty: CFNumberType) -> bool {
|
||||
unsafe {
|
||||
CFNumberGetType(self.contents.obj) == ty
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ use base::{CFRangeMake, CFTypeRef, CFTypeID, CFWrapper, kCFAllocatorDefault, kCF
|
||||
use std::cast;
|
||||
use std::libc;
|
||||
use std::ptr;
|
||||
use std::str;
|
||||
use std::vec;
|
||||
|
||||
pub type UniChar = libc::c_ushort;
|
||||
@@ -235,7 +234,7 @@ impl CFString {
|
||||
// like CFString::new, but references a string that can be used as
|
||||
// a backing store by virtue of being statically allocated.
|
||||
pub fn new_static(string: &'static str) -> CFString {
|
||||
let string_ref = do str::as_buf(string) |bytes, len| {
|
||||
let string_ref = do string.as_imm_buf |bytes, len| {
|
||||
unsafe {
|
||||
CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
|
||||
bytes,
|
||||
@@ -252,7 +251,7 @@ impl CFString {
|
||||
}
|
||||
|
||||
pub fn new(string: &str) -> CFString {
|
||||
let string_ref = do str::as_buf(string) |bytes, len| {
|
||||
let string_ref = do string.as_imm_buf |bytes, len| {
|
||||
unsafe {
|
||||
CFStringCreateWithBytes(kCFAllocatorDefault,
|
||||
bytes,
|
||||
|
||||
Reference in New Issue
Block a user