Skip to content

Commit ef44809

Browse files
authored
Auto merge of #592 - michaelwright235:bag, r=jdm
sys: Introduce CFBag Implements CFBag related functions and constants.
2 parents 3ef0b36 + 91d8daa commit ef44809

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

core-foundation-sys/src/bag.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2023 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, Boolean, CFHashCode, CFIndex, CFTypeID};
13+
use string::CFStringRef;
14+
15+
#[repr(C)]
16+
pub struct __CFBag(c_void);
17+
18+
pub type CFBagRef = *const __CFBag;
19+
pub type CFMutableBagRef = *mut __CFBag;
20+
21+
pub type CFBagRetainCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void;
22+
pub type CFBagReleaseCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void);
23+
pub type CFBagCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef;
24+
pub type CFBagEqualCallBack = extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean;
25+
pub type CFBagHashCallBack = extern "C" fn(value: *const c_void) -> CFHashCode;
26+
27+
#[repr(C)]
28+
#[derive(Debug, Clone, Copy)]
29+
pub struct CFBagCallBacks {
30+
pub version: CFIndex,
31+
pub retain: CFBagRetainCallBack,
32+
pub release: CFBagReleaseCallBack,
33+
pub copyDescription: CFBagCopyDescriptionCallBack,
34+
pub equal: CFBagEqualCallBack,
35+
pub hash: CFBagHashCallBack
36+
}
37+
38+
pub type CFBagApplierFunction = extern "C" fn(value: *const c_void, context: *mut c_void);
39+
40+
extern {
41+
/*
42+
* CFBag.h
43+
*/
44+
/* Predefined Callback Structures */
45+
pub static kCFTypeBagCallBacks: CFBagCallBacks;
46+
pub static kCFCopyStringBagCallBacks: CFBagCallBacks;
47+
48+
/* CFBag */
49+
/* Creating a Bag */
50+
pub fn CFBagCreate(allocator: CFAllocatorRef, values: *const *const c_void, numValues: CFIndex, callBacks: *const CFBagCallBacks) -> CFBagRef;
51+
pub fn CFBagCreateCopy(allocator: CFAllocatorRef, theBag: CFBagRef) -> CFBagRef;
52+
53+
/* Examining a Bag */
54+
pub fn CFBagContainsValue(theBag: CFBagRef, value: *const c_void) -> Boolean;
55+
pub fn CFBagGetCount(theBag: CFBagRef) -> CFIndex;
56+
pub fn CFBagGetCountOfValue(theBag: CFBagRef, value: *const c_void) -> CFIndex;
57+
pub fn CFBagGetValue(theBag: CFBagRef, value: *const c_void) -> *const c_void;
58+
pub fn CFBagGetValueIfPresent(theBag: CFBagRef, candidate: *const c_void, value: *const *const c_void) -> Boolean;
59+
pub fn CFBagGetValues(theBag: CFBagRef, values: *const *const c_void);
60+
61+
/* Applying a Function to the Contents of a Bag */
62+
pub fn CFBagApplyFunction(theBag: CFBagRef, applier: CFBagApplierFunction, context: *mut c_void);
63+
64+
/* Getting the CFBag Type ID */
65+
pub fn CFBagGetTypeID() -> CFTypeID;
66+
67+
/* CFMutableBag */
68+
/* Creating a Mutable Bag */
69+
pub fn CFBagCreateMutable(allocator: CFAllocatorRef, capacity: CFIndex, callBacks: *const CFBagCallBacks) -> CFMutableBagRef;
70+
pub fn CFBagCreateMutableCopy(allocator: CFAllocatorRef, capacity: CFIndex, theBag: CFBagRef) -> CFMutableBagRef;
71+
72+
/* Modifying a Mutable Bag */
73+
pub fn CFBagAddValue(theBag: CFMutableBagRef, value: *const c_void);
74+
pub fn CFBagRemoveAllValues(theBag: CFMutableBagRef);
75+
pub fn CFBagRemoveValue(theBag: CFMutableBagRef, value: *const c_void);
76+
pub fn CFBagReplaceValue(theBag: CFMutableBagRef, value: *const c_void);
77+
pub fn CFBagSetValue(theBag: CFMutableBagRef, value: *const c_void);
78+
}

core-foundation-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {}
2222

2323
pub mod array;
2424
pub mod attributed_string;
25+
pub mod bag;
2526
pub mod base;
2627
pub mod bundle;
2728
pub mod calendar;

0 commit comments

Comments
 (0)