1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
extern_class!(
/// [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkdecisionnode?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct GKDecisionNode;
);
extern_conformance!(
unsafe impl NSObjectProtocol for GKDecisionNode {}
);
impl GKDecisionNode {
extern_methods!(
/// Creates a numeric branch to a node containing the specified attribute
///
///
/// Parameter `value`: The value to create a branch with
///
/// Parameter `attribute`: The attribute of the created node
///
/// Returns: The node lead to by the branch
///
/// # Safety
///
/// `attribute` should be of the correct type.
#[unsafe(method(createBranchWithValue:attribute:))]
#[unsafe(method_family = none)]
pub unsafe fn createBranchWithValue_attribute(
&self,
value: &NSNumber,
attribute: &ProtocolObject<dyn NSObjectProtocol>,
) -> Retained<Self>;
/// Creates a predicated branch to a node containing the specified attribute
///
///
/// Parameter `predicate`: The predicate to create a branch with
///
/// Parameter `attribute`: The attribute of the created node
///
/// Returns: The node lead to by the branch
///
/// # Safety
///
/// `attribute` should be of the correct type.
#[unsafe(method(createBranchWithPredicate:attribute:))]
#[unsafe(method_family = none)]
pub unsafe fn createBranchWithPredicate_attribute(
&self,
predicate: &NSPredicate,
attribute: &ProtocolObject<dyn NSObjectProtocol>,
) -> Retained<Self>;
/// Creates a random branch to a node containing the specified attribute
///
///
/// Parameter `weight`: The weight to create a branch with (weighted for random selection)
///
/// Parameter `attribute`: The attribute of the created node
///
/// Returns: The node lead to by the branch
///
///
/// See: GKDecisionTree
///
/// # Safety
///
/// `attribute` should be of the correct type.
#[unsafe(method(createBranchWithWeight:attribute:))]
#[unsafe(method_family = none)]
pub unsafe fn createBranchWithWeight_attribute(
&self,
weight: NSInteger,
attribute: &ProtocolObject<dyn NSObjectProtocol>,
) -> Retained<Self>;
);
}
/// Methods declared on superclass `NSObject`.
impl GKDecisionNode {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}
extern_class!(
/// [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkdecisiontree?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct GKDecisionTree;
);
extern_conformance!(
unsafe impl NSCoding for GKDecisionTree {}
);
extern_conformance!(
unsafe impl NSObjectProtocol for GKDecisionTree {}
);
extern_conformance!(
unsafe impl NSSecureCoding for GKDecisionTree {}
);
impl GKDecisionTree {
extern_methods!(
/// The node for the decision tree that all other nodes descend from
#[unsafe(method(rootNode))]
#[unsafe(method_family = none)]
pub unsafe fn rootNode(&self) -> Option<Retained<GKDecisionNode>>;
#[cfg(feature = "GKRandomSource")]
/// The random source used by the decision tree when descending on a random branch
/// This must be set before creating any weighted branches
///
/// See: GKDecisionNode
#[unsafe(method(randomSource))]
#[unsafe(method_family = none)]
pub unsafe fn randomSource(&self) -> Retained<GKRandomSource>;
#[cfg(feature = "GKRandomSource")]
/// Setter for [`randomSource`][Self::randomSource].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setRandomSource:))]
#[unsafe(method_family = none)]
pub unsafe fn setRandomSource(&self, random_source: &GKRandomSource);
/// Initializes the decision tree with a root node containing the provided attribute
///
///
/// Parameter `attribute`: The attribute to be contained at the root of the tree
///
/// Returns: GKDecisionTree with the set root
///
/// # Safety
///
/// `attribute` should be of the correct type.
#[unsafe(method(initWithAttribute:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithAttribute(
this: Allocated<Self>,
attribute: &ProtocolObject<dyn NSObjectProtocol>,
) -> Retained<Self>;
/// Initializes and constructs a decision tree by learning from the provided examples
/// &
/// attributes
///
///
/// Parameter `examples`: Must be an array of examples (with each example being a collection of the various attributes at a given state)
///
/// Parameter `actions`: An array of the corresponding actions for each example. Ordered such that the first action matches with the first example in examples.
///
/// Parameter `attributes`: The list of attributes. Ordered such that the first attribute matches with the first result in each example.
/// So if we have two attributes: [distance, jump height], and two examples: [[20, 8], [15, 14]], and the resulting actions here: [Roll, Jump], we can think of this as a matrix:
///
/// distance| height
/// <
/// - Attributes
/// _______|_______
/// | | |
/// | 20 | 8 | jump
/// |-------|-------|-------
/// <
/// - Results
/// | 15 | 14 | roll
/// |_______|_______|
/// ^
/// |
/// Examples
///
///
/// Returns: GKDecisionTree created by learning from the provided examples for the provided attributes
///
/// # Safety
///
/// - `examples` generic generic should be of the correct type.
/// - `actions` generic should be of the correct type.
/// - `attributes` generic should be of the correct type.
#[unsafe(method(initWithExamples:actions:attributes:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithExamples_actions_attributes(
this: Allocated<Self>,
examples: &NSArray<NSArray<ProtocolObject<dyn NSObjectProtocol>>>,
actions: &NSArray<ProtocolObject<dyn NSObjectProtocol>>,
attributes: &NSArray<ProtocolObject<dyn NSObjectProtocol>>,
) -> Retained<Self>;
/// Initializes a decision tree from the contents of a file
///
///
/// Parameter `url`: The URL from which the contents will be loaded
///
/// Returns: The instance of the decision tree constructed
#[unsafe(method(initWithURL:error:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithURL_error(
this: Allocated<Self>,
url: &NSURL,
error: Option<&NSError>,
) -> Retained<Self>;
/// Exports a decision tree to the given URL
///
///
/// Parameter `url`: The URL to which the contents will be exported
///
/// Returns: The response indicating the status of the decision tree being successfully exported
#[unsafe(method(exportToURL:error:))]
#[unsafe(method_family = none)]
pub unsafe fn exportToURL_error(&self, url: &NSURL, error: Option<&NSError>) -> bool;
/// Will branch down from the root node to find the correct action attribute for the given collection of results and their respective attributes
///
///
/// Parameter `answers`: The dictionary of attributes (keys) and their answers (values)
///
/// Returns: The attribute found by traversing the tree given the provided answers
///
/// # Safety
///
/// - `answers` generic should be of the correct type.
/// - `answers` generic should be of the correct type.
#[unsafe(method(findActionForAnswers:))]
#[unsafe(method_family = none)]
pub unsafe fn findActionForAnswers(
&self,
answers: &NSDictionary<
ProtocolObject<dyn NSObjectProtocol>,
ProtocolObject<dyn NSObjectProtocol>,
>,
) -> Option<Retained<ProtocolObject<dyn NSObjectProtocol>>>;
);
}
/// Methods declared on superclass `NSObject`.
impl GKDecisionTree {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}