SFDataWrapper
Inherits From: NSObject
Declared In: SFDataWrapper.h
Class Description
A SFDataWrapper is an NSObject that encapsulates data and carries it between the application and SFDataBase object. SFDataWrappers are usually placed into NSMutableArray that works as a container that carries them to their destination.
SFDataWrapper can contain the following types of data:
TINY | unsigned char | |
SHORT | short int | |
INTEGER | int | |
FLOAT | double | |
MONEY | double | |
LOGICAL | BOOL | |
TEXT | NSString (free-formatted text string) | |
NOTE | NSString (free-formatted text string) | |
DATE | NSString (CCYYMMDD, e.g. Feb 1, 1999 = @"1990201") | |
ACCPERIOD | NSString (e.g. @"99/05") | |
GLPREFIX | NSString (e.g. @"01") | |
GLNUMBER | NSString (e.g. @"1234") | |
SLNUMBER | NSString (e.g. @"500") | |
TIME | NSString (HHMMSS, e.g. 3:00 PM = @"150000") | |
FILENAME | NSString (file name, with or without path) | |
IMAGE | NSImage | |
NSOBJECT | any object of NSObject hierarchy | |
BINARYOBJECT | buffer with arbitrary bytestream |
These types are deined in DefinedConstants.h header file.
Method Types
Initialization | - init - initWithData:type: - initWithUnterminatedString:size: - initWithNSString: - initWithNSString:type: - initForType:maxSize: - initFromVariable: - initFromObject: |
Termination | - release |
Copying | - copy - copyWithZone: |
Setting contents | - setObject: - setDataType: - setContentsFromVariable: - setSize: - setData: - setNull: |
Accessors | - isEmpty - dataType - dataSize - data - rawData - object - string - intValue - shortValue - tinyValue - charValue - floatValue - doubleValue - boolValue - isNull - isObject |
Instance Methods
boolValue
- (BOOL) boolValue
Returns integer value carried by the receiver. Should be used with SFDataWrappers of LOGICAL data type only.
copy
- copy
Returns an autoreleased copy of the receiver, allocating it from the default zone. If the receiver contains an object, the original object is retained by the copy (rather than copied).
copyWithZone:
- copyWithZone: (NSZone *) zone
Returns an autoreleased copy of the receiver, allocating it from zone. If the receiver contains an object, the original object is retained by the copy (rather than copied).
data
- (void *) data
Returns pointer to the internal data buffer of the receiver. Depending on the receiver's data type, this may be a pointer to a fixed-length variable, an object or a buffer of length returned by the dataSize method.
dataSize
- (int) dataSize
Returns the data size of the receiver.
dataType
- (int) dataType
Returns the data type of the receiver.
doubleValue
- (double) doubleValue
Returns integer value carried by the receiver. Should be used with SFDataWrappers of FLOAT or MONEY data type only.
init
- init
Initializes a newly allocated empty SFDataWrapper. The contents of SFDataWrapper must be set using set... methods. The initialized object is autoreleased.
initForType:maxSize:
- initForType: (int) type
maxSize: (int) size
Initializes a newly allocated SFDataWrapper with an empty buffer of length size. This method is used for priming up SFDataWrapper to receive a buffer of BINARYOBJECT data.
The initialized object is autoreleased.
initFromObject:
- initFromObject: id) object
Initializes a newly allocated SFDataWrapper with an arbitrary object from NSObject hierarchy. The object is retained by the receiver.
The initialized object is autoreleased.
initFromVariable:
- initFromVariable: (SFVariable *) variable
Initializes a newly allocated SFDataWrapper with a contents and data type of SFVariable object. This method can be used in user-defined functions that receive their parameters as SFVariables.
The initialized object is autoreleased.
initWithData:type:
- initWithData: (const void *) dataPtr
type: (int) type
Initializes a newly allocated SFDataWrapper with an arbitrary data of the known type. dataPtr is a pointer to the variable that contains the data. The data type of the variable must correspond to the type parameter as follows:
TINY | unsigned char | |
SHORT | short int | |
INTEGER | int | |
FLOAT | double | |
MONEY | double | |
LOGICAL | BOOL | |
TEXT | NULL-terminated ASCII string | |
DATE | NULL-terminated ASCII string | |
ACCPERIOD | NULL-terminated ASCII string | |
GLPREFIX | NULL-terminated ASCII string | |
GLNUMBER | NULL-terminated ASCII string | |
SLNUMBER | NULL-terminated ASCII string | |
TIME | NULL-terminated ASCII string | |
FILENAME | NULL-terminated ASCII string |
ASCII strings passed to SFDataWrapper are converted to NSString objects inside SFDataWrapper.
The initialized object is autoreleased.
initWithNSString:
- initWithNSString: (NSString *) string
Initializes a newly allocated SFDataWrapper with an NSString. The data type of SFDataWrapper is set to TEXT.
The initialized object is autoreleased.
initWithNSString:type:
- initWithNSString: (NSString *) string
type: (int) type
Same as initWithNSString: but allows for setting to the data type other than TEXT.
initWithUnterminatedString:size:
- initWithUnterminatedString: (const void *) dataPtr
size: (int) size
Initializes a newly allocated SFDataWrapper with a character string. dataPtr is a pointer to the string; size is the length of the string, not including the NULL terminator. The character string is converted to NSString inside SFDataWrapper.
The initialized object is autoreleased.
intValue
- (int) intValue
Returns integer value carried by the receiver. Should be used with SFDataWrappers of INTEGER data type only.
isNull
- (BOOL) isNull
Returns flag that indicates whether the contents of SFDataWrapper is empty due to the NULL value in the database table from which the receiver has been initialized.
isObject
- (BOOL) isObject
Returns flag that indicates whether the receiver contains an object (NSString or any other subclass of NSObject).
object
- (NSObject *) object
Returns the object carried by the receiver. If the receiver's contents is not an object, returns nil.
rawData
- (void *) rawData
For the fixed-length data types, behaves like data. For objects, returns the following data:
NSString: | Returns the NULL-terminated ASCII character string as in cString instance method of NSString class. | |
NSObject: | Archives the object into NSData object, using archivedDataWithRootObject: method of NSArchiver class, and returns the pointer to its internal data buffer using bytes method of NSData. |
setContentsFromVariable:
- (void) setContentsFromVariable: (SFVariable *) variable
Sets contents of the receiver to that of variable. This method can be used in user-defined functions that receive their parameters as SFVariables.
.
setData:
- (void) setData: (const void *) dataPtr
Sets contents of the receiver based on dataPtr. The result of this method depends on the data type of the receiver. For the data types that carry NSStrings (i.e. TEXT, DATE, TIME etc. - see the class description for the complete list) dataPtr must be a NSString object; this object is retained by the receiver. For the NSOBJECT data type dataPtr must be a pointer to the buffer containing previously archived object from NSObject hierarchy (as found in the archive file); the object is unarchived inside the receiver. For the fixed-size data types dataPtr must point to the variable that carries the data; the data is copied to the receiver's internal buffer according to the receiver's data size.
setDataType:
- (void) setDataType: (int) type
Sets data type of the receiver to type. Should be used for SFDataWrapper initialized by init method.
setSize:
- (void) setSize: (int) size
Clears the current contents of the receiver and allocates its data buffer to size bytes.
shortValue
- (short) shortValue
Returns integer value carried by the receiver. Should be used with SFDataWrappers of SHORT data type only.
string
- (NSString *) string
Same as object, but casts the returned object as NSString for convenience. Should be used with SFDataWrappers of the data type that carries NSStrings (see class description).
tinyValue
- (unsigned char) tinyValue
Returns integer value carried by the receiver. Should be used with SFDataWrappers of TINY data type only.