Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/metal-cpp/Foundation/NSBundle.hpp
21066 views
1
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
2
//
3
// Foundation/NSBundle.hpp
4
//
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 at
10
//
11
// http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// 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 and
17
// limitations under the License.
18
//
19
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
20
21
#pragma once
22
23
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
24
25
#include "NSDefines.hpp"
26
#include "NSNotification.hpp"
27
#include "NSObject.hpp"
28
#include "NSTypes.hpp"
29
30
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
31
32
namespace NS
33
{
34
_NS_CONST(NotificationName, BundleDidLoadNotification);
35
_NS_CONST(NotificationName, BundleResourceRequestLowDiskSpaceNotification);
36
37
class String* LocalizedString(const String* pKey, const String*);
38
class String* LocalizedStringFromTable(const String* pKey, const String* pTbl, const String*);
39
class String* LocalizedStringFromTableInBundle(const String* pKey, const String* pTbl, const class Bundle* pBdle, const String*);
40
class String* LocalizedStringWithDefaultValue(const String* pKey, const String* pTbl, const class Bundle* pBdle, const String* pVal, const String*);
41
42
class Bundle : public Referencing<Bundle>
43
{
44
public:
45
static Bundle* mainBundle();
46
47
static Bundle* bundle(const class String* pPath);
48
static Bundle* bundle(const class URL* pURL);
49
50
static class Array* allBundles();
51
static class Array* allFrameworks();
52
53
static Bundle* alloc();
54
55
Bundle* init(const class String* pPath);
56
Bundle* init(const class URL* pURL);
57
58
bool load();
59
bool unload();
60
61
bool isLoaded() const;
62
63
bool preflightAndReturnError(class Error** pError) const;
64
bool loadAndReturnError(class Error** pError);
65
66
class URL* bundleURL() const;
67
class URL* resourceURL() const;
68
class URL* executableURL() const;
69
class URL* URLForAuxiliaryExecutable(const class String* pExecutableName) const;
70
71
class URL* privateFrameworksURL() const;
72
class URL* sharedFrameworksURL() const;
73
class URL* sharedSupportURL() const;
74
class URL* builtInPlugInsURL() const;
75
class URL* appStoreReceiptURL() const;
76
77
class String* bundlePath() const;
78
class String* resourcePath() const;
79
class String* executablePath() const;
80
class String* pathForAuxiliaryExecutable(const class String* pExecutableName) const;
81
82
class String* privateFrameworksPath() const;
83
class String* sharedFrameworksPath() const;
84
class String* sharedSupportPath() const;
85
class String* builtInPlugInsPath() const;
86
87
class String* bundleIdentifier() const;
88
class Dictionary* infoDictionary() const;
89
class Dictionary* localizedInfoDictionary() const;
90
class Object* objectForInfoDictionaryKey(const class String* pKey);
91
92
class String* localizedString(const class String* pKey, const class String* pValue = nullptr, const class String* pTableName = nullptr) const;
93
};
94
}
95
96
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
97
98
_NS_PRIVATE_DEF_CONST(NS::NotificationName, BundleDidLoadNotification);
99
_NS_PRIVATE_DEF_CONST(NS::NotificationName, BundleResourceRequestLowDiskSpaceNotification);
100
101
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
102
103
_NS_INLINE NS::String* NS::LocalizedString(const String* pKey, const String*)
104
{
105
return Bundle::mainBundle()->localizedString(pKey, nullptr, nullptr);
106
}
107
108
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
109
110
_NS_INLINE NS::String* NS::LocalizedStringFromTable(const String* pKey, const String* pTbl, const String*)
111
{
112
return Bundle::mainBundle()->localizedString(pKey, nullptr, pTbl);
113
}
114
115
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
116
117
_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
}
121
122
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
123
124
_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
}
128
129
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
130
131
_NS_INLINE NS::Bundle* NS::Bundle::mainBundle()
132
{
133
return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(mainBundle));
134
}
135
136
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
137
138
_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
}
142
143
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
144
145
_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
}
149
150
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
151
152
_NS_INLINE NS::Array* NS::Bundle::allBundles()
153
{
154
return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(allBundles));
155
}
156
157
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
158
159
_NS_INLINE NS::Array* NS::Bundle::allFrameworks()
160
{
161
return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(allFrameworks));
162
}
163
164
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
165
166
_NS_INLINE NS::Bundle* NS::Bundle::alloc()
167
{
168
return Object::sendMessage<Bundle*>(_NS_PRIVATE_CLS(NSBundle), _NS_PRIVATE_SEL(alloc));
169
}
170
171
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
172
173
_NS_INLINE NS::Bundle* NS::Bundle::init(const String* pPath)
174
{
175
return Object::sendMessage<Bundle*>(this, _NS_PRIVATE_SEL(initWithPath_), pPath);
176
}
177
178
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
179
180
_NS_INLINE NS::Bundle* NS::Bundle::init(const URL* pURL)
181
{
182
return Object::sendMessage<Bundle*>(this, _NS_PRIVATE_SEL(initWithURL_), pURL);
183
}
184
185
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
186
187
_NS_INLINE bool NS::Bundle::load()
188
{
189
return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(load));
190
}
191
192
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
193
194
_NS_INLINE bool NS::Bundle::unload()
195
{
196
return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(unload));
197
}
198
199
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
200
201
_NS_INLINE bool NS::Bundle::isLoaded() const
202
{
203
return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(isLoaded));
204
}
205
206
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
207
208
_NS_INLINE bool NS::Bundle::preflightAndReturnError(Error** pError) const
209
{
210
return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(preflightAndReturnError_), pError);
211
}
212
213
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
214
215
_NS_INLINE bool NS::Bundle::loadAndReturnError(Error** pError)
216
{
217
return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(loadAndReturnError_), pError);
218
}
219
220
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
221
222
_NS_INLINE NS::URL* NS::Bundle::bundleURL() const
223
{
224
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(bundleURL));
225
}
226
227
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
228
229
_NS_INLINE NS::URL* NS::Bundle::resourceURL() const
230
{
231
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(resourceURL));
232
}
233
234
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
235
236
_NS_INLINE NS::URL* NS::Bundle::executableURL() const
237
{
238
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(executableURL));
239
}
240
241
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
242
243
_NS_INLINE NS::URL* NS::Bundle::URLForAuxiliaryExecutable(const String* pExecutableName) const
244
{
245
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(URLForAuxiliaryExecutable_), pExecutableName);
246
}
247
248
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
249
250
_NS_INLINE NS::URL* NS::Bundle::privateFrameworksURL() const
251
{
252
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(privateFrameworksURL));
253
}
254
255
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
256
257
_NS_INLINE NS::URL* NS::Bundle::sharedFrameworksURL() const
258
{
259
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(sharedFrameworksURL));
260
}
261
262
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
263
264
_NS_INLINE NS::URL* NS::Bundle::sharedSupportURL() const
265
{
266
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(sharedSupportURL));
267
}
268
269
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
270
271
_NS_INLINE NS::URL* NS::Bundle::builtInPlugInsURL() const
272
{
273
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(builtInPlugInsURL));
274
}
275
276
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
277
278
_NS_INLINE NS::URL* NS::Bundle::appStoreReceiptURL() const
279
{
280
return Object::sendMessage<URL*>(this, _NS_PRIVATE_SEL(appStoreReceiptURL));
281
}
282
283
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
284
285
_NS_INLINE NS::String* NS::Bundle::bundlePath() const
286
{
287
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(bundlePath));
288
}
289
290
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
291
292
_NS_INLINE NS::String* NS::Bundle::resourcePath() const
293
{
294
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(resourcePath));
295
}
296
297
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
298
299
_NS_INLINE NS::String* NS::Bundle::executablePath() const
300
{
301
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(executablePath));
302
}
303
304
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
305
306
_NS_INLINE NS::String* NS::Bundle::pathForAuxiliaryExecutable(const String* pExecutableName) const
307
{
308
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(pathForAuxiliaryExecutable_), pExecutableName);
309
}
310
311
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
312
313
_NS_INLINE NS::String* NS::Bundle::privateFrameworksPath() const
314
{
315
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(privateFrameworksPath));
316
}
317
318
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
319
320
_NS_INLINE NS::String* NS::Bundle::sharedFrameworksPath() const
321
{
322
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(sharedFrameworksPath));
323
}
324
325
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
326
327
_NS_INLINE NS::String* NS::Bundle::sharedSupportPath() const
328
{
329
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(sharedSupportPath));
330
}
331
332
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
333
334
_NS_INLINE NS::String* NS::Bundle::builtInPlugInsPath() const
335
{
336
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(builtInPlugInsPath));
337
}
338
339
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
340
341
_NS_INLINE NS::String* NS::Bundle::bundleIdentifier() const
342
{
343
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(bundleIdentifier));
344
}
345
346
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
347
348
_NS_INLINE NS::Dictionary* NS::Bundle::infoDictionary() const
349
{
350
return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(infoDictionary));
351
}
352
353
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
354
355
_NS_INLINE NS::Dictionary* NS::Bundle::localizedInfoDictionary() const
356
{
357
return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(localizedInfoDictionary));
358
}
359
360
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
361
362
_NS_INLINE NS::Object* NS::Bundle::objectForInfoDictionaryKey(const String* pKey)
363
{
364
return Object::sendMessage<Object*>(this, _NS_PRIVATE_SEL(objectForInfoDictionaryKey_), pKey);
365
}
366
367
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
368
369
_NS_INLINE NS::String* NS::Bundle::localizedString(const String* pKey, const String* pValue /* = nullptr */, const String* pTableName /* = nullptr */) const
370
{
371
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(localizedStringForKey_value_table_), pKey, pValue, pTableName);
372
}
373
374
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
375
376