Path: blob/master/thirdparty/metal-cpp/Foundation/NSBundle.hpp
21066 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Foundation/NSBundle.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 "NSDefines.hpp"25#include "NSNotification.hpp"26#include "NSObject.hpp"27#include "NSTypes.hpp"2829//-------------------------------------------------------------------------------------------------------------------------------------------------------------3031namespace NS32{33_NS_CONST(NotificationName, BundleDidLoadNotification);34_NS_CONST(NotificationName, BundleResourceRequestLowDiskSpaceNotification);3536class String* LocalizedString(const String* pKey, const String*);37class String* LocalizedStringFromTable(const String* pKey, const String* pTbl, const String*);38class String* LocalizedStringFromTableInBundle(const String* pKey, const String* pTbl, const class Bundle* pBdle, const String*);39class String* LocalizedStringWithDefaultValue(const String* pKey, const String* pTbl, const class Bundle* pBdle, const String* pVal, const String*);4041class Bundle : public Referencing<Bundle>42{43public:44static Bundle* mainBundle();4546static Bundle* bundle(const class String* pPath);47static Bundle* bundle(const class URL* pURL);4849static class Array* allBundles();50static class Array* allFrameworks();5152static Bundle* alloc();5354Bundle* init(const class String* pPath);55Bundle* init(const class URL* pURL);5657bool load();58bool unload();5960bool isLoaded() const;6162bool preflightAndReturnError(class Error** pError) const;63bool loadAndReturnError(class Error** pError);6465class URL* bundleURL() const;66class URL* resourceURL() const;67class URL* executableURL() const;68class URL* URLForAuxiliaryExecutable(const class String* pExecutableName) const;6970class URL* privateFrameworksURL() const;71class URL* sharedFrameworksURL() const;72class URL* sharedSupportURL() const;73class URL* builtInPlugInsURL() const;74class URL* appStoreReceiptURL() const;7576class String* bundlePath() const;77class String* resourcePath() const;78class String* executablePath() const;79class String* pathForAuxiliaryExecutable(const class String* pExecutableName) const;8081class String* privateFrameworksPath() const;82class String* sharedFrameworksPath() const;83class String* sharedSupportPath() const;84class String* builtInPlugInsPath() const;8586class String* bundleIdentifier() const;87class Dictionary* infoDictionary() const;88class Dictionary* localizedInfoDictionary() const;89class Object* objectForInfoDictionaryKey(const class String* pKey);9091class String* localizedString(const class String* pKey, const class String* pValue = nullptr, const class String* pTableName = nullptr) const;92};93}9495//-------------------------------------------------------------------------------------------------------------------------------------------------------------9697_NS_PRIVATE_DEF_CONST(NS::NotificationName, BundleDidLoadNotification);98_NS_PRIVATE_DEF_CONST(NS::NotificationName, BundleResourceRequestLowDiskSpaceNotification);99100//-------------------------------------------------------------------------------------------------------------------------------------------------------------101102_NS_INLINE NS::String* NS::LocalizedString(const String* pKey, const String*)103{104return Bundle::mainBundle()->localizedString(pKey, nullptr, nullptr);105}106107//-------------------------------------------------------------------------------------------------------------------------------------------------------------108109_NS_INLINE NS::String* NS::LocalizedStringFromTable(const String* pKey, const String* pTbl, const String*)110{111return Bundle::mainBundle()->localizedString(pKey, nullptr, pTbl);112}113114//-------------------------------------------------------------------------------------------------------------------------------------------------------------115116_NS_INLINE NS::String* NS::LocalizedStringFromTableInBundle(const String* pKey, const String* pTbl, const Bundle* pBdl, const String*)117{118return pBdl->localizedString(pKey, nullptr, pTbl);119}120121//-------------------------------------------------------------------------------------------------------------------------------------------------------------122123_NS_INLINE NS::String* NS::LocalizedStringWithDefaultValue(const String* pKey, const String* pTbl, const Bundle* pBdl, const String* pVal, const String*)124{125return pBdl->localizedString(pKey, pVal, pTbl);126}127128//-------------------------------------------------------------------------------------------------------------------------------------------------------------129130_NS_INLINE NS::Bundle* NS::Bundle::mainBundle()131{132return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(mainBundle));133}134135//-------------------------------------------------------------------------------------------------------------------------------------------------------------136137_NS_INLINE NS::Bundle* NS::Bundle::bundle(const class String* pPath)138{139return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(bundleWithPath_), pPath);140}141142//-------------------------------------------------------------------------------------------------------------------------------------------------------------143144_NS_INLINE NS::Bundle* NS::Bundle::bundle(const class URL* pURL)145{146return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(bundleWithURL_), pURL);147}148149//-------------------------------------------------------------------------------------------------------------------------------------------------------------150151_NS_INLINE NS::Array* NS::Bundle::allBundles()152{153return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(allBundles));154}155156//-------------------------------------------------------------------------------------------------------------------------------------------------------------157158_NS_INLINE NS::Array* NS::Bundle::allFrameworks()159{160return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(allFrameworks));161}162163//-------------------------------------------------------------------------------------------------------------------------------------------------------------164165_NS_INLINE NS::Bundle* NS::Bundle::alloc()166{167return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(alloc));168}169170//-------------------------------------------------------------------------------------------------------------------------------------------------------------171172_NS_INLINE NS::Bundle* NS::Bundle::init(const String* pPath)173{174return Object::sendMessage<Bundle*>(this, _NS_PRIVATE_SEL(initWithPath_), pPath);175}176177//-------------------------------------------------------------------------------------------------------------------------------------------------------------178179_NS_INLINE NS::Bundle* NS::Bundle::init(const URL* pURL)180{181return Object::sendMessage<Bundle*>(this, _NS_PRIVATE_SEL(initWithURL_), pURL);182}183184//-------------------------------------------------------------------------------------------------------------------------------------------------------------185186_NS_INLINE bool NS::Bundle::load()187{188return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(load));189}190191//-------------------------------------------------------------------------------------------------------------------------------------------------------------192193_NS_INLINE bool NS::Bundle::unload()194{195return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(unload));196}197198//-------------------------------------------------------------------------------------------------------------------------------------------------------------199200_NS_INLINE bool NS::Bundle::isLoaded() const201{202return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(isLoaded));203}204205//-------------------------------------------------------------------------------------------------------------------------------------------------------------206207_NS_INLINE bool NS::Bundle::preflightAndReturnError(Error** pError) const208{209return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(preflightAndReturnError_), pError);210}211212//-------------------------------------------------------------------------------------------------------------------------------------------------------------213214_NS_INLINE bool NS::Bundle::loadAndReturnError(Error** pError)215{216return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(loadAndReturnError_), pError);217}218219//-------------------------------------------------------------------------------------------------------------------------------------------------------------220221_NS_INLINE NS::URL* NS::Bundle::bundleURL() const222{223return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(bundleURL));224}225226//-------------------------------------------------------------------------------------------------------------------------------------------------------------227228_NS_INLINE NS::URL* NS::Bundle::resourceURL() const229{230return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(resourceURL));231}232233//-------------------------------------------------------------------------------------------------------------------------------------------------------------234235_NS_INLINE NS::URL* NS::Bundle::executableURL() const236{237return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(executableURL));238}239240//-------------------------------------------------------------------------------------------------------------------------------------------------------------241242_NS_INLINE NS::URL* NS::Bundle::URLForAuxiliaryExecutable(const String* pExecutableName) const243{244return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(URLForAuxiliaryExecutable_), pExecutableName);245}246247//-------------------------------------------------------------------------------------------------------------------------------------------------------------248249_NS_INLINE NS::URL* NS::Bundle::privateFrameworksURL() const250{251return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(privateFrameworksURL));252}253254//-------------------------------------------------------------------------------------------------------------------------------------------------------------255256_NS_INLINE NS::URL* NS::Bundle::sharedFrameworksURL() const257{258return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(sharedFrameworksURL));259}260261//-------------------------------------------------------------------------------------------------------------------------------------------------------------262263_NS_INLINE NS::URL* NS::Bundle::sharedSupportURL() const264{265return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(sharedSupportURL));266}267268//-------------------------------------------------------------------------------------------------------------------------------------------------------------269270_NS_INLINE NS::URL* NS::Bundle::builtInPlugInsURL() const271{272return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(builtInPlugInsURL));273}274275//-------------------------------------------------------------------------------------------------------------------------------------------------------------276277_NS_INLINE NS::URL* NS::Bundle::appStoreReceiptURL() const278{279return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(appStoreReceiptURL));280}281282//-------------------------------------------------------------------------------------------------------------------------------------------------------------283284_NS_INLINE NS::String* NS::Bundle::bundlePath() const285{286return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(bundlePath));287}288289//-------------------------------------------------------------------------------------------------------------------------------------------------------------290291_NS_INLINE NS::String* NS::Bundle::resourcePath() const292{293return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(resourcePath));294}295296//-------------------------------------------------------------------------------------------------------------------------------------------------------------297298_NS_INLINE NS::String* NS::Bundle::executablePath() const299{300return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(executablePath));301}302303//-------------------------------------------------------------------------------------------------------------------------------------------------------------304305_NS_INLINE NS::String* NS::Bundle::pathForAuxiliaryExecutable(const String* pExecutableName) const306{307return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(pathForAuxiliaryExecutable_), pExecutableName);308}309310//-------------------------------------------------------------------------------------------------------------------------------------------------------------311312_NS_INLINE NS::String* NS::Bundle::privateFrameworksPath() const313{314return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(privateFrameworksPath));315}316317//-------------------------------------------------------------------------------------------------------------------------------------------------------------318319_NS_INLINE NS::String* NS::Bundle::sharedFrameworksPath() const320{321return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(sharedFrameworksPath));322}323324//-------------------------------------------------------------------------------------------------------------------------------------------------------------325326_NS_INLINE NS::String* NS::Bundle::sharedSupportPath() const327{328return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(sharedSupportPath));329}330331//-------------------------------------------------------------------------------------------------------------------------------------------------------------332333_NS_INLINE NS::String* NS::Bundle::builtInPlugInsPath() const334{335return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(builtInPlugInsPath));336}337338//-------------------------------------------------------------------------------------------------------------------------------------------------------------339340_NS_INLINE NS::String* NS::Bundle::bundleIdentifier() const341{342return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(bundleIdentifier));343}344345//-------------------------------------------------------------------------------------------------------------------------------------------------------------346347_NS_INLINE NS::Dictionary* NS::Bundle::infoDictionary() const348{349return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(infoDictionary));350}351352//-------------------------------------------------------------------------------------------------------------------------------------------------------------353354_NS_INLINE NS::Dictionary* NS::Bundle::localizedInfoDictionary() const355{356return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(localizedInfoDictionary));357}358359//-------------------------------------------------------------------------------------------------------------------------------------------------------------360361_NS_INLINE NS::Object* NS::Bundle::objectForInfoDictionaryKey(const String* pKey)362{363return Object::sendMessage<Object*>(this, _NS_PRIVATE_SEL(objectForInfoDictionaryKey_), pKey);364}365366//-------------------------------------------------------------------------------------------------------------------------------------------------------------367368_NS_INLINE NS::String* NS::Bundle::localizedString(const String* pKey, const String* pValue /* = nullptr */, const String* pTableName /* = nullptr */) const369{370return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(localizedStringForKey_value_table_), pKey, pValue, pTableName);371}372373//-------------------------------------------------------------------------------------------------------------------------------------------------------------374375376