spb/forge Public MIT
Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.
C++ 61.2%
C 23%
Python 7.6%
TeX 7.2%
CMake 1.1%
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Foundation/NSBundle.hpp4//5// Copyright 2020-2024 Apple Inc.6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11// http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223//-------------------------------------------------------------------------------------------------------------------------------------------------------------2425#include "NSDefines.hpp"26#include "NSNotification.hpp"27#include "NSObject.hpp"28#include "NSTypes.hpp"2930//-------------------------------------------------------------------------------------------------------------------------------------------------------------3132namespace NS33{34_NS_CONST(NotificationName, BundleDidLoadNotification);35_NS_CONST(NotificationName, BundleResourceRequestLowDiskSpaceNotification);3637class String* LocalizedString(const String* pKey, const String*);38class String* LocalizedStringFromTable(const String* pKey, const String* pTbl, const String*);39class String* LocalizedStringFromTableInBundle(const String* pKey, const String* pTbl, const class Bundle* pBdle, const String*);40class String* LocalizedStringWithDefaultValue(const String* pKey, const String* pTbl, const class Bundle* pBdle, const String* pVal, const String*);4142class Bundle : public Referencing<Bundle>43{44public:45 static Bundle* mainBundle();4647 static Bundle* bundle(const class String* pPath);48 static Bundle* bundle(const class URL* pURL);4950 static class Array* allBundles();51 static class Array* allFrameworks();5253 static Bundle* alloc();5455 Bundle* init(const class String* pPath);56 Bundle* init(const class URL* pURL);5758 bool load();59 bool unload();6061 bool isLoaded() const;6263 bool preflightAndReturnError(class Error** pError) const;64 bool loadAndReturnError(class Error** pError);6566 class URL* bundleURL() const;67 class URL* resourceURL() const;68 class URL* executableURL() const;69 class URL* URLForAuxiliaryExecutable(const class String* pExecutableName) const;7071 class URL* privateFrameworksURL() const;72 class URL* sharedFrameworksURL() const;73 class URL* sharedSupportURL() const;74 class URL* builtInPlugInsURL() const;75 class URL* appStoreReceiptURL() const;7677 class String* bundlePath() const;78 class String* resourcePath() const;79 class String* executablePath() const;80 class String* pathForAuxiliaryExecutable(const class String* pExecutableName) const;8182 class String* privateFrameworksPath() const;83 class String* sharedFrameworksPath() const;84 class String* sharedSupportPath() const;85 class String* builtInPlugInsPath() const;8687 class String* bundleIdentifier() const;88 class Dictionary* infoDictionary() const;89 class Dictionary* localizedInfoDictionary() const;90 class Object* objectForInfoDictionaryKey(const class String* pKey);9192 class String* localizedString(const class String* pKey, const class String* pValue = nullptr, const class String* pTableName = nullptr) const;93};94}9596//-------------------------------------------------------------------------------------------------------------------------------------------------------------9798_NS_PRIVATE_DEF_CONST(NS::NotificationName, BundleDidLoadNotification);99_NS_PRIVATE_DEF_CONST(NS::NotificationName, BundleResourceRequestLowDiskSpaceNotification);100101//-------------------------------------------------------------------------------------------------------------------------------------------------------------102103_NS_INLINE NS::String* NS::LocalizedString(const String* pKey, const String*)104{105 return Bundle::mainBundle()->localizedString(pKey, nullptr, nullptr);106}107108//-------------------------------------------------------------------------------------------------------------------------------------------------------------109110_NS_INLINE NS::String* NS::LocalizedStringFromTable(const String* pKey, const String* pTbl, const String*)111{112 return Bundle::mainBundle()->localizedString(pKey, nullptr, pTbl);113}114115//-------------------------------------------------------------------------------------------------------------------------------------------------------------116117_NS_INLINE NS::String* NS::LocalizedStringFromTableInBundle(const String* pKey, const String* pTbl, const Bundle* pBdl, const String*)118{119 return pBdl->localizedString(pKey, nullptr, pTbl);120}121122//-------------------------------------------------------------------------------------------------------------------------------------------------------------123124_NS_INLINE NS::String* NS::LocalizedStringWithDefaultValue(const String* pKey, const String* pTbl, const Bundle* pBdl, const String* pVal, const String*)125{126 return pBdl->localizedString(pKey, pVal, pTbl);127}128129//-------------------------------------------------------------------------------------------------------------------------------------------------------------130131_NS_INLINE NS::Bundle* NS::Bundle::mainBundle()132{133 return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(mainBundle));134}135136//-------------------------------------------------------------------------------------------------------------------------------------------------------------137138_NS_INLINE NS::Bundle* NS::Bundle::bundle(const class String* pPath)139{140 return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(bundleWithPath_), pPath);141}142143//-------------------------------------------------------------------------------------------------------------------------------------------------------------144145_NS_INLINE NS::Bundle* NS::Bundle::bundle(const class URL* pURL)146{147 return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(bundleWithURL_), pURL);148}149150//-------------------------------------------------------------------------------------------------------------------------------------------------------------151152_NS_INLINE NS::Array* NS::Bundle::allBundles()153{154 return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(allBundles));155}156157//-------------------------------------------------------------------------------------------------------------------------------------------------------------158159_NS_INLINE NS::Array* NS::Bundle::allFrameworks()160{161 return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(allFrameworks));162}163164//-------------------------------------------------------------------------------------------------------------------------------------------------------------165166_NS_INLINE NS::Bundle* NS::Bundle::alloc()167{168 return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(alloc));169}170171//-------------------------------------------------------------------------------------------------------------------------------------------------------------172173_NS_INLINE NS::Bundle* NS::Bundle::init(const String* pPath)174{175 return Object::sendMessage<Bundle*>(this, _NS_PRIVATE_SEL(initWithPath_), pPath);176}177178//-------------------------------------------------------------------------------------------------------------------------------------------------------------179180_NS_INLINE NS::Bundle* NS::Bundle::init(const URL* pURL)181{182 return Object::sendMessage<Bundle*>(this, _NS_PRIVATE_SEL(initWithURL_), pURL);183}184185//-------------------------------------------------------------------------------------------------------------------------------------------------------------186187_NS_INLINE bool NS::Bundle::load()188{189 return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(load));190}191192//-------------------------------------------------------------------------------------------------------------------------------------------------------------193194_NS_INLINE bool NS::Bundle::unload()195{196 return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(unload));197}198199//-------------------------------------------------------------------------------------------------------------------------------------------------------------200201_NS_INLINE bool NS::Bundle::isLoaded() const202{203 return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(isLoaded));204}205206//-------------------------------------------------------------------------------------------------------------------------------------------------------------207208_NS_INLINE bool NS::Bundle::preflightAndReturnError(Error** pError) const209{210 return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(preflightAndReturnError_), pError);211}212213//-------------------------------------------------------------------------------------------------------------------------------------------------------------214215_NS_INLINE bool NS::Bundle::loadAndReturnError(Error** pError)216{217 return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(loadAndReturnError_), pError);218}219220//-------------------------------------------------------------------------------------------------------------------------------------------------------------221222_NS_INLINE NS::URL* NS::Bundle::bundleURL() const223{224 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(bundleURL));225}226227//-------------------------------------------------------------------------------------------------------------------------------------------------------------228229_NS_INLINE NS::URL* NS::Bundle::resourceURL() const230{231 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(resourceURL));232}233234//-------------------------------------------------------------------------------------------------------------------------------------------------------------235236_NS_INLINE NS::URL* NS::Bundle::executableURL() const237{238 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(executableURL));239}240241//-------------------------------------------------------------------------------------------------------------------------------------------------------------242243_NS_INLINE NS::URL* NS::Bundle::URLForAuxiliaryExecutable(const String* pExecutableName) const244{245 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(URLForAuxiliaryExecutable_), pExecutableName);246}247248//-------------------------------------------------------------------------------------------------------------------------------------------------------------249250_NS_INLINE NS::URL* NS::Bundle::privateFrameworksURL() const251{252 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(privateFrameworksURL));253}254255//-------------------------------------------------------------------------------------------------------------------------------------------------------------256257_NS_INLINE NS::URL* NS::Bundle::sharedFrameworksURL() const258{259 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(sharedFrameworksURL));260}261262//-------------------------------------------------------------------------------------------------------------------------------------------------------------263264_NS_INLINE NS::URL* NS::Bundle::sharedSupportURL() const265{266 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(sharedSupportURL));267}268269//-------------------------------------------------------------------------------------------------------------------------------------------------------------270271_NS_INLINE NS::URL* NS::Bundle::builtInPlugInsURL() const272{273 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(builtInPlugInsURL));274}275276//-------------------------------------------------------------------------------------------------------------------------------------------------------------277278_NS_INLINE NS::URL* NS::Bundle::appStoreReceiptURL() const279{280 return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(appStoreReceiptURL));281}282283//-------------------------------------------------------------------------------------------------------------------------------------------------------------284285_NS_INLINE NS::String* NS::Bundle::bundlePath() const286{287 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(bundlePath));288}289290//-------------------------------------------------------------------------------------------------------------------------------------------------------------291292_NS_INLINE NS::String* NS::Bundle::resourcePath() const293{294 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(resourcePath));295}296297//-------------------------------------------------------------------------------------------------------------------------------------------------------------298299_NS_INLINE NS::String* NS::Bundle::executablePath() const300{301 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(executablePath));302}303304//-------------------------------------------------------------------------------------------------------------------------------------------------------------305306_NS_INLINE NS::String* NS::Bundle::pathForAuxiliaryExecutable(const String* pExecutableName) const307{308 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(pathForAuxiliaryExecutable_), pExecutableName);309}310311//-------------------------------------------------------------------------------------------------------------------------------------------------------------312313_NS_INLINE NS::String* NS::Bundle::privateFrameworksPath() const314{315 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(privateFrameworksPath));316}317318//-------------------------------------------------------------------------------------------------------------------------------------------------------------319320_NS_INLINE NS::String* NS::Bundle::sharedFrameworksPath() const321{322 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(sharedFrameworksPath));323}324325//-------------------------------------------------------------------------------------------------------------------------------------------------------------326327_NS_INLINE NS::String* NS::Bundle::sharedSupportPath() const328{329 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(sharedSupportPath));330}331332//-------------------------------------------------------------------------------------------------------------------------------------------------------------333334_NS_INLINE NS::String* NS::Bundle::builtInPlugInsPath() const335{336 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(builtInPlugInsPath));337}338339//-------------------------------------------------------------------------------------------------------------------------------------------------------------340341_NS_INLINE NS::String* NS::Bundle::bundleIdentifier() const342{343 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(bundleIdentifier));344}345346//-------------------------------------------------------------------------------------------------------------------------------------------------------------347348_NS_INLINE NS::Dictionary* NS::Bundle::infoDictionary() const349{350 return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(infoDictionary));351}352353//-------------------------------------------------------------------------------------------------------------------------------------------------------------354355_NS_INLINE NS::Dictionary* NS::Bundle::localizedInfoDictionary() const356{357 return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(localizedInfoDictionary));358}359360//-------------------------------------------------------------------------------------------------------------------------------------------------------------361362_NS_INLINE NS::Object* NS::Bundle::objectForInfoDictionaryKey(const String* pKey)363{364 return Object::sendMessage<Object*>(this, _NS_PRIVATE_SEL(objectForInfoDictionaryKey_), pKey);365}366367//-------------------------------------------------------------------------------------------------------------------------------------------------------------368369_NS_INLINE NS::String* NS::Bundle::localizedString(const String* pKey, const String* pValue /* = nullptr */, const String* pTableName /* = nullptr */) const370{371 return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(localizedStringForKey_value_table_), pKey, pValue, pTableName);372}373374//-------------------------------------------------------------------------------------------------------------------------------------------------------------375