src/MulleScionObjectModel+NSCoding.m
2995f4ad
 //
 //  MulleScionObjectModel+NSCoding.m
d2f30cd2
 //  MulleScion
2995f4ad
 //
 //  Created by Nat! on 25.02.13.
 //
ef82839d
 //  Copyright (c) 2013 Nat! - Mulle kybernetiK
 //  All rights reserved.
 //
 //  Redistribution and use in source and binary forms, with or without
 //  modification, are permitted provided that the following conditions are met:
 //
 //  Redistributions of source code must retain the above copyright notice, this
 //  list of conditions and the following disclaimer.
 //
 //  Redistributions in binary form must reproduce the above copyright notice,
 //  this list of conditions and the following disclaimer in the documentation
 //  and/or other materials provided with the distribution.
 //
 //  Neither the name of Mulle kybernetiK nor the names of its contributors
 //  may be used to endorse or promote products derived from this software
 //  without specific prior written permission.
 //
 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 //  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 //  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 //  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 //  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 //  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 //  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 //  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 //  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 //  POSSIBILITY OF SUCH DAMAGE.
 //
 
2995f4ad
 
 #import "MulleScionObjectModel+NSCoding.h"
 
 
27dc2200
 @implementation MulleScionObject( NSCoding)
2995f4ad
 
 + (void) load
 {
d7a43901
    [self setVersion:1851];  // sry had to change something, old stuff not loading anymore
2995f4ad
 }
 
 
08b5d36d
 //
 // use NSCoding to make a copy, so I don't have to write all those
 // copy routines
 //
27dc2200
 static id  _copy(id self)
08b5d36d
 {
    NSData             *data;
    NSAutoreleasePool  *pool;
    id                 copy;
27dc2200
 
08b5d36d
    pool = [NSAutoreleasePool new];
3f8d4c56
 #if TARGET_OS_IPHONE  // much slower...
    data = [NSKeyedArchiver archivedDataWithRootObject:self];
    copy = [[NSKeyedUnarchiver unarchiveObjectWithData:data] retain];
 #else
08b5d36d
    data = [NSArchiver archivedDataWithRootObject:self];
    copy = [[NSUnarchiver unarchiveObjectWithData:data] retain];
3f8d4c56
 #endif
08b5d36d
    [pool release];
27dc2200
 
08b5d36d
    return( copy);
 }
27dc2200
 
 
 - (id) copyWithZone:(NSZone *) zone
 {
    return( _copy( self));
 }
 
 
 - (id) copy
 {
    return( _copy( self));
 }
 
 
2995f4ad
 - (id) initWithCoder:(NSCoder *) decoder
 {
b6b361d1
    uint32_t  lineNumber;
    id        next;
27dc2200
 
bdb5913e
    [decoder decodeValueOfObjCType:@encode( uint32_t)
                                at:&lineNumber];
2995f4ad
 
7e71be68
     // needed to be coded like this otherwise keyed unarchiver trashes the
     // stack
bdb5913e
    next = [decoder decodeObject];
27dc2200
 
2995f4ad
    self = [self initWithLineNumber:lineNumber];
    assert( self);
 
bdb5913e
    self->next_ = [next retain];
2995f4ad
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
b6b361d1
    uint32_t  lineNumber;
27dc2200
 
b6b361d1
    lineNumber = (uint32_t) lineNumber_;
bdb5913e
    [encoder encodeValueOfObjCType:@encode( uint32_t)
                                at:&lineNumber];
7e71be68
    [encoder encodeObject:next_];
2995f4ad
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionValueObject( NSCoding)
2995f4ad
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
2995f4ad
    [decoder decodeValuesOfObjCTypes:"@", &value_];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"@", &value_];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionAssignmentExpression( NSCoding )
c533990f
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
c533990f
    [decoder decodeValuesOfObjCTypes:"@", &right_];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"@", &right_];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionParameterAssignment( NSCoding )
801f8317
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
801f8317
    [decoder decodeValuesOfObjCTypes:"@", &expression_];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"@", &expression_];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionFunction( NSCoding )
2995f4ad
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
2995f4ad
    [decoder decodeValuesOfObjCTypes:"@", &arguments_];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"@", &arguments_];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionMethod( NSCoding )
2995f4ad
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    NSString  *methodName;
27dc2200
 
2995f4ad
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
2995f4ad
    [decoder decodeValuesOfObjCTypes:"@@", &arguments_, &methodName];
    action_ = NSSelectorFromString( methodName);
    [methodName release];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    NSString  *methodName;
 
    [super encodeWithCoder:encoder];
    methodName = NSStringFromSelector( action_);
    [encoder encodeValuesOfObjCTypes:"@@", &arguments_, &methodName];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionBinaryOperatorExpression ( NSCoding )
2995f4ad
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
2995f4ad
    [decoder decodeValuesOfObjCTypes:"@", &right_];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"@", &right_];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionComparison ( NSCoding )
801f8317
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    unsigned char   code;
 
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
801f8317
    [decoder decodeValuesOfObjCTypes:"C", &code];
    comparison_ = code;
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    unsigned char   code;
27dc2200
 
801f8317
    [super encodeWithCoder:encoder];
    code = comparison_;
    [encoder encodeValuesOfObjCTypes:"C", &code];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionConditional( NSCoding )
801f8317
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
801f8317
    [decoder decodeValuesOfObjCTypes:"@@", &middle_, &right_];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"@@", &middle_, &right_];
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionExpressionCommand( NSCoding)
2995f4ad
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
c533990f
    [decoder decodeValuesOfObjCTypes:"@", &expression_];
2995f4ad
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
c533990f
    [encoder encodeValuesOfObjCTypes:"@", &expression_];
2995f4ad
 }
 
 @end
 
 
27dc2200
 @implementation MulleScionFilter( NSCoding)
fec98eee
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    [decoder decodeValuesOfObjCTypes:"I", &self->_flags];
 
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"I", &self->_flags];
 }
 
 @end
 
 
 
27dc2200
 @implementation MulleScionSet( NSCoding)
2995f4ad
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
c533990f
    [decoder decodeValuesOfObjCTypes:"@@", &left_, &right_];
2995f4ad
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
c533990f
    [encoder encodeValuesOfObjCTypes:"@@", &left_, &right_];
2995f4ad
 }
 
 @end
 
 
c533990f
 
27dc2200
 @implementation MulleScionBlock( NSCoding)
2995f4ad
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
801f8317
    [decoder decodeValuesOfObjCTypes:"@@", &identifier_, &fileName_];
2995f4ad
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
801f8317
    [encoder encodeValuesOfObjCTypes:"@@", &identifier_, &fileName_];
2995f4ad
 }
 
 @end
 
 
08b5d36d
 #ifdef DEBUG
27dc2200
 @implementation MulleScionMacro( NSCoding )
2995f4ad
 
08b5d36d
 - (id) initWithCoder:(NSCoder *) decoder
 {
    abort();
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    abort();
 }
 @end
 #endif
fee8e7fd
 
 
27dc2200
 @implementation MulleScionRequires( NSCoding)
fee8e7fd
 
 - (id) initWithCoder:(NSCoder *) decoder
 {
    self = [super initWithCoder:decoder];
    assert( self);
27dc2200
 
fee8e7fd
    [decoder decodeValuesOfObjCTypes:"@", &identifier_];
    return( self);
 }
 
 
 - (void) encodeWithCoder:(NSCoder *) encoder
 {
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:"@", &identifier_];
 }
 
 @end