Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/metal-cpp/Foundation/NSError.hpp
21117 views
1
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
2
//
3
// Foundation/NSError.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 "NSObject.hpp"
27
#include "NSPrivate.hpp"
28
#include "NSTypes.hpp"
29
30
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
31
32
namespace NS
33
{
34
using ErrorDomain = class String*;
35
36
_NS_CONST(ErrorDomain, CocoaErrorDomain);
37
_NS_CONST(ErrorDomain, POSIXErrorDomain);
38
_NS_CONST(ErrorDomain, OSStatusErrorDomain);
39
_NS_CONST(ErrorDomain, MachErrorDomain);
40
41
using ErrorUserInfoKey = class String*;
42
43
_NS_CONST(ErrorUserInfoKey, UnderlyingErrorKey);
44
_NS_CONST(ErrorUserInfoKey, LocalizedDescriptionKey);
45
_NS_CONST(ErrorUserInfoKey, LocalizedFailureReasonErrorKey);
46
_NS_CONST(ErrorUserInfoKey, LocalizedRecoverySuggestionErrorKey);
47
_NS_CONST(ErrorUserInfoKey, LocalizedRecoveryOptionsErrorKey);
48
_NS_CONST(ErrorUserInfoKey, RecoveryAttempterErrorKey);
49
_NS_CONST(ErrorUserInfoKey, HelpAnchorErrorKey);
50
_NS_CONST(ErrorUserInfoKey, DebugDescriptionErrorKey);
51
_NS_CONST(ErrorUserInfoKey, LocalizedFailureErrorKey);
52
_NS_CONST(ErrorUserInfoKey, StringEncodingErrorKey);
53
_NS_CONST(ErrorUserInfoKey, URLErrorKey);
54
_NS_CONST(ErrorUserInfoKey, FilePathErrorKey);
55
56
class Error : public Copying<Error>
57
{
58
public:
59
static Error* error(ErrorDomain domain, Integer code, class Dictionary* pDictionary);
60
61
static Error* alloc();
62
Error* init();
63
Error* init(ErrorDomain domain, Integer code, class Dictionary* pDictionary);
64
65
Integer code() const;
66
ErrorDomain domain() const;
67
class Dictionary* userInfo() const;
68
69
class String* localizedDescription() const;
70
class Array* localizedRecoveryOptions() const;
71
class String* localizedRecoverySuggestion() const;
72
class String* localizedFailureReason() const;
73
};
74
}
75
76
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
77
78
_NS_PRIVATE_DEF_CONST(NS::ErrorDomain, CocoaErrorDomain);
79
_NS_PRIVATE_DEF_CONST(NS::ErrorDomain, POSIXErrorDomain);
80
_NS_PRIVATE_DEF_CONST(NS::ErrorDomain, OSStatusErrorDomain);
81
_NS_PRIVATE_DEF_CONST(NS::ErrorDomain, MachErrorDomain);
82
83
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, UnderlyingErrorKey);
84
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, LocalizedDescriptionKey);
85
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, LocalizedFailureReasonErrorKey);
86
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, LocalizedRecoverySuggestionErrorKey);
87
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, LocalizedRecoveryOptionsErrorKey);
88
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, RecoveryAttempterErrorKey);
89
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, HelpAnchorErrorKey);
90
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, DebugDescriptionErrorKey);
91
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, LocalizedFailureErrorKey);
92
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, StringEncodingErrorKey);
93
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, URLErrorKey);
94
_NS_PRIVATE_DEF_CONST(NS::ErrorUserInfoKey, FilePathErrorKey);
95
96
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
97
98
_NS_INLINE NS::Error* NS::Error::error(ErrorDomain domain, Integer code, class Dictionary* pDictionary)
99
{
100
return Object::sendMessage<Error*>(_NS_PRIVATE_CLS(NSError), _NS_PRIVATE_SEL(errorWithDomain_code_userInfo_), domain, code, pDictionary);
101
}
102
103
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
104
105
_NS_INLINE NS::Error* NS::Error::alloc()
106
{
107
return Object::alloc<Error>(_NS_PRIVATE_CLS(NSError));
108
}
109
110
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
111
112
_NS_INLINE NS::Error* NS::Error::init()
113
{
114
return Object::init<Error>();
115
}
116
117
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
118
119
_NS_INLINE NS::Error* NS::Error::init(ErrorDomain domain, Integer code, class Dictionary* pDictionary)
120
{
121
return Object::sendMessage<Error*>(this, _NS_PRIVATE_SEL(initWithDomain_code_userInfo_), domain, code, pDictionary);
122
}
123
124
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
125
126
_NS_INLINE NS::Integer NS::Error::code() const
127
{
128
return Object::sendMessage<Integer>(this, _NS_PRIVATE_SEL(code));
129
}
130
131
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
132
133
_NS_INLINE NS::ErrorDomain NS::Error::domain() const
134
{
135
return Object::sendMessage<ErrorDomain>(this, _NS_PRIVATE_SEL(domain));
136
}
137
138
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
139
140
_NS_INLINE NS::Dictionary* NS::Error::userInfo() const
141
{
142
return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(userInfo));
143
}
144
145
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
146
147
_NS_INLINE NS::String* NS::Error::localizedDescription() const
148
{
149
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(localizedDescription));
150
}
151
152
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
153
154
_NS_INLINE NS::Array* NS::Error::localizedRecoveryOptions() const
155
{
156
return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(localizedRecoveryOptions));
157
}
158
159
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
160
161
_NS_INLINE NS::String* NS::Error::localizedRecoverySuggestion() const
162
{
163
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(localizedRecoverySuggestion));
164
}
165
166
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
167
168
_NS_INLINE NS::String* NS::Error::localizedFailureReason() const
169
{
170
return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(localizedFailureReason));
171
}
172
173
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
174
175