Change AbstractCFType::as_type_ref() to use get_ref(), and add AbstractCFTypeRef::as_CFTypeRef().
This commit is contained in:
@@ -47,9 +47,7 @@ pub impl<ElemRefType : AbstractCFTypeRef,
|
||||
static fn new(elems: &[ElemType]) -> CFArray<ElemRefType, ElemType> {
|
||||
let array_ref : CFArrayRef;
|
||||
|
||||
let elems_refs = do vec::map(elems) |e| {
|
||||
e.as_type_ref()
|
||||
};
|
||||
let elems_refs = do vec::map(elems) |e: &ElemType| { e.get_ref().as_type_ref() };
|
||||
|
||||
unsafe {
|
||||
array_ref = CFArrayCreate(kCFAllocatorDefault,
|
||||
@@ -81,6 +79,9 @@ pub impl<ElemRefType : AbstractCFTypeRef,
|
||||
pub impl<ElemRefType : AbstractCFTypeRef,
|
||||
ElemType : AbstractCFType<ElemRefType>>
|
||||
CFArray<ElemRefType, ElemType> : AbstractCFType<CFArrayRef> {
|
||||
|
||||
pure fn get_ref() -> CFArrayRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFArrayRef) -> CFArray<ElemRefType, ElemType> {
|
||||
CFArray { obj: obj }
|
||||
}
|
||||
@@ -88,12 +89,6 @@ pub impl<ElemRefType : AbstractCFTypeRef,
|
||||
static fn unwrap(wrapper: CFArray<ElemRefType, ElemType>) -> CFArrayRef {
|
||||
wrapper.obj
|
||||
}
|
||||
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
unsafe {
|
||||
cast::transmute(self.obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<ElemRefType : AbstractCFTypeRef,
|
||||
|
||||
@@ -39,7 +39,7 @@ trait AbstractCFTypeRef {
|
||||
}
|
||||
|
||||
trait AbstractCFType<T: AbstractCFTypeRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef;
|
||||
pure fn get_ref() -> T;
|
||||
static fn wrap(T) -> self;
|
||||
static fn unwrap(wrapper: self) -> T;
|
||||
}
|
||||
@@ -49,9 +49,8 @@ impl CFTypeRef : AbstractCFTypeRef {
|
||||
}
|
||||
|
||||
impl CFType : AbstractCFType<CFTypeRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
self.obj
|
||||
}
|
||||
pure fn get_ref() -> CFTypeRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFTypeRef) -> CFType {
|
||||
CFType { obj: obj }
|
||||
}
|
||||
@@ -62,30 +61,44 @@ impl CFType : AbstractCFType<CFTypeRef> {
|
||||
}
|
||||
|
||||
trait CFTypeOps<T:AbstractCFTypeRef> {
|
||||
fn as_type(&self) -> CFType;
|
||||
static fn wrap_borrowed(T) -> self;
|
||||
pure fn get_type_ref(&self) -> CFTypeRef;
|
||||
static fn as_CFType(o: self) -> CFType;
|
||||
fn clone_as_CFType(&self) -> CFType;
|
||||
static fn clone(&T) -> self;
|
||||
fn retain_count(&self) -> CFIndex;
|
||||
fn show(&self);
|
||||
}
|
||||
|
||||
impl<T:AbstractCFTypeRef,S:AbstractCFType<T>> S : CFTypeOps<T> {
|
||||
// FIXME: Should move, but there's a linearity bug.
|
||||
fn as_type(&self) -> CFType {
|
||||
CFRetain(self.as_type_ref());
|
||||
CFType { obj: self.as_type_ref() }
|
||||
impl<T:Copy AbstractCFTypeRef,S:AbstractCFType<T>> S : CFTypeOps<T> {
|
||||
// not actually unsafe
|
||||
pure fn get_type_ref(&self) -> CFTypeRef unsafe {
|
||||
self.get_ref().as_type_ref()
|
||||
}
|
||||
|
||||
static fn wrap_borrowed(cfref: T) -> S {
|
||||
// FIXME: Should move, but there's a linearity bug.
|
||||
static fn as_CFType(obj: S) -> CFType {
|
||||
let tyref : CFTypeRef = base::unwrap(move obj).as_type_ref();
|
||||
CFType { obj: tyref }
|
||||
}
|
||||
|
||||
// FIXME: Should move, but there's a linearity bug.
|
||||
fn clone_as_CFType(&self) -> CFType {
|
||||
let tyref = self.get_ref().as_type_ref();
|
||||
CFRetain(tyref);
|
||||
CFType { obj: tyref }
|
||||
}
|
||||
|
||||
static fn clone(cfref: &T) -> S {
|
||||
CFRetain(cfref.as_type_ref());
|
||||
base::wrap(move cfref)
|
||||
base::wrap(copy *cfref)
|
||||
}
|
||||
|
||||
fn retain_count(&self) -> CFIndex {
|
||||
CFGetRetainCount(self.as_type_ref())
|
||||
CFGetRetainCount(self.get_type_ref())
|
||||
}
|
||||
|
||||
fn show(&self) {
|
||||
CFShow(self.as_type_ref());
|
||||
CFShow(self.get_type_ref());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -41,9 +41,7 @@ pub impl CFBoolean {
|
||||
}
|
||||
|
||||
impl CFBoolean : AbstractCFType<CFBooleanRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
unsafe { cast::transmute(self.obj) }
|
||||
}
|
||||
pure fn get_ref() -> CFBooleanRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFBooleanRef) -> CFBoolean {
|
||||
CFBoolean { obj: obj }
|
||||
|
||||
@@ -30,9 +30,8 @@ struct CFData {
|
||||
}
|
||||
|
||||
impl CFData : AbstractCFType<CFDataRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
self.obj.as_type_ref()
|
||||
}
|
||||
pure fn get_ref() -> CFDataRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFDataRef) -> CFData {
|
||||
CFData { obj: obj }
|
||||
}
|
||||
|
||||
+4
-6
@@ -53,11 +53,8 @@ pub impl<KeyRefType : AbstractCFTypeRef,
|
||||
KeyType : AbstractCFType<KeyRefType>,
|
||||
ValueType : AbstractCFType<ValueRefType>>
|
||||
CFDictionary<KeyRefType, ValueRefType, KeyType, ValueType> : AbstractCFType<CFDictionaryRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
unsafe { self.obj.as_type_ref() }
|
||||
}
|
||||
|
||||
pure fn borrow_ref(&self) -> &self/CFDictionaryRef { &self.obj }
|
||||
pure fn get_ref() -> CFDictionaryRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFDictionaryRef) -> CFDictionary<KeyRefType, ValueRefType, KeyType, ValueType> {
|
||||
CFDictionary { obj: obj }
|
||||
@@ -80,8 +77,9 @@ pub impl<KeyRefType : AbstractCFTypeRef,
|
||||
// FIXME: "let" would be much nicer here, but that doesn't work yet.
|
||||
match *pair {
|
||||
(ref key, ref value) => {
|
||||
keys.push(key.as_type_ref());
|
||||
values.push(value.as_type_ref());
|
||||
// TODO: should be able to say key.get_type_ref(), but resolve isn't having any of it.
|
||||
keys.push(key.get_ref().as_type_ref());
|
||||
values.push(value.get_ref().as_type_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,9 +102,7 @@ pub impl CFNumber {
|
||||
}
|
||||
|
||||
impl CFNumber : AbstractCFType<CFNumberRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
unsafe { cast::transmute(self.obj) }
|
||||
}
|
||||
pure fn get_ref() -> CFNumberRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFNumberRef) -> CFNumber {
|
||||
CFNumber { obj: obj }
|
||||
|
||||
@@ -42,11 +42,7 @@ pub struct CFSet {
|
||||
}
|
||||
|
||||
pub impl CFSet : AbstractCFType<CFSetRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
unsafe {
|
||||
self.obj.as_type_ref()
|
||||
}
|
||||
}
|
||||
pure fn get_ref() -> CFSetRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFSetRef) -> CFSet {
|
||||
CFSet { obj: obj }
|
||||
|
||||
@@ -28,11 +28,7 @@ pub struct CFString {
|
||||
}
|
||||
|
||||
pub impl CFString : AbstractCFType<CFStringRef> {
|
||||
pure fn as_type_ref(&self) -> CFTypeRef {
|
||||
unsafe {
|
||||
reinterpret_cast(&self.obj)
|
||||
}
|
||||
}
|
||||
pure fn get_ref() -> CFStringRef { self.obj }
|
||||
|
||||
static fn wrap(obj: CFStringRef) -> CFString {
|
||||
CFString { obj: obj }
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use base::CFTypeOps;
|
||||
use boolean::CFBoolean;
|
||||
use number::CFNumber;
|
||||
use boolean::{CFBoolean, CFBooleanRef};
|
||||
use number::{CFNumber, CFNumberRef};
|
||||
use dictionary::CFDictionary;
|
||||
use string::CFString;
|
||||
use string::{CFString, CFStringRef};
|
||||
|
||||
fn main() {
|
||||
/*let n = CFNumber::new_number(42 as i32);
|
||||
io::println(fmt!("%d", (&n).retain_count() as int));
|
||||
(&n).show();*/
|
||||
let d = CFDictionary::new([
|
||||
(CFString::new_static("Foo"), (&CFString::new_static("Bar")).as_type()),
|
||||
(CFString::new_static("Baz"), (&CFBoolean::true_value()).as_type()),
|
||||
(CFString::new_static("Boo"), (&CFNumber::new(42 as i32)).as_type()),
|
||||
(CFString::new_static("Foo"), base::as_CFType::<CFStringRef, CFString>(CFString::new_static("Bar"))),
|
||||
(CFString::new_static("Baz"), base::as_CFType::<CFBooleanRef, CFBoolean>(CFBoolean::true_value())),
|
||||
(CFString::new_static("Boo"), base::as_CFType::<CFNumberRef, CFNumber>(CFNumber::new(42 as i32))),
|
||||
]);
|
||||
(&d).show();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user