use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
use crate::*;
#[doc(alias = "SKSearchRef")]
#[repr(C)]
pub struct SKSearch {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl SKSearch {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__SKSearch"> for SKSearch {}
);
unsafe impl ConcreteType for SKSearch {
#[doc(alias = "SKSearchGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn SKSearchGetTypeID() -> CFTypeID;
}
unsafe { SKSearchGetTypeID() }
}
}
pub type SKSearchOptions = u32;
pub const kSKSearchOptionDefault: c_uint = 0;
pub const kSKSearchOptionNoRelevanceScores: c_uint = 1 << 0;
pub const kSKSearchOptionSpaceMeansOR: c_uint = 1 << 1;
pub const kSKSearchOptionFindSimilar: c_uint = 1 << 2;
impl SKSearch {
#[doc(alias = "SKSearchCreate")]
#[cfg(feature = "SKIndex")]
#[inline]
pub unsafe fn new(
in_index: Option<&SKIndex>,
in_query: Option<&CFString>,
in_search_options: SKSearchOptions,
) -> Option<CFRetained<SKSearch>> {
extern "C-unwind" {
fn SKSearchCreate(
in_index: Option<&SKIndex>,
in_query: Option<&CFString>,
in_search_options: SKSearchOptions,
) -> Option<NonNull<SKSearch>>;
}
let ret = unsafe { SKSearchCreate(in_index, in_query, in_search_options) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "SKSearchCancel")]
#[inline]
pub unsafe fn cancel(&self) {
extern "C-unwind" {
fn SKSearchCancel(in_search: &SKSearch);
}
unsafe { SKSearchCancel(self) }
}
#[doc(alias = "SKSearchFindMatches")]
#[cfg(feature = "SKIndex")]
#[inline]
pub unsafe fn find_matches(
&self,
in_maximum_count: CFIndex,
out_document_i_ds_array: *mut SKDocumentID,
out_scores_array: *mut c_float,
maximum_time: CFTimeInterval,
out_found_count: *mut CFIndex,
) -> bool {
extern "C-unwind" {
fn SKSearchFindMatches(
in_search: &SKSearch,
in_maximum_count: CFIndex,
out_document_i_ds_array: *mut SKDocumentID,
out_scores_array: *mut c_float,
maximum_time: CFTimeInterval,
out_found_count: *mut CFIndex,
) -> Boolean;
}
let ret = unsafe {
SKSearchFindMatches(
self,
in_maximum_count,
out_document_i_ds_array,
out_scores_array,
maximum_time,
out_found_count,
)
};
ret != 0
}
}
#[cfg(feature = "SKIndex")]
impl SKIndex {
#[doc(alias = "SKIndexCopyInfoForDocumentIDs")]
#[cfg(feature = "SKIndex")]
#[inline]
pub unsafe fn copy_info_for_document_ids(
&self,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_names_array: *mut *const CFString,
out_parent_i_ds_array: *mut SKDocumentID,
) {
extern "C-unwind" {
fn SKIndexCopyInfoForDocumentIDs(
in_index: &SKIndex,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_names_array: *mut *const CFString,
out_parent_i_ds_array: *mut SKDocumentID,
);
}
unsafe {
SKIndexCopyInfoForDocumentIDs(
self,
in_count,
in_document_i_ds_array,
out_names_array,
out_parent_i_ds_array,
)
}
}
#[doc(alias = "SKIndexCopyDocumentRefsForDocumentIDs")]
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[inline]
pub unsafe fn copy_document_refs_for_document_ids(
&self,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_document_refs_array: *mut *const SKDocument,
) {
extern "C-unwind" {
fn SKIndexCopyDocumentRefsForDocumentIDs(
in_index: &SKIndex,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_document_refs_array: *mut *const SKDocument,
);
}
unsafe {
SKIndexCopyDocumentRefsForDocumentIDs(
self,
in_count,
in_document_i_ds_array,
out_document_refs_array,
)
}
}
#[doc(alias = "SKIndexCopyDocumentURLsForDocumentIDs")]
#[cfg(feature = "SKIndex")]
#[inline]
pub unsafe fn copy_document_urls_for_document_ids(
&self,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_document_ur_ls_array: *mut *const CFURL,
) {
extern "C-unwind" {
fn SKIndexCopyDocumentURLsForDocumentIDs(
in_index: &SKIndex,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_document_ur_ls_array: *mut *const CFURL,
);
}
unsafe {
SKIndexCopyDocumentURLsForDocumentIDs(
self,
in_count,
in_document_i_ds_array,
out_document_ur_ls_array,
)
}
}
}
#[doc(alias = "SKSearchGroupRef")]
#[repr(C)]
pub struct SKSearchGroup {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl SKSearchGroup {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__SKSearchGroup"> for SKSearchGroup {}
);
unsafe impl ConcreteType for SKSearchGroup {
#[doc(alias = "SKSearchGroupGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn SKSearchGroupGetTypeID() -> CFTypeID;
}
unsafe { SKSearchGroupGetTypeID() }
}
}
#[doc(alias = "SKSearchResultsRef")]
#[repr(C)]
pub struct SKSearchResults {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl SKSearchResults {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__SKSearchResults"> for SKSearchResults {}
);
unsafe impl ConcreteType for SKSearchResults {
#[doc(alias = "SKSearchResultsGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn SKSearchResultsGetTypeID() -> CFTypeID;
}
unsafe { SKSearchResultsGetTypeID() }
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SKSearchType(pub c_uint);
impl SKSearchType {
#[doc(alias = "kSKSearchRanked")]
pub const Ranked: Self = Self(0);
#[doc(alias = "kSKSearchBooleanRanked")]
pub const BooleanRanked: Self = Self(1);
#[doc(alias = "kSKSearchRequiredRanked")]
pub const RequiredRanked: Self = Self(2);
#[doc(alias = "kSKSearchPrefixRanked")]
pub const PrefixRanked: Self = Self(3);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for SKSearchType {
const ENCODING: Encoding = c_uint::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for SKSearchType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
pub type SKSearchResultsFilterCallBack =
Option<unsafe extern "C-unwind" fn(*mut SKIndex, *const SKDocument, *mut c_void) -> Boolean>;
impl SKSearchGroup {
#[doc(alias = "SKSearchGroupCreate")]
#[deprecated = "No longer supported"]
#[inline]
pub unsafe fn new(
in_array_of_in_indexes: Option<&CFArray>,
) -> Option<CFRetained<SKSearchGroup>> {
extern "C-unwind" {
fn SKSearchGroupCreate(
in_array_of_in_indexes: Option<&CFArray>,
) -> Option<NonNull<SKSearchGroup>>;
}
let ret = unsafe { SKSearchGroupCreate(in_array_of_in_indexes) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "SKSearchGroupCopyIndexes")]
#[deprecated = "No longer supported"]
#[inline]
pub unsafe fn indexes(&self) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn SKSearchGroupCopyIndexes(
in_search_group: &SKSearchGroup,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { SKSearchGroupCopyIndexes(self) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
impl SKSearchResults {
#[doc(alias = "SKSearchResultsCreateWithQuery")]
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[deprecated = "No longer supported"]
#[inline]
pub unsafe fn with_query(
in_search_group: Option<&SKSearchGroup>,
in_query: Option<&CFString>,
in_search_type: SKSearchType,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<CFRetained<SKSearchResults>> {
extern "C-unwind" {
fn SKSearchResultsCreateWithQuery(
in_search_group: Option<&SKSearchGroup>,
in_query: Option<&CFString>,
in_search_type: SKSearchType,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<NonNull<SKSearchResults>>;
}
let ret = unsafe {
SKSearchResultsCreateWithQuery(
in_search_group,
in_query,
in_search_type,
in_max_found_documents,
in_context,
in_filter_call_back,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "SKSearchResultsCreateWithDocuments")]
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[deprecated = "No longer supported"]
#[inline]
pub unsafe fn with_documents(
in_search_group: Option<&SKSearchGroup>,
in_example_documents: Option<&CFArray>,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<CFRetained<SKSearchResults>> {
extern "C-unwind" {
fn SKSearchResultsCreateWithDocuments(
in_search_group: Option<&SKSearchGroup>,
in_example_documents: Option<&CFArray>,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<NonNull<SKSearchResults>>;
}
let ret = unsafe {
SKSearchResultsCreateWithDocuments(
in_search_group,
in_example_documents,
in_max_found_documents,
in_context,
in_filter_call_back,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "SKSearchResultsGetCount")]
#[deprecated = "No longer supported"]
#[inline]
pub unsafe fn count(&self) -> CFIndex {
extern "C-unwind" {
fn SKSearchResultsGetCount(in_search_results: &SKSearchResults) -> CFIndex;
}
unsafe { SKSearchResultsGetCount(self) }
}
#[doc(alias = "SKSearchResultsGetInfoInRange")]
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[deprecated = "No longer supported"]
#[inline]
pub unsafe fn info_in_range(
&self,
in_range: CFRange,
out_documents_array: *mut *const SKDocument,
out_indexes_array: *mut *mut SKIndex,
out_scores_array: *mut c_float,
) -> CFIndex {
extern "C-unwind" {
fn SKSearchResultsGetInfoInRange(
in_search_results: &SKSearchResults,
in_range: CFRange,
out_documents_array: *mut *const SKDocument,
out_indexes_array: *mut *mut SKIndex,
out_scores_array: *mut c_float,
) -> CFIndex;
}
unsafe {
SKSearchResultsGetInfoInRange(
self,
in_range,
out_documents_array,
out_indexes_array,
out_scores_array,
)
}
}
#[doc(alias = "SKSearchResultsCopyMatchingTerms")]
#[deprecated = "No longer supported"]
#[inline]
pub unsafe fn matching_terms(&self, in_item: CFIndex) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn SKSearchResultsCopyMatchingTerms(
in_search_results: &SKSearchResults,
in_item: CFIndex,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { SKSearchResultsCopyMatchingTerms(self, in_item) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
}
#[cfg(feature = "SKIndex")]
#[deprecated = "renamed to `SKSearch::new`"]
#[inline]
pub unsafe extern "C-unwind" fn SKSearchCreate(
in_index: Option<&SKIndex>,
in_query: Option<&CFString>,
in_search_options: SKSearchOptions,
) -> Option<CFRetained<SKSearch>> {
extern "C-unwind" {
fn SKSearchCreate(
in_index: Option<&SKIndex>,
in_query: Option<&CFString>,
in_search_options: SKSearchOptions,
) -> Option<NonNull<SKSearch>>;
}
let ret = unsafe { SKSearchCreate(in_index, in_query, in_search_options) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `SKSearch::cancel`"]
pub fn SKSearchCancel(in_search: &SKSearch);
}
#[cfg(feature = "SKIndex")]
#[deprecated = "renamed to `SKSearch::find_matches`"]
#[inline]
pub unsafe extern "C-unwind" fn SKSearchFindMatches(
in_search: &SKSearch,
in_maximum_count: CFIndex,
out_document_i_ds_array: *mut SKDocumentID,
out_scores_array: *mut c_float,
maximum_time: CFTimeInterval,
out_found_count: *mut CFIndex,
) -> bool {
extern "C-unwind" {
fn SKSearchFindMatches(
in_search: &SKSearch,
in_maximum_count: CFIndex,
out_document_i_ds_array: *mut SKDocumentID,
out_scores_array: *mut c_float,
maximum_time: CFTimeInterval,
out_found_count: *mut CFIndex,
) -> Boolean;
}
let ret = unsafe {
SKSearchFindMatches(
in_search,
in_maximum_count,
out_document_i_ds_array,
out_scores_array,
maximum_time,
out_found_count,
)
};
ret != 0
}
extern "C-unwind" {
#[cfg(feature = "SKIndex")]
#[deprecated = "renamed to `SKIndex::copy_info_for_document_ids`"]
pub fn SKIndexCopyInfoForDocumentIDs(
in_index: &SKIndex,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_names_array: *mut *const CFString,
out_parent_i_ds_array: *mut SKDocumentID,
);
}
extern "C-unwind" {
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[deprecated = "renamed to `SKIndex::copy_document_refs_for_document_ids`"]
pub fn SKIndexCopyDocumentRefsForDocumentIDs(
in_index: &SKIndex,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_document_refs_array: *mut *const SKDocument,
);
}
extern "C-unwind" {
#[cfg(feature = "SKIndex")]
#[deprecated = "renamed to `SKIndex::copy_document_urls_for_document_ids`"]
pub fn SKIndexCopyDocumentURLsForDocumentIDs(
in_index: &SKIndex,
in_count: CFIndex,
in_document_i_ds_array: *mut SKDocumentID,
out_document_ur_ls_array: *mut *const CFURL,
);
}
#[deprecated = "renamed to `SKSearchGroup::new`"]
#[inline]
pub unsafe extern "C-unwind" fn SKSearchGroupCreate(
in_array_of_in_indexes: Option<&CFArray>,
) -> Option<CFRetained<SKSearchGroup>> {
extern "C-unwind" {
fn SKSearchGroupCreate(
in_array_of_in_indexes: Option<&CFArray>,
) -> Option<NonNull<SKSearchGroup>>;
}
let ret = unsafe { SKSearchGroupCreate(in_array_of_in_indexes) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `SKSearchGroup::indexes`"]
#[inline]
pub unsafe extern "C-unwind" fn SKSearchGroupCopyIndexes(
in_search_group: &SKSearchGroup,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn SKSearchGroupCopyIndexes(in_search_group: &SKSearchGroup) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { SKSearchGroupCopyIndexes(in_search_group) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[deprecated = "renamed to `SKSearchResults::with_query`"]
#[inline]
pub unsafe extern "C-unwind" fn SKSearchResultsCreateWithQuery(
in_search_group: Option<&SKSearchGroup>,
in_query: Option<&CFString>,
in_search_type: SKSearchType,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<CFRetained<SKSearchResults>> {
extern "C-unwind" {
fn SKSearchResultsCreateWithQuery(
in_search_group: Option<&SKSearchGroup>,
in_query: Option<&CFString>,
in_search_type: SKSearchType,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<NonNull<SKSearchResults>>;
}
let ret = unsafe {
SKSearchResultsCreateWithQuery(
in_search_group,
in_query,
in_search_type,
in_max_found_documents,
in_context,
in_filter_call_back,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[deprecated = "renamed to `SKSearchResults::with_documents`"]
#[inline]
pub unsafe extern "C-unwind" fn SKSearchResultsCreateWithDocuments(
in_search_group: Option<&SKSearchGroup>,
in_example_documents: Option<&CFArray>,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<CFRetained<SKSearchResults>> {
extern "C-unwind" {
fn SKSearchResultsCreateWithDocuments(
in_search_group: Option<&SKSearchGroup>,
in_example_documents: Option<&CFArray>,
in_max_found_documents: CFIndex,
in_context: *mut c_void,
in_filter_call_back: SKSearchResultsFilterCallBack,
) -> Option<NonNull<SKSearchResults>>;
}
let ret = unsafe {
SKSearchResultsCreateWithDocuments(
in_search_group,
in_example_documents,
in_max_found_documents,
in_context,
in_filter_call_back,
)
};
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `SKSearchResults::count`"]
pub fn SKSearchResultsGetCount(in_search_results: &SKSearchResults) -> CFIndex;
}
extern "C-unwind" {
#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
#[deprecated = "renamed to `SKSearchResults::info_in_range`"]
pub fn SKSearchResultsGetInfoInRange(
in_search_results: &SKSearchResults,
in_range: CFRange,
out_documents_array: *mut *const SKDocument,
out_indexes_array: *mut *mut SKIndex,
out_scores_array: *mut c_float,
) -> CFIndex;
}
#[deprecated = "renamed to `SKSearchResults::matching_terms`"]
#[inline]
pub unsafe extern "C-unwind" fn SKSearchResultsCopyMatchingTerms(
in_search_results: &SKSearchResults,
in_item: CFIndex,
) -> Option<CFRetained<CFArray>> {
extern "C-unwind" {
fn SKSearchResultsCopyMatchingTerms(
in_search_results: &SKSearchResults,
in_item: CFIndex,
) -> Option<NonNull<CFArray>>;
}
let ret = unsafe { SKSearchResultsCopyMatchingTerms(in_search_results, in_item) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}