Debian Codegraph @

.cargo/vendor/core-foundation-sys/src/number.rs

raw
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 crate::base::{Boolean, CFAllocatorRef, CFComparisonResult, CFIndex, CFTypeID};
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 "C" {
47 /*
48 * CFNumber.h
49 */
50 pub static kCFBooleanTrue: CFBooleanRef;
51 pub static kCFBooleanFalse: CFBooleanRef;
52 pub static kCFNumberPositiveInfinity: CFNumberRef;
53 pub static kCFNumberNegativeInfinity: CFNumberRef;
54 pub static kCFNumberNaN: CFNumberRef;
55
56 /* Creating a Number */
57 pub fn CFNumberCreate(
58 allocator: CFAllocatorRef,
59 theType: CFNumberType,
60 valuePtr: *const c_void,
61 ) -> CFNumberRef;
62
63 /* Getting Information About Numbers */
64 pub fn CFNumberGetByteSize(number: CFNumberRef) -> CFIndex;
65 pub fn CFNumberGetType(number: CFNumberRef) -> CFNumberType;
66 pub fn CFNumberGetValue(
67 number: CFNumberRef,
68 theType: CFNumberType,
69 valuePtr: *mut c_void,
70 ) -> bool;
71 pub fn CFNumberIsFloatType(number: CFNumberRef) -> Boolean;
72
73 /* Comparing Numbers */
74 pub fn CFNumberCompare(
75 date: CFNumberRef,
76 other: CFNumberRef,
77 context: *mut c_void,
78 ) -> CFComparisonResult;
79
80 /* Getting the CFNumber Type ID */
81 pub fn CFNumberGetTypeID() -> CFTypeID;
82
83 pub fn CFBooleanGetValue(boolean: CFBooleanRef) -> bool;
84 pub fn CFBooleanGetTypeID() -> CFTypeID;
85 }
86
87 #[cfg(test)]
88 mod test {
89 use super::*;
90
91 #[test]
92 fn match_for_type_id_should_be_backwards_compatible() {
93 let type_id = kCFNumberFloat32Type;
94 // this is the old style of matching for static variables
95 match type_id {
96 vf64 if vf64 == kCFNumberFloat32Type => assert!(true),
97 _ => panic!("should not happen"),
98 };
99
100 // this is new new style of matching for consts
101 match type_id {
102 kCFNumberFloat32Type => assert!(true),
103 _ => panic!("should not happen"),
104 };
105 }
106 }