Update for language changes
This commit is contained in:
@@ -16,7 +16,11 @@ use base::{
|
||||
CFWrapper,
|
||||
kCFAllocatorDefault,
|
||||
};
|
||||
use core::libc::c_void;
|
||||
use std::cast;
|
||||
use std::libc::c_void;
|
||||
use std::ptr;
|
||||
use std::uint;
|
||||
use std::vec;
|
||||
|
||||
pub type CFArrayRetainCallBack = *u8;
|
||||
pub type CFArrayReleaseCallBack = *u8;
|
||||
@@ -44,22 +48,22 @@ pub struct CFArray<ElemRefType> {
|
||||
contents: CFWrapper<CFArrayRef, ElemRefType, ()>
|
||||
}
|
||||
|
||||
pub impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
|
||||
fn wrap_shared(array: CFArrayRef) -> CFArray<ElemRefType> {
|
||||
impl<ElemRefType:AbstractCFTypeRef> CFArray<ElemRefType> {
|
||||
pub fn wrap_shared(array: CFArrayRef) -> CFArray<ElemRefType> {
|
||||
CFArray {
|
||||
contents: CFWrapper::wrap_shared(array)
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap_owned(array: CFArrayRef) -> CFArray<ElemRefType> {
|
||||
pub fn wrap_owned(array: CFArrayRef) -> CFArray<ElemRefType> {
|
||||
CFArray {
|
||||
contents: CFWrapper::wrap_owned(array)
|
||||
}
|
||||
}
|
||||
|
||||
fn new(elems: &[ElemRefType]) -> CFArray<ElemRefType> {
|
||||
pub fn new(elems: &[ElemRefType]) -> CFArray<ElemRefType> {
|
||||
let array_ref: CFArrayRef;
|
||||
let elems_refs = do vec::map(elems) |e: &ElemRefType| { e.as_type_ref() };
|
||||
let elems_refs = do elems.map |e: &ElemRefType| { e.as_type_ref() };
|
||||
|
||||
unsafe {
|
||||
array_ref = CFArrayCreate(kCFAllocatorDefault,
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use core::libc::c_long;
|
||||
use std::cast;
|
||||
use std::libc;
|
||||
use std::libc::c_long;
|
||||
|
||||
// a raw Core Foundation reference. It may or may not have been
|
||||
// CFRetain'ed, depending on whether it was obtained via ownership or
|
||||
@@ -80,12 +82,12 @@ impl<T,E1,E2> Drop for CFWrapper<T,E1,E2> {
|
||||
|
||||
pub type CFType = CFWrapper<CFTypeRef, (), ()>;
|
||||
|
||||
pub impl<'self, T:Copy + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
fn borrow_ref(&'self self) -> &'self T {
|
||||
impl<'self, T:Copy + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
pub fn borrow_ref(&'self self) -> &'self T {
|
||||
&self.obj
|
||||
}
|
||||
|
||||
fn borrow_type_ref(&self) -> &'self CFTypeRef {
|
||||
pub fn borrow_type_ref(&self) -> &'self CFTypeRef {
|
||||
unsafe {
|
||||
cast::transmute::<&T, &CFTypeRef>(&self.obj)
|
||||
}
|
||||
@@ -93,7 +95,7 @@ pub impl<'self, T:Copy + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
|
||||
// Use this when following Core Foundation's "Create" rule; i.e., the wrapper assumes ownership.
|
||||
// The object has already been retained, so we need not increment the retain count ourself.
|
||||
fn wrap_owned(some_ref: T) -> CFWrapper<T,E1,E2> {
|
||||
pub fn wrap_owned(some_ref: T) -> CFWrapper<T,E1,E2> {
|
||||
// N.B. we can't make any assertions about retain count here,
|
||||
// because returned things are only guaranteed to be already
|
||||
// retained. Strings, for example, could be interned.
|
||||
@@ -102,46 +104,46 @@ pub impl<'self, T:Copy + AbstractCFTypeRef, E1, E2> CFWrapper<T,E1,E2> {
|
||||
|
||||
// Use this when following Core Foundation's "Get" rule. The wrapper does not have ownership.
|
||||
// Twe need to increment object's the retain count so it isn't freed out from under our noses.
|
||||
fn wrap_shared(some_ref: T) -> CFWrapper<T,E1,E2> {
|
||||
pub fn wrap_shared(some_ref: T) -> CFWrapper<T,E1,E2> {
|
||||
unsafe { CFRetain(some_ref.as_type_ref()); }
|
||||
CFWrapper { obj: some_ref }
|
||||
}
|
||||
|
||||
// Unwraps the wrapper, returning the underlying AbstractCFType.
|
||||
fn unwrap(wrapper: CFWrapper<T,E1,E2>) -> T {
|
||||
wrapper.obj
|
||||
pub fn unwrap(wrapper: CFWrapper<T,E1,E2>) -> T {
|
||||
copy wrapper.obj
|
||||
}
|
||||
|
||||
fn to_CFType(wrapper: CFWrapper<T,E1,E2>) -> CFType {
|
||||
pub fn to_CFType(wrapper: CFWrapper<T,E1,E2>) -> CFType {
|
||||
unsafe {
|
||||
cast::transmute::<CFWrapper<T, E1, E2>, CFType>(wrapper)
|
||||
}
|
||||
}
|
||||
|
||||
fn from_CFType(wrapper: CFType) -> CFWrapper<T,E1,E2> {
|
||||
pub fn from_CFType(wrapper: CFType) -> CFWrapper<T,E1,E2> {
|
||||
unsafe {
|
||||
assert!(wrapper.type_id() == AbstractCFTypeRef::type_id::<T>());
|
||||
cast::transmute::<CFType,CFWrapper<T,E1,E2>>(wrapper)
|
||||
}
|
||||
}
|
||||
|
||||
fn clone(wrapper: &CFWrapper<T,E1,E2>) -> CFWrapper<T,E1,E2> {
|
||||
CFWrapper::wrap_shared(*wrapper.borrow_ref())
|
||||
pub fn clone(wrapper: &CFWrapper<T,E1,E2>) -> CFWrapper<T,E1,E2> {
|
||||
CFWrapper::wrap_shared(copy *wrapper.borrow_ref())
|
||||
}
|
||||
|
||||
fn retain_count(&self) -> CFIndex {
|
||||
pub fn retain_count(&self) -> CFIndex {
|
||||
unsafe {
|
||||
CFGetRetainCount(*self.borrow_type_ref())
|
||||
}
|
||||
}
|
||||
|
||||
fn type_id(&self) -> CFTypeID {
|
||||
pub fn type_id(&self) -> CFTypeID {
|
||||
unsafe {
|
||||
CFGetTypeID(*self.borrow_type_ref())
|
||||
}
|
||||
}
|
||||
|
||||
fn show(&self) {
|
||||
pub fn show(&self) {
|
||||
unsafe {
|
||||
CFShow(*self.borrow_type_ref());
|
||||
}
|
||||
|
||||
+3
-3
@@ -33,14 +33,14 @@ pub struct CFBoolean {
|
||||
contents: CFWrapper<CFBooleanRef, (), ()>
|
||||
}
|
||||
|
||||
pub impl CFBoolean {
|
||||
fn true_value() -> CFBoolean {
|
||||
impl CFBoolean {
|
||||
pub fn true_value() -> CFBoolean {
|
||||
CFBoolean {
|
||||
contents: CFWrapper::wrap_shared(kCFBooleanTrue)
|
||||
}
|
||||
}
|
||||
|
||||
fn false_value() -> CFBoolean {
|
||||
pub fn false_value() -> CFBoolean {
|
||||
CFBoolean {
|
||||
contents: CFWrapper::wrap_shared(kCFBooleanFalse)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ use base::{
|
||||
kCFAllocatorDefault,
|
||||
};
|
||||
|
||||
use core::vec;
|
||||
use std::vec;
|
||||
|
||||
struct __CFData { private: () }
|
||||
pub type CFDataRef = *__CFData;
|
||||
@@ -39,14 +39,14 @@ pub struct CFData {
|
||||
contents: CFWrapper<CFDataRef, (), ()>
|
||||
}
|
||||
|
||||
pub impl CFData {
|
||||
fn wrap_owned(data: CFDataRef) -> CFData {
|
||||
impl CFData {
|
||||
pub fn wrap_owned(data: CFDataRef) -> CFData {
|
||||
CFData {
|
||||
contents: CFWrapper::wrap_owned(data)
|
||||
}
|
||||
}
|
||||
|
||||
fn new_from_buf(buf: &[u8]) -> CFData {
|
||||
pub fn new_from_buf(buf: &[u8]) -> CFData {
|
||||
let result;
|
||||
unsafe {
|
||||
result = CFDataCreate(kCFAllocatorDefault,
|
||||
@@ -60,25 +60,25 @@ pub impl CFData {
|
||||
}
|
||||
|
||||
// tread with caution; read-only
|
||||
fn bytes(&self) -> *u8 {
|
||||
pub fn bytes(&self) -> *u8 {
|
||||
unsafe {
|
||||
CFDataGetBytePtr(self.contents.obj)
|
||||
}
|
||||
}
|
||||
|
||||
fn len(&self) -> uint {
|
||||
pub fn len(&self) -> uint {
|
||||
unsafe {
|
||||
CFDataGetLength(self.contents.obj) as uint
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_to_buf(&self) -> ~[u8] {
|
||||
pub fn copy_to_buf(&self) -> ~[u8] {
|
||||
unsafe {
|
||||
vec::from_buf(self.bytes(), self.len())
|
||||
}
|
||||
}
|
||||
|
||||
fn with_buf<U>(&self, blk: &fn(v: &[u8]) -> U) -> U {
|
||||
pub fn with_buf<U>(&self, blk: &fn(v: &[u8]) -> U) -> U {
|
||||
unsafe {
|
||||
vec::raw::buf_as_slice(self.bytes(), self.len(), blk)
|
||||
}
|
||||
|
||||
+15
-11
@@ -19,7 +19,11 @@ use base::{
|
||||
};
|
||||
use string::CFStringRef;
|
||||
|
||||
use core::libc::c_void;
|
||||
use std::cast;
|
||||
use std::libc::c_void;
|
||||
use std::ptr;
|
||||
use std::uint;
|
||||
use std::vec;
|
||||
|
||||
pub type CFDictionaryApplierFunction = *u8;
|
||||
pub type CFDictionaryCopyDescriptionCallBack = *u8;
|
||||
@@ -66,21 +70,21 @@ pub struct CFDictionary<KeyRefType, ValueRefType> {
|
||||
|
||||
pub type UntypedCFDictionary = CFDictionary<CFStringRef, CFTypeRef>;
|
||||
|
||||
pub impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTypeRef>
|
||||
impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTypeRef>
|
||||
CFDictionary<KeyRefType, ValueRefType> {
|
||||
fn wrap_owned(dictionary: CFDictionaryRef) -> CFDictionary<KeyRefType, ValueRefType> {
|
||||
pub fn wrap_owned(dictionary: CFDictionaryRef) -> CFDictionary<KeyRefType, ValueRefType> {
|
||||
CFDictionary {
|
||||
contents: CFWrapper::wrap_owned(dictionary)
|
||||
}
|
||||
}
|
||||
|
||||
fn new(pairs: &[(KeyRefType,ValueRefType)]) -> CFDictionary<KeyRefType, ValueRefType> {
|
||||
pub fn new(pairs: &[(KeyRefType,ValueRefType)]) -> CFDictionary<KeyRefType, ValueRefType> {
|
||||
let mut keys : ~[CFTypeRef] = ~[];
|
||||
let mut values : ~[CFTypeRef] = ~[];
|
||||
for pairs.each |pair| {
|
||||
// FIXME: "let" would be much nicer here, but that doesn't work yet.
|
||||
match *pair {
|
||||
(key, value) => {
|
||||
(ref key, ref value) => {
|
||||
keys.push(key.as_type_ref());
|
||||
values.push(value.as_type_ref());
|
||||
}
|
||||
@@ -106,17 +110,17 @@ pub impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTy
|
||||
}
|
||||
}
|
||||
|
||||
fn len(&self) -> uint {
|
||||
pub fn len(&self) -> uint {
|
||||
unsafe {
|
||||
CFDictionaryGetCount(self.contents.obj) as uint
|
||||
}
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
fn contains_key(&self, key: &KeyRefType) -> bool {
|
||||
pub fn contains_key(&self, key: &KeyRefType) -> bool {
|
||||
unsafe {
|
||||
CFDictionaryContainsKey(self.contents.obj,
|
||||
cast::transmute::<CFTypeRef, *c_void>(key.as_type_ref()))
|
||||
@@ -124,7 +128,7 @@ pub impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTy
|
||||
}
|
||||
}
|
||||
|
||||
fn find(&self, key: &KeyRefType) -> Option<ValueRefType> {
|
||||
pub fn find(&self, key: &KeyRefType) -> Option<ValueRefType> {
|
||||
unsafe {
|
||||
let value : *c_void = ptr::null();
|
||||
let did_find_value = CFDictionaryGetValueIfPresent(
|
||||
@@ -142,7 +146,7 @@ pub impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTy
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&self, key: &KeyRefType) -> ValueRefType {
|
||||
pub fn get(&self, key: &KeyRefType) -> ValueRefType {
|
||||
let value = self.find(key);
|
||||
if value.is_none() {
|
||||
fail!(fmt!("No entry found for key: %?", key));
|
||||
@@ -150,7 +154,7 @@ pub impl<KeyRefType: Copy + AbstractCFTypeRef, ValueRefType: Copy + AbstractCFTy
|
||||
return value.unwrap();
|
||||
}
|
||||
|
||||
fn each(&self, blk: &fn(&KeyRefType, &ValueRefType) -> bool) -> bool {
|
||||
pub fn each(&self, blk: &fn(&KeyRefType, &ValueRefType) -> bool) -> bool {
|
||||
unsafe {
|
||||
let len = self.len();
|
||||
let null_keys = cast::transmute::<*c_void,KeyRefType>(ptr::null());
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
use base::{AbstractCFTypeRef, Boolean, CFAllocatorRef, CFTypeID, CFTypeRef, CFWrapper};
|
||||
use base::{kCFAllocatorDefault};
|
||||
|
||||
use core::libc::c_void;
|
||||
use std::cast;
|
||||
use std::libc;
|
||||
use std::libc::c_void;
|
||||
|
||||
pub type CFNumberType = u32;
|
||||
|
||||
@@ -50,20 +52,20 @@ pub struct CFNumber {
|
||||
contents: CFWrapper<CFNumberRef, (), ()>
|
||||
}
|
||||
|
||||
pub impl CFNumber {
|
||||
fn wrap_owned(number: CFNumberRef) -> CFNumber {
|
||||
impl CFNumber {
|
||||
pub fn wrap_owned(number: CFNumberRef) -> CFNumber {
|
||||
CFNumber {
|
||||
contents: CFWrapper::wrap_owned(number)
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap_shared(number: CFNumberRef) -> CFNumber {
|
||||
pub fn wrap_shared(number: CFNumberRef) -> CFNumber {
|
||||
CFNumber {
|
||||
contents: CFWrapper::wrap_shared(number)
|
||||
}
|
||||
}
|
||||
|
||||
fn new<T:Copy + ConvertibleToCFNumber>(n: T) -> CFNumber {
|
||||
pub fn new<T:Copy + ConvertibleToCFNumber>(n: T) -> CFNumber {
|
||||
unsafe {
|
||||
let objref = CFNumberCreate(kCFAllocatorDefault,
|
||||
n.cf_number_type(),
|
||||
@@ -74,7 +76,7 @@ pub impl CFNumber {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_i8(&self) -> i8 {
|
||||
pub fn to_i8(&self) -> i8 {
|
||||
let ty = kCFNumberSInt8Type;
|
||||
assert!(self.has_number_type(ty));
|
||||
unsafe {
|
||||
@@ -86,7 +88,7 @@ pub impl CFNumber {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_i16(&self) -> i16 {
|
||||
pub fn to_i16(&self) -> i16 {
|
||||
let ty = kCFNumberSInt16Type;
|
||||
assert!(self.has_number_type(ty));
|
||||
unsafe {
|
||||
@@ -98,7 +100,7 @@ pub impl CFNumber {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_i32(&self) -> i32 {
|
||||
pub fn to_i32(&self) -> i32 {
|
||||
let ty = kCFNumberSInt32Type;
|
||||
assert!(self.has_number_type(ty));
|
||||
unsafe {
|
||||
@@ -110,7 +112,7 @@ pub impl CFNumber {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_float(&self) -> float {
|
||||
pub fn to_float(&self) -> float {
|
||||
unsafe {
|
||||
assert!(self.has_float_type());
|
||||
let ty = CFNumberGetType(self.contents.obj);
|
||||
|
||||
@@ -17,7 +17,9 @@ use base::{
|
||||
CFWrapper,
|
||||
kCFAllocatorDefault,
|
||||
};
|
||||
use core::libc::c_void;
|
||||
use std::cast;
|
||||
use std::libc::c_void;
|
||||
use std::vec;
|
||||
|
||||
pub type CFSetRetainCallBack = *u8;
|
||||
pub type CFSetReleaseCallBack = *u8;
|
||||
@@ -53,8 +55,8 @@ pub struct CFSet<ElemRefType> {
|
||||
contents: CFWrapper<CFSetRef, ElemRefType, ()>
|
||||
}
|
||||
|
||||
pub impl<ElemRefType : AbstractCFTypeRef> CFSet<ElemRefType> {
|
||||
fn new(elems: &[ElemRefType]) -> CFSet<ElemRefType> {
|
||||
impl<ElemRefType : AbstractCFTypeRef> CFSet<ElemRefType> {
|
||||
pub fn new(elems: &[ElemRefType]) -> CFSet<ElemRefType> {
|
||||
let result: CFSetRef;
|
||||
let elems_refs = do vec::map(elems) |e: &ElemRefType| {
|
||||
e.as_type_ref()
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
use base::{AbstractCFTypeRef, Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFRange};
|
||||
use base::{CFRangeMake, CFTypeRef, CFTypeID, CFWrapper, kCFAllocatorDefault, kCFAllocatorNull};
|
||||
|
||||
use std::cast;
|
||||
use std::libc;
|
||||
use std::ptr;
|
||||
use std::str;
|
||||
use std::vec;
|
||||
|
||||
pub type UniChar = libc::c_ushort;
|
||||
|
||||
/*
|
||||
@@ -207,10 +213,10 @@ pub struct CFString {
|
||||
contents: CFWrapper<CFStringRef, (), ()>
|
||||
}
|
||||
|
||||
pub impl CFString {
|
||||
impl CFString {
|
||||
// convenience method to make it easier to wrap extern
|
||||
// CFStringRefs without providing explicit typarams to base::wrap()
|
||||
fn wrap_owned(string: CFStringRef) -> CFString {
|
||||
pub fn wrap_owned(string: CFStringRef) -> CFString {
|
||||
CFString {
|
||||
contents: CFWrapper::wrap_owned(string)
|
||||
}
|
||||
@@ -218,7 +224,7 @@ pub impl CFString {
|
||||
|
||||
// convenience method to make it easier to wrap extern
|
||||
// CFStringRefs without providing explicit typarams to base::wrap()
|
||||
fn wrap_shared(string: CFStringRef) -> CFString {
|
||||
pub fn wrap_shared(string: CFStringRef) -> CFString {
|
||||
CFString {
|
||||
contents: CFWrapper::wrap_shared(string)
|
||||
}
|
||||
@@ -226,7 +232,7 @@ pub impl CFString {
|
||||
|
||||
// like CFString::new, but references a string that can be used as
|
||||
// a backing store by virtue of being statically allocated.
|
||||
fn new_static(string: &'static str) -> CFString {
|
||||
pub fn new_static(string: &'static str) -> CFString {
|
||||
let string_ref = do str::as_buf(string) |bytes, len| {
|
||||
unsafe {
|
||||
CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
|
||||
@@ -243,7 +249,7 @@ pub impl CFString {
|
||||
}
|
||||
}
|
||||
|
||||
fn new(string: &str) -> CFString {
|
||||
pub fn new(string: &str) -> CFString {
|
||||
let string_ref = do str::as_buf(string) |bytes, len| {
|
||||
unsafe {
|
||||
CFStringCreateWithBytes(kCFAllocatorDefault,
|
||||
|
||||
Reference in New Issue
Block a user