Annotation of Examples/EnterpriseObjects/DistributedEO/DEOClient.subproj/DOExtensions.subproj/FoundationExtensionsPrivate.m, revision 1.1.1.1

1.1       root        1: /*
                      2:    FoundationExtensionsPrivate.m modified by enoyau on Fri 13-Jan-1995
                      3: 
                      4:    You may freely copy, distribute, and reuse the code in this example.
                      5:    NeXT disclaims any warranty of any kind, expressed or implied, as to its
                      6:    fitness for any particular use.
                      7: */
                      8: /*
                      9:  *  Private classes for the compatibility routines between the old DO
                     10:  *  mechanisms and the new Foundation objects.
                     11:  *
                     12:  *  No guarantee is made for the fitness of this code for any particular
                     13:  *  use.  No warranty expressed or implied.  Use at your own risk!
                     14:  *
                     15:  *  Randy Tidd
                     16:  *  NeXT Premium Developer Support
                     17:  */
                     18: #import "FoundationExtensionsPrivate.h"
                     19: #import <remote/transport.h>
                     20: #import <foundation/NSUtilities.h>
                     21: #import <foundation/NSException.h>
                     22: 
                     23: @implementation _NSArrayPlaceHolder
                     24: - initWithArray:(NSArray *)anArray
                     25: {
                     26:     [super init];
                     27:     array = [anArray copy];
                     28:     return self;
                     29: }
                     30: 
                     31: - free
                     32: {
                     33:     [array release];
                     34:     return [super free];
                     35: }
                     36: 
                     37: - encodeUsing:(id <NXEncoding>)portal
                     38: {
                     39:     unsigned count, i;
                     40: 
                     41:     // First encode the count
                     42:     count = [array count];
                     43:     [portal encodeData:&count ofType:"i"];
                     44: 
                     45:     // Then encode the objects one by one
                     46:     for(i=0; i<[array count]; i++) {
                     47:         [portal encodeObject:[array objectAtIndex:i]];
                     48:     }
                     49:     return self;
                     50: }
                     51: 
                     52: - decodeUsing:(id <NXDecoding>)portal
                     53: {
                     54:     NSMutableArray *newArray = nil;
                     55:     unsigned count, i;
                     56: 
                     57:     // We encoded the count first, and here it is
                     58:     [portal decodeData:&count ofType:"i"];
                     59:     newArray = [NSMutableArray arrayWithCapacity:count];
                     60: 
                     61:     // Decode the objects one by one and add them to the array
                     62:     for(i=0; i<count; i++) {
                     63:         [newArray addObject:[portal decodeObject]];
                     64:     }
                     65: 
                     66:     /*
                     67:      *  We return our mutable array instance here even though we might
                     68:      *  be the placeholder for a regular NSArray.  There is usually no
                     69:      *  harm in returning a mutable array in place of an immutable one.
                     70:      *  If there is, you need to implement some smarts here to return an
                     71:      *  instance of the appropriate class.
                     72:      */
                     73:     return newArray;
                     74: }
                     75: @end
                     76: 
                     77: @implementation _NSDictionaryPlaceHolder
                     78: - initWithDictionary:(NSDictionary *)aDictionary
                     79: {
                     80:     [super init];
                     81:     dictionary = [aDictionary copy];
                     82:     return self;
                     83: }
                     84: 
                     85: - free
                     86: {
                     87:     [dictionary release];
                     88:     return [super free];
                     89: }
                     90: 
                     91: - encodeUsing:(id <NXEncoding>)portal
                     92: {
                     93:     unsigned count;
                     94:     NSEnumerator *enumerator = [dictionary keyEnumerator];
                     95:     NSString *key;
                     96: 
                     97:     // First encode the count
                     98:     count = [dictionary count];
                     99:     [portal encodeData:&count ofType:"i"];
                    100: 
                    101:     // Then encode the objects one by one
                    102:     while(key = [enumerator nextObject]) {
                    103:         [portal encodeObject:key];
                    104:         [portal encodeObject:[dictionary objectForKey:key]];
                    105:     }
                    106:     return self;
                    107: }
                    108: 
                    109: - decodeUsing:(id <NXDecoding>)portal
                    110: {
                    111:     NSMutableDictionary *newDictionary = nil;
                    112:     unsigned count, i;
                    113: 
                    114:     // We encoded the count first, and here it is
                    115:     [portal decodeData:&count ofType:"i"];
                    116:     newDictionary = [NSMutableDictionary dictionaryWithCapacity:count];
                    117: 
                    118:     // Decode the objects one by one and add them to the array
                    119:     for(i=0; i<count; i++) {
                    120:         id newKey, newObject;
                    121:         newKey = [portal decodeObject];
                    122:         newObject = [portal decodeObject];
                    123:         if(!newKey || !newObject) {
                    124:             // This should never happen, or we're in trouble.
                    125:             [NSException raise:NSInternalInconsistencyException format:@"%s: %s: can't decode key or object",
                    126:                 isa->name, sel_getName(_cmd)];
                    127:         } else {
                    128:            [newDictionary setObject:newObject forKey:newKey];
                    129:        }
                    130:     }
                    131:     /*
                    132:      *  We return our mutable dictionary instance here even though we might
                    133:      *  be the placeholder for a regular NSDictionary.  There is usually no
                    134:      *  harm in returning a mutable dictionary in place of an immutable one.
                    135:      *  If there is, you need to implement some smarts here to return an
                    136:      *  instance of the appropriate class.
                    137:      */
                    138:     return newDictionary;
                    139: }
                    140: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.