|
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
|
//
// EMResourceValue.h
// Emmoco
//
// Created by bob frankel on 8/8/11.
// Copyright 2011 Emmoco, Inc.. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "EMSerialPacket.h"
@class EMSchema;
@class EMSerialPacket;
@class EMResourceValue;
/**
* A protocol to define the methods that all EMResourceValue subclasses must define.
*
* Written by Carolyn Vaughan
*/
@protocol EMResourceValueProtocol
/**
* Internal initialization method used by EMResourceValue subclasses
* @param theName the name of this value
* @param theType the type of this value
* @param theResourceSchema the schema associated with this value
* @return this value
*/
- (id)initWithName:(NSString*)theName type:(NSString*)theType schema:(EMSchema*)theResourceSchema;
/**
* Returns true if the type of this value is an Array, and false otherwise.
*/
- (BOOL)isArray;
/**
* Returns true if the type of this value is a Num, and false otherwise.
*/
- (BOOL)isNum;
/**
* Returns true if the type of this value is an Enum, and false otherwise.
*/
- (BOOL)isEnum;
/**
* Returns true if the type of this value is a File, and false otherwise.
*/
- (BOOL)isFile;
/**
* Returns true if the type of this value is an Int, and false otherwise.
*/
- (BOOL)isInt;
/**
* Returns true if the type of this value is a String, and false otherwise.
*/
- (BOOL)isString;
/**
* Returns true if the type of this value is scalar (Num, Enum, Int, String), and false otherwise.
*/
- (BOOL)isScalar;
/**
* Return true if the type of this value is a Struct, and false otherwise.
*/
- (BOOL)isStruct;
/**
* Return true if the type of this value is a Void, and false otherwise.
*/
- (BOOL)isVoid;
/**
* Used to put the resource's value to the device
* @param buffer the data buffer being sent to the device
*
* The PUT is based on RESTful resourcing
*/
- (void)putData:(EMSerialPacket*)buffer;
/**
* Used to get the resource's value from the device
* @param buffer the data buffer being received from the device
* @param size the amount of data the buffer holds
*
* The GET is based on RESTful resourcing
*/
- (void)getDataOfSize:(int)size fromBuffer:(EMSerialPacket*)buffer;
/**
* Assign a double value to a resource.
* @param value the value to be assigned, represented as a double
*/
- (void)setDoubleValue:(double)value;
/**
* Assign a long value to a resource. For Num and Enum resources, this sets the ordinal value for the resource instead of setting the value directly.
* @param value the value to be assigned, represented as a long
*/
- (void)setLongValue:(long long)value;
/**
* Assign a string value to a resource.
* @param value the value to be assigned, represented as a String
*/
- (void)setStringValue:(NSString*)value;
/**
* This ResourceValue, as a double.
* @exception UsageError the type of this value is not a Num
*/
- (double)doubleValue;
/**
* This ResourceValue, as a long. For Num and Enum resources, this returns the ordinal value for the resource instead of the actual value.
* @exception UsageError the type of this value is not a Scalar
*/
- (long long)longValue;
/**
* This ResourceValue, as a String.
* @exception UsageError the type of this value is not a Scalar
*/
- (NSString*)stringValue;
/**
* Assign another resource value's value to this resource value
* @param source the ResourceValue who's value you wish to assign to this EMResourceValue instance
*/
- (void)copyFromResource:(EMResourceValue*)source;
/**
* Reset this ResourceValue to its initial state upon creation
*/
- (void)reset;
/**
* The minimum numerical value for this ResourceValue.
*/
- (double)min;
/**
* The maximum numerical value for this ResourceValue.
*/
- (double)max;
/**
* The step for this ResourceValue.
*/
- (double)step;
/**
* The maximum number of distinct values for this ResourceValue.
*/
- (long)length;
/**
* An array of acceptable enum values for this ResourceValue.
*/
- (NSArray *)enumValues;
/**
* An array of acceptable field names for this ResourceValue.
*/
- (NSArray *)fieldNames;
/**
* Select a ResourceValue element from a ResourceValue Array by index
* @param index the element to be selected
* @return the indexed element
*/
- (EMResourceValue*)index:(int)index;
/**
* Select a ResourceValue element from a ResourceValue Struct by field name
* @param fieldName the element to be selected
* @return the ResourceValue held in the selected field
*/
- (EMResourceValue*)select:(NSString*)fieldName;
/**
* Return the end-of-file status for this ResourceValue File. For internal use only.
*/
- (BOOL)fileEof;
/**
* Prepare a local file associated with this ResourceValue File for reading. For internal use only;
d*/
- (void)fileFetch;
/**
* Prepare a local file associated with this ResourceValue File for writing. For internal use only;
*/
- (void)fileStore;
-(NSData *)fileData;
@end
/**
* A container for different types of resource values.
* Instances of this class are used to hold values for resources whose types is
* either Void, Int, Enum, Num, String, Struct, Array, or File.
*
* See also:
*
* - [EMSchema newResourceValueForResourceNamed:]
*
* Written by Bob Frankel and Carolyn Vaughan
*/
@interface EMResourceValue : NSObject <EMResourceValueProtocol> {
}
/**
* The name of the resource.
*/
@property(readonly) NSString* name;
/**
* The resource schema associated with the resource.
*/
@property(readonly) EMSchema* resourceSchema;
/**
* The type of the resource.
*/
@property(readonly) NSString* type;
- (int)valueSize;
/**
* Create a EMResourceValue. This method is used internally by the framework.
* @param name the name given to the newly-created value
* @param type the type of the newly-created value
* @param resourceSchema an EMSchema instance
* @return a new EMResourceValue instance
*/
+ (EMResourceValue*)resourceWithName:(NSString*)name ofType:(NSString*)type fromSchema:(EMSchema*)resourceSchema;
@end
|