1 // Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9 
10 use std::os::raw::c_void;
11 
12 use base::{CFAllocatorRef, CFTypeID, CFComparisonResult};
13 
14 #[repr(C)]
15 pub struct __CFBoolean(c_void);
16 
17 pub type CFBooleanRef = *const __CFBoolean;
18 
19 pub type CFNumberType = u32;
20 
21 // members of enum CFNumberType
22 pub const kCFNumberSInt8Type:     CFNumberType = 1;
23 pub const kCFNumberSInt16Type:    CFNumberType = 2;
24 pub const kCFNumberSInt32Type:    CFNumberType = 3;
25 pub const kCFNumberSInt64Type:    CFNumberType = 4;
26 pub const kCFNumberFloat32Type:   CFNumberType = 5;
27 pub const kCFNumberFloat64Type:   CFNumberType = 6;
28 pub const kCFNumberCharType:      CFNumberType = 7;
29 pub const kCFNumberShortType:     CFNumberType = 8;
30 pub const kCFNumberIntType:       CFNumberType = 9;
31 pub const kCFNumberLongType:      CFNumberType = 10;
32 pub const kCFNumberLongLongType:  CFNumberType = 11;
33 pub const kCFNumberFloatType:     CFNumberType = 12;
34 pub const kCFNumberDoubleType:    CFNumberType = 13;
35 pub const kCFNumberCFIndexType:   CFNumberType = 14;
36 pub const kCFNumberNSIntegerType: CFNumberType = 15;
37 pub const kCFNumberCGFloatType:   CFNumberType = 16;
38 pub const kCFNumberMaxType:       CFNumberType = 16;
39 
40 // This is an enum due to zero-sized types warnings.
41 // For more details see https://github.com/rust-lang/rust/issues/27303
42 pub enum __CFNumber {}
43 
44 pub type CFNumberRef = *const __CFNumber;
45 
46 extern {
47     /*
48      * CFNumber.h
49      */
50     pub static kCFBooleanTrue: CFBooleanRef;
51     pub static kCFBooleanFalse: CFBooleanRef;
52 
CFBooleanGetTypeID() -> CFTypeID53     pub fn CFBooleanGetTypeID() -> CFTypeID;
CFBooleanGetValue(boolean: CFBooleanRef) -> bool54     pub fn CFBooleanGetValue(boolean: CFBooleanRef) -> bool;
55 
CFNumberCreate(allocator: CFAllocatorRef, theType: CFNumberType, valuePtr: *const c_void) -> CFNumberRef56     pub fn CFNumberCreate(allocator: CFAllocatorRef, theType: CFNumberType, valuePtr: *const c_void)
57                           -> CFNumberRef;
58     //fn CFNumberGetByteSize
CFNumberGetValue(number: CFNumberRef, theType: CFNumberType, valuePtr: *mut c_void) -> bool59     pub fn CFNumberGetValue(number: CFNumberRef, theType: CFNumberType, valuePtr: *mut c_void) -> bool;
CFNumberCompare(date: CFNumberRef, other: CFNumberRef, context: *mut c_void) -> CFComparisonResult60     pub fn CFNumberCompare(date: CFNumberRef, other: CFNumberRef, context: *mut c_void) -> CFComparisonResult;
CFNumberGetTypeID() -> CFTypeID61     pub fn CFNumberGetTypeID() -> CFTypeID;
CFNumberGetType(number: CFNumberRef) -> CFNumberType62     pub fn CFNumberGetType(number: CFNumberRef) -> CFNumberType;
63 }
64 
65 #[cfg(test)]
66 mod test {
67     use super::*;
68 
69     #[test]
match_for_type_id_should_be_backwards_compatible()70     fn match_for_type_id_should_be_backwards_compatible() {
71         let type_id = kCFNumberFloat32Type;
72         // this is the old style of matching for static variables
73         match type_id {
74             vf64 if vf64 == kCFNumberFloat32Type => assert!(true),
75             _ => panic!("should not happen"),
76         };
77 
78         // this is new new style of matching for consts
79         match type_id {
80             kCFNumberFloat32Type => assert!(true),
81             _ => panic!("should not happen"),
82         };
83     }
84 }
85