Path: blob/master/thirdparty/metal-cpp/Foundation/NSPrivate.hpp
21085 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Foundation/NSPrivate.hpp3//4// Copyright 2020-2024 Apple Inc.5//6// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.17//18//-------------------------------------------------------------------------------------------------------------------------------------------------------------1920#pragma once2122//-------------------------------------------------------------------------------------------------------------------------------------------------------------2324#include <objc/runtime.h>2526//-------------------------------------------------------------------------------------------------------------------------------------------------------------2728#define _NS_PRIVATE_CLS(symbol) (Private::Class::s_k##symbol)29#define _NS_PRIVATE_SEL(accessor) (Private::Selector::s_k##accessor)3031//-------------------------------------------------------------------------------------------------------------------------------------------------------------3233#if defined(NS_PRIVATE_IMPLEMENTATION)3435#include <dlfcn.h>3637namespace NS::Private38{39template <typename _Type>40inline _Type const LoadSymbol(const char* pSymbol)41{42const _Type* pAddress = static_cast<_Type*>(dlsym(RTLD_DEFAULT, pSymbol));4344return pAddress ? *pAddress : _Type();45}46} // NS::Private4748#ifdef METALCPP_SYMBOL_VISIBILITY_HIDDEN49#define _NS_PRIVATE_VISIBILITY __attribute__((visibility("hidden")))50#else51#define _NS_PRIVATE_VISIBILITY __attribute__((visibility("default")))52#endif // METALCPP_SYMBOL_VISIBILITY_HIDDEN5354#define _NS_PRIVATE_IMPORT __attribute__((weak_import))5556#ifdef __OBJC__57#define _NS_PRIVATE_OBJC_LOOKUP_CLASS(symbol) ((__bridge void*)objc_lookUpClass(#symbol))58#define _NS_PRIVATE_OBJC_GET_PROTOCOL(symbol) ((__bridge void*)objc_getProtocol(#symbol))59#else60#define _NS_PRIVATE_OBJC_LOOKUP_CLASS(symbol) objc_lookUpClass(#symbol)61#define _NS_PRIVATE_OBJC_GET_PROTOCOL(symbol) objc_getProtocol(#symbol)62#endif // __OBJC__6364#define _NS_PRIVATE_DEF_CLS(symbol) void* s_k##symbol _NS_PRIVATE_VISIBILITY = _NS_PRIVATE_OBJC_LOOKUP_CLASS(symbol)65#define _NS_PRIVATE_DEF_PRO(symbol) void* s_k##symbol _NS_PRIVATE_VISIBILITY = _NS_PRIVATE_OBJC_GET_PROTOCOL(symbol)66#define _NS_PRIVATE_DEF_SEL(accessor, symbol) SEL s_k##accessor _NS_PRIVATE_VISIBILITY = sel_registerName(symbol)6768#if defined(__MAC_26_0) || defined(__IPHONE_26_0) || defined(__TVOS_26_0)69#define _NS_PRIVATE_DEF_CONST(type, symbol) \70_NS_EXTERN type const NS##symbol _NS_PRIVATE_IMPORT; \71type const NS::symbol = (nullptr != &NS##symbol) ? NS##symbol : type()72#else73#define _NS_PRIVATE_DEF_CONST(type, symbol) \74_NS_EXTERN type const MTL##symbol _NS_PRIVATE_IMPORT; \75type const NS::symbol = Private::LoadSymbol<type>("NS" #symbol)76#endif7778#else7980#define _NS_PRIVATE_DEF_CLS(symbol) extern void* s_k##symbol81#define _NS_PRIVATE_DEF_PRO(symbol) extern void* s_k##symbol82#define _NS_PRIVATE_DEF_SEL(accessor, symbol) extern SEL s_k##accessor83#define _NS_PRIVATE_DEF_CONST(type, symbol) extern type const NS::symbol8485#endif // NS_PRIVATE_IMPLEMENTATION8687//-------------------------------------------------------------------------------------------------------------------------------------------------------------8889namespace NS90{91namespace Private92{93namespace Class94{9596_NS_PRIVATE_DEF_CLS(NSArray);97_NS_PRIVATE_DEF_CLS(NSAutoreleasePool);98_NS_PRIVATE_DEF_CLS(NSBundle);99_NS_PRIVATE_DEF_CLS(NSCondition);100_NS_PRIVATE_DEF_CLS(NSDate);101_NS_PRIVATE_DEF_CLS(NSDictionary);102_NS_PRIVATE_DEF_CLS(NSError);103_NS_PRIVATE_DEF_CLS(NSNotificationCenter);104_NS_PRIVATE_DEF_CLS(NSNumber);105_NS_PRIVATE_DEF_CLS(NSObject);106_NS_PRIVATE_DEF_CLS(NSProcessInfo);107_NS_PRIVATE_DEF_CLS(NSSet);108_NS_PRIVATE_DEF_CLS(NSString);109_NS_PRIVATE_DEF_CLS(NSURL);110_NS_PRIVATE_DEF_CLS(NSValue);111112} // Class113} // Private114} // MTL115116//-------------------------------------------------------------------------------------------------------------------------------------------------------------117118namespace NS119{120namespace Private121{122namespace Protocol123{124125} // Protocol126} // Private127} // NS128129//-------------------------------------------------------------------------------------------------------------------------------------------------------------130131namespace NS132{133namespace Private134{135namespace Selector136{137138_NS_PRIVATE_DEF_SEL(addObject_,139"addObject:");140_NS_PRIVATE_DEF_SEL(addObserverName_object_queue_block_,141"addObserverForName:object:queue:usingBlock:");142_NS_PRIVATE_DEF_SEL(activeProcessorCount,143"activeProcessorCount");144_NS_PRIVATE_DEF_SEL(allBundles,145"allBundles");146_NS_PRIVATE_DEF_SEL(allFrameworks,147"allFrameworks");148_NS_PRIVATE_DEF_SEL(allObjects,149"allObjects");150_NS_PRIVATE_DEF_SEL(alloc,151"alloc");152_NS_PRIVATE_DEF_SEL(appStoreReceiptURL,153"appStoreReceiptURL");154_NS_PRIVATE_DEF_SEL(arguments,155"arguments");156_NS_PRIVATE_DEF_SEL(array,157"array");158_NS_PRIVATE_DEF_SEL(arrayWithObject_,159"arrayWithObject:");160_NS_PRIVATE_DEF_SEL(arrayWithObjects_count_,161"arrayWithObjects:count:");162_NS_PRIVATE_DEF_SEL(automaticTerminationSupportEnabled,163"automaticTerminationSupportEnabled");164_NS_PRIVATE_DEF_SEL(autorelease,165"autorelease");166_NS_PRIVATE_DEF_SEL(beginActivityWithOptions_reason_,167"beginActivityWithOptions:reason:");168_NS_PRIVATE_DEF_SEL(boolValue,169"boolValue");170_NS_PRIVATE_DEF_SEL(broadcast,171"broadcast");172_NS_PRIVATE_DEF_SEL(builtInPlugInsPath,173"builtInPlugInsPath");174_NS_PRIVATE_DEF_SEL(builtInPlugInsURL,175"builtInPlugInsURL");176_NS_PRIVATE_DEF_SEL(bundleIdentifier,177"bundleIdentifier");178_NS_PRIVATE_DEF_SEL(bundlePath,179"bundlePath");180_NS_PRIVATE_DEF_SEL(bundleURL,181"bundleURL");182_NS_PRIVATE_DEF_SEL(bundleWithPath_,183"bundleWithPath:");184_NS_PRIVATE_DEF_SEL(bundleWithURL_,185"bundleWithURL:");186_NS_PRIVATE_DEF_SEL(caseInsensitiveCompare_,187"caseInsensitiveCompare:");188_NS_PRIVATE_DEF_SEL(characterAtIndex_,189"characterAtIndex:");190_NS_PRIVATE_DEF_SEL(charValue,191"charValue");192_NS_PRIVATE_DEF_SEL(countByEnumeratingWithState_objects_count_,193"countByEnumeratingWithState:objects:count:");194_NS_PRIVATE_DEF_SEL(cStringUsingEncoding_,195"cStringUsingEncoding:");196_NS_PRIVATE_DEF_SEL(code,197"code");198_NS_PRIVATE_DEF_SEL(compare_,199"compare:");200_NS_PRIVATE_DEF_SEL(copy,201"copy");202_NS_PRIVATE_DEF_SEL(count,203"count");204_NS_PRIVATE_DEF_SEL(dateWithTimeIntervalSinceNow_,205"dateWithTimeIntervalSinceNow:");206_NS_PRIVATE_DEF_SEL(defaultCenter,207"defaultCenter");208_NS_PRIVATE_DEF_SEL(descriptionWithLocale_,209"descriptionWithLocale:");210_NS_PRIVATE_DEF_SEL(disableAutomaticTermination_,211"disableAutomaticTermination:");212_NS_PRIVATE_DEF_SEL(disableSuddenTermination,213"disableSuddenTermination");214_NS_PRIVATE_DEF_SEL(debugDescription,215"debugDescription");216_NS_PRIVATE_DEF_SEL(description,217"description");218_NS_PRIVATE_DEF_SEL(dictionary,219"dictionary");220_NS_PRIVATE_DEF_SEL(dictionaryWithObject_forKey_,221"dictionaryWithObject:forKey:");222_NS_PRIVATE_DEF_SEL(dictionaryWithObjects_forKeys_count_,223"dictionaryWithObjects:forKeys:count:");224_NS_PRIVATE_DEF_SEL(domain,225"domain");226_NS_PRIVATE_DEF_SEL(doubleValue,227"doubleValue");228_NS_PRIVATE_DEF_SEL(drain,229"drain");230_NS_PRIVATE_DEF_SEL(enableAutomaticTermination_,231"enableAutomaticTermination:");232_NS_PRIVATE_DEF_SEL(enableSuddenTermination,233"enableSuddenTermination");234_NS_PRIVATE_DEF_SEL(endActivity_,235"endActivity:");236_NS_PRIVATE_DEF_SEL(environment,237"environment");238_NS_PRIVATE_DEF_SEL(errorWithDomain_code_userInfo_,239"errorWithDomain:code:userInfo:");240_NS_PRIVATE_DEF_SEL(executablePath,241"executablePath");242_NS_PRIVATE_DEF_SEL(executableURL,243"executableURL");244_NS_PRIVATE_DEF_SEL(fileSystemRepresentation,245"fileSystemRepresentation");246_NS_PRIVATE_DEF_SEL(fileURLWithPath_,247"fileURLWithPath:");248_NS_PRIVATE_DEF_SEL(floatValue,249"floatValue");250_NS_PRIVATE_DEF_SEL(fullUserName,251"fullUserName");252_NS_PRIVATE_DEF_SEL(getValue_size_,253"getValue:size:");254_NS_PRIVATE_DEF_SEL(globallyUniqueString,255"globallyUniqueString");256_NS_PRIVATE_DEF_SEL(hash,257"hash");258_NS_PRIVATE_DEF_SEL(hasPerformanceProfile_,259"hasPerformanceProfile:");260_NS_PRIVATE_DEF_SEL(hostName,261"hostName");262_NS_PRIVATE_DEF_SEL(infoDictionary,263"infoDictionary");264_NS_PRIVATE_DEF_SEL(init,265"init");266_NS_PRIVATE_DEF_SEL(initFileURLWithPath_,267"initFileURLWithPath:");268_NS_PRIVATE_DEF_SEL(initWithBool_,269"initWithBool:");270_NS_PRIVATE_DEF_SEL(initWithBytes_objCType_,271"initWithBytes:objCType:");272_NS_PRIVATE_DEF_SEL(initWithBytesNoCopy_length_encoding_freeWhenDone_,273"initWithBytesNoCopy:length:encoding:freeWhenDone:");274_NS_PRIVATE_DEF_SEL(initWithBytes_length_encoding_,275"initWithBytes:length:encoding:");276_NS_PRIVATE_DEF_SEL(initWithChar_,277"initWithChar:");278_NS_PRIVATE_DEF_SEL(initWithCoder_,279"initWithCoder:");280_NS_PRIVATE_DEF_SEL(initWithCString_encoding_,281"initWithCString:encoding:");282_NS_PRIVATE_DEF_SEL(initWithDomain_code_userInfo_,283"initWithDomain:code:userInfo:");284_NS_PRIVATE_DEF_SEL(initWithDouble_,285"initWithDouble:");286_NS_PRIVATE_DEF_SEL(initWithFloat_,287"initWithFloat:");288_NS_PRIVATE_DEF_SEL(initWithInt_,289"initWithInt:");290_NS_PRIVATE_DEF_SEL(initWithLong_,291"initWithLong:");292_NS_PRIVATE_DEF_SEL(initWithLongLong_,293"initWithLongLong:");294_NS_PRIVATE_DEF_SEL(initWithObjects_count_,295"initWithObjects:count:");296_NS_PRIVATE_DEF_SEL(initWithObjects_forKeys_count_,297"initWithObjects:forKeys:count:");298_NS_PRIVATE_DEF_SEL(initWithPath_,299"initWithPath:");300_NS_PRIVATE_DEF_SEL(initWithShort_,301"initWithShort:");302_NS_PRIVATE_DEF_SEL(initWithString_,303"initWithString:");304_NS_PRIVATE_DEF_SEL(initWithUnsignedChar_,305"initWithUnsignedChar:");306_NS_PRIVATE_DEF_SEL(initWithUnsignedInt_,307"initWithUnsignedInt:");308_NS_PRIVATE_DEF_SEL(initWithUnsignedLong_,309"initWithUnsignedLong:");310_NS_PRIVATE_DEF_SEL(initWithUnsignedLongLong_,311"initWithUnsignedLongLong:");312_NS_PRIVATE_DEF_SEL(initWithUnsignedShort_,313"initWithUnsignedShort:");314_NS_PRIVATE_DEF_SEL(initWithURL_,315"initWithURL:");316_NS_PRIVATE_DEF_SEL(integerValue,317"integerValue");318_NS_PRIVATE_DEF_SEL(intValue,319"intValue");320_NS_PRIVATE_DEF_SEL(isDeviceCertified_,321"isDeviceCertifiedFor:");322_NS_PRIVATE_DEF_SEL(isEqual_,323"isEqual:");324_NS_PRIVATE_DEF_SEL(isEqualToNumber_,325"isEqualToNumber:");326_NS_PRIVATE_DEF_SEL(isEqualToString_,327"isEqualToString:");328_NS_PRIVATE_DEF_SEL(isEqualToValue_,329"isEqualToValue:");330_NS_PRIVATE_DEF_SEL(isiOSAppOnMac,331"isiOSAppOnMac");332_NS_PRIVATE_DEF_SEL(isLoaded,333"isLoaded");334_NS_PRIVATE_DEF_SEL(isLowPowerModeEnabled,335"isLowPowerModeEnabled");336_NS_PRIVATE_DEF_SEL(isMacCatalystApp,337"isMacCatalystApp");338_NS_PRIVATE_DEF_SEL(isOperatingSystemAtLeastVersion_,339"isOperatingSystemAtLeastVersion:");340_NS_PRIVATE_DEF_SEL(keyEnumerator,341"keyEnumerator");342_NS_PRIVATE_DEF_SEL(length,343"length");344_NS_PRIVATE_DEF_SEL(lengthOfBytesUsingEncoding_,345"lengthOfBytesUsingEncoding:");346_NS_PRIVATE_DEF_SEL(load,347"load");348_NS_PRIVATE_DEF_SEL(loadAndReturnError_,349"loadAndReturnError:");350_NS_PRIVATE_DEF_SEL(localizedDescription,351"localizedDescription");352_NS_PRIVATE_DEF_SEL(localizedFailureReason,353"localizedFailureReason");354_NS_PRIVATE_DEF_SEL(localizedInfoDictionary,355"localizedInfoDictionary");356_NS_PRIVATE_DEF_SEL(localizedRecoveryOptions,357"localizedRecoveryOptions");358_NS_PRIVATE_DEF_SEL(localizedRecoverySuggestion,359"localizedRecoverySuggestion");360_NS_PRIVATE_DEF_SEL(localizedStringForKey_value_table_,361"localizedStringForKey:value:table:");362_NS_PRIVATE_DEF_SEL(lock,363"lock");364_NS_PRIVATE_DEF_SEL(longValue,365"longValue");366_NS_PRIVATE_DEF_SEL(longLongValue,367"longLongValue");368_NS_PRIVATE_DEF_SEL(mainBundle,369"mainBundle");370_NS_PRIVATE_DEF_SEL(maximumLengthOfBytesUsingEncoding_,371"maximumLengthOfBytesUsingEncoding:");372_NS_PRIVATE_DEF_SEL(methodSignatureForSelector_,373"methodSignatureForSelector:");374_NS_PRIVATE_DEF_SEL(mutableBytes,375"mutableBytes");376_NS_PRIVATE_DEF_SEL(bytes,377"bytes");378_NS_PRIVATE_DEF_SEL(name,379"name");380_NS_PRIVATE_DEF_SEL(nextObject,381"nextObject");382_NS_PRIVATE_DEF_SEL(numberWithBool_,383"numberWithBool:");384_NS_PRIVATE_DEF_SEL(numberWithChar_,385"numberWithChar:");386_NS_PRIVATE_DEF_SEL(numberWithDouble_,387"numberWithDouble:");388_NS_PRIVATE_DEF_SEL(numberWithFloat_,389"numberWithFloat:");390_NS_PRIVATE_DEF_SEL(numberWithInt_,391"numberWithInt:");392_NS_PRIVATE_DEF_SEL(numberWithLong_,393"numberWithLong:");394_NS_PRIVATE_DEF_SEL(numberWithLongLong_,395"numberWithLongLong:");396_NS_PRIVATE_DEF_SEL(numberWithShort_,397"numberWithShort:");398_NS_PRIVATE_DEF_SEL(numberWithUnsignedChar_,399"numberWithUnsignedChar:");400_NS_PRIVATE_DEF_SEL(numberWithUnsignedInt_,401"numberWithUnsignedInt:");402_NS_PRIVATE_DEF_SEL(numberWithUnsignedLong_,403"numberWithUnsignedLong:");404_NS_PRIVATE_DEF_SEL(numberWithUnsignedLongLong_,405"numberWithUnsignedLongLong:");406_NS_PRIVATE_DEF_SEL(numberWithUnsignedShort_,407"numberWithUnsignedShort:");408_NS_PRIVATE_DEF_SEL(objCType,409"objCType");410_NS_PRIVATE_DEF_SEL(object,411"object");412_NS_PRIVATE_DEF_SEL(objectAtIndex_,413"objectAtIndex:");414_NS_PRIVATE_DEF_SEL(objectEnumerator,415"objectEnumerator");416_NS_PRIVATE_DEF_SEL(objectForInfoDictionaryKey_,417"objectForInfoDictionaryKey:");418_NS_PRIVATE_DEF_SEL(objectForKey_,419"objectForKey:");420_NS_PRIVATE_DEF_SEL(operatingSystem,421"operatingSystem");422_NS_PRIVATE_DEF_SEL(operatingSystemVersion,423"operatingSystemVersion");424_NS_PRIVATE_DEF_SEL(operatingSystemVersionString,425"operatingSystemVersionString");426_NS_PRIVATE_DEF_SEL(pathForAuxiliaryExecutable_,427"pathForAuxiliaryExecutable:");428_NS_PRIVATE_DEF_SEL(performActivityWithOptions_reason_usingBlock_,429"performActivityWithOptions:reason:usingBlock:");430_NS_PRIVATE_DEF_SEL(performExpiringActivityWithReason_usingBlock_,431"performExpiringActivityWithReason:usingBlock:");432_NS_PRIVATE_DEF_SEL(physicalMemory,433"physicalMemory");434_NS_PRIVATE_DEF_SEL(pointerValue,435"pointerValue");436_NS_PRIVATE_DEF_SEL(preflightAndReturnError_,437"preflightAndReturnError:");438_NS_PRIVATE_DEF_SEL(privateFrameworksPath,439"privateFrameworksPath");440_NS_PRIVATE_DEF_SEL(privateFrameworksURL,441"privateFrameworksURL");442_NS_PRIVATE_DEF_SEL(processIdentifier,443"processIdentifier");444_NS_PRIVATE_DEF_SEL(processInfo,445"processInfo");446_NS_PRIVATE_DEF_SEL(processName,447"processName");448_NS_PRIVATE_DEF_SEL(processorCount,449"processorCount");450_NS_PRIVATE_DEF_SEL(rangeOfString_options_,451"rangeOfString:options:");452_NS_PRIVATE_DEF_SEL(release,453"release");454_NS_PRIVATE_DEF_SEL(removeObserver_,455"removeObserver:");456_NS_PRIVATE_DEF_SEL(resourcePath,457"resourcePath");458_NS_PRIVATE_DEF_SEL(resourceURL,459"resourceURL");460_NS_PRIVATE_DEF_SEL(respondsToSelector_,461"respondsToSelector:");462_NS_PRIVATE_DEF_SEL(retain,463"retain");464_NS_PRIVATE_DEF_SEL(retainCount,465"retainCount");466_NS_PRIVATE_DEF_SEL(setAutomaticTerminationSupportEnabled_,467"setAutomaticTerminationSupportEnabled:");468_NS_PRIVATE_DEF_SEL(setProcessName_,469"setProcessName:");470_NS_PRIVATE_DEF_SEL(sharedFrameworksPath,471"sharedFrameworksPath");472_NS_PRIVATE_DEF_SEL(sharedFrameworksURL,473"sharedFrameworksURL");474_NS_PRIVATE_DEF_SEL(sharedSupportPath,475"sharedSupportPath");476_NS_PRIVATE_DEF_SEL(sharedSupportURL,477"sharedSupportURL");478_NS_PRIVATE_DEF_SEL(shortValue,479"shortValue");480_NS_PRIVATE_DEF_SEL(showPools,481"showPools");482_NS_PRIVATE_DEF_SEL(signal,483"signal");484_NS_PRIVATE_DEF_SEL(string,485"string");486_NS_PRIVATE_DEF_SEL(stringValue,487"stringValue");488_NS_PRIVATE_DEF_SEL(stringWithString_,489"stringWithString:");490_NS_PRIVATE_DEF_SEL(stringWithCString_encoding_,491"stringWithCString:encoding:");492_NS_PRIVATE_DEF_SEL(stringByAppendingString_,493"stringByAppendingString:");494_NS_PRIVATE_DEF_SEL(systemUptime,495"systemUptime");496_NS_PRIVATE_DEF_SEL(thermalState,497"thermalState");498_NS_PRIVATE_DEF_SEL(unload,499"unload");500_NS_PRIVATE_DEF_SEL(unlock,501"unlock");502_NS_PRIVATE_DEF_SEL(unsignedCharValue,503"unsignedCharValue");504_NS_PRIVATE_DEF_SEL(unsignedIntegerValue,505"unsignedIntegerValue");506_NS_PRIVATE_DEF_SEL(unsignedIntValue,507"unsignedIntValue");508_NS_PRIVATE_DEF_SEL(unsignedLongValue,509"unsignedLongValue");510_NS_PRIVATE_DEF_SEL(unsignedLongLongValue,511"unsignedLongLongValue");512_NS_PRIVATE_DEF_SEL(unsignedShortValue,513"unsignedShortValue");514_NS_PRIVATE_DEF_SEL(URLForAuxiliaryExecutable_,515"URLForAuxiliaryExecutable:");516_NS_PRIVATE_DEF_SEL(userInfo,517"userInfo");518_NS_PRIVATE_DEF_SEL(userName,519"userName");520_NS_PRIVATE_DEF_SEL(UTF8String,521"UTF8String");522_NS_PRIVATE_DEF_SEL(valueWithBytes_objCType_,523"valueWithBytes:objCType:");524_NS_PRIVATE_DEF_SEL(valueWithPointer_,525"valueWithPointer:");526_NS_PRIVATE_DEF_SEL(wait,527"wait");528_NS_PRIVATE_DEF_SEL(waitUntilDate_,529"waitUntilDate:");530} // Class531} // Private532} // MTL533534//-------------------------------------------------------------------------------------------------------------------------------------------------------------535536537