wizumwalt
2007.04.06, 11:11 PM
I've slowly been wrestling with this problem and am getting closer.
I'm trying to serialize a C++ object into a standard cocoa object so that I can send it over DO. As I understand it, if I can write my C++ objects into a byte buffer, I can create an NSArray of NSData objects and tell the encoder inside encodeWithCoder: to encode the array and all the objects will be encoded automatically, and send those over DO.
I have a PatternWrapper class that encapsulates a single c++ pattern and does encode/decode. Then I will stick those in NSArray and send it over DO.
My problem is the encodeWithCoder: and initWithCoder: methods, I'm not sure how to get my C++ object in them.
Can anyone help out here?
---
using namespace TX;
@interface PatternWrapper : NSObject {
TX::Pattern *pattern;
}
- (id)initWithPattern:(TX::Pattern *)nativePattern;
- (void)encodeWithCoder:(NSCoder *)encoder;
- (id)initWithCoder:(NSCoder *)decoder;
@end
@implementation PatternWrapper
- (id)initWithPattern:(TX::Pattern *)nativePattern
{
if (self) {
pattern = new TX::Pattern(nativePattern);
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[super encodeWithCoder:encoder];
// ???
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];
if (self) {
pattern = new TX::Pattern();
// ???
}
return self;
}
---
Any help much appreciated.
I'm trying to serialize a C++ object into a standard cocoa object so that I can send it over DO. As I understand it, if I can write my C++ objects into a byte buffer, I can create an NSArray of NSData objects and tell the encoder inside encodeWithCoder: to encode the array and all the objects will be encoded automatically, and send those over DO.
I have a PatternWrapper class that encapsulates a single c++ pattern and does encode/decode. Then I will stick those in NSArray and send it over DO.
My problem is the encodeWithCoder: and initWithCoder: methods, I'm not sure how to get my C++ object in them.
Can anyone help out here?
---
using namespace TX;
@interface PatternWrapper : NSObject {
TX::Pattern *pattern;
}
- (id)initWithPattern:(TX::Pattern *)nativePattern;
- (void)encodeWithCoder:(NSCoder *)encoder;
- (id)initWithCoder:(NSCoder *)decoder;
@end
@implementation PatternWrapper
- (id)initWithPattern:(TX::Pattern *)nativePattern
{
if (self) {
pattern = new TX::Pattern(nativePattern);
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[super encodeWithCoder:encoder];
// ???
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];
if (self) {
pattern = new TX::Pattern();
// ???
}
return self;
}
---
Any help much appreciated.