mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 12:00:48 +00:00
Move GMArchiver files so gui doesnt depend on extenions
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3614 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
68b1bc9a05
commit
ec6158f0bb
13 changed files with 1488 additions and 12 deletions
168
Model/GMArchiveObjects.m
Normal file
168
Model/GMArchiveObjects.m
Normal file
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
GMArchiveObjects.m
|
||||
|
||||
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
||||
Date: October 1997
|
||||
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* This file declares categories to various OpenStep classes so they get
|
||||
archived correctly by GMArchiver. The main things deal with encoding in
|
||||
place of some objects like imutable strings, arrays, dictionaries and
|
||||
data objects (basically the property list classes).
|
||||
|
||||
This file is included by GMArchiver rather than compiled as a separate file
|
||||
because of the linking problems with categories (they are not linked into
|
||||
the executable even if you refer a method from category; you should refer a
|
||||
symbol from the category's file in order to force it link.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSData.h>
|
||||
|
||||
|
||||
@implementation NSObject (ModelArchivingMethods)
|
||||
- (id)replacementObjectForModelArchiver:(GMArchiver*)archiver
|
||||
{
|
||||
return [self replacementObjectForCoder:nil];
|
||||
}
|
||||
|
||||
- (Class)classForModelArchiver
|
||||
{
|
||||
return [self classForCoder];
|
||||
}
|
||||
|
||||
+ (id)createObjectForModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||
{
|
||||
return [[[self allocWithZone:[unarchiver objectZone]] init] autorelease];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSString (ModelArchivingMethods)
|
||||
- (void)encodeWithModelArchiver:(id)archiver
|
||||
{
|
||||
[archiver encodeString:self withName:@"string"];
|
||||
}
|
||||
|
||||
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||
{
|
||||
return [unarchiver decodeStringWithName:@"string"];
|
||||
}
|
||||
|
||||
- (Class)classForModelArchiver
|
||||
{
|
||||
return [NSString class];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSMutableString (ModelArchivingMethods)
|
||||
- (Class)classForModelArchiver
|
||||
{
|
||||
return [NSMutableString class];
|
||||
}
|
||||
|
||||
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||
{
|
||||
return [[[unarchiver decodeStringWithName:@"string"] mutableCopy]
|
||||
autorelease];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSArray (ModelArchivingMethods)
|
||||
- (void)encodeWithModelArchiver:(id)archiver
|
||||
{
|
||||
[archiver encodeArray:self withName:@"elements"];
|
||||
}
|
||||
|
||||
- (Class)classForModelArchiver
|
||||
{
|
||||
return [NSMutableArray class];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSMutableArray (ModelArchivingMethods)
|
||||
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||
{
|
||||
id array = [unarchiver decodeArrayWithName:@"elements"];
|
||||
int i, count;
|
||||
|
||||
for (i = 0, count = [array count]; i < count; i++)
|
||||
[self addObject:[array objectAtIndex:i]];
|
||||
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSDictionary (ModelArchivingMethods)
|
||||
- (void)encodeWithModelArchiver:(id)archiver
|
||||
{
|
||||
[archiver encodeDictionary:self withName:@"elements"];
|
||||
}
|
||||
|
||||
- (Class)classForModelArchiver
|
||||
{
|
||||
return [NSMutableDictionary class];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSMutableDictionary (ModelArchivingMethods)
|
||||
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||
{
|
||||
id dictionary = [unarchiver decodeDictionaryWithName:@"elements"];
|
||||
id enumerator = [dictionary keyEnumerator];
|
||||
id key, value;
|
||||
|
||||
while ((key = [enumerator nextObject])) {
|
||||
value = [dictionary objectForKey:key];
|
||||
[self setObject:value forKey:key];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSData (ModelArchivingMethods)
|
||||
- (void)encodeWithModelArchiver:(id)archiver
|
||||
{
|
||||
[archiver encodeData:self withName:@"data"];
|
||||
}
|
||||
|
||||
- (Class)classForModelArchiver
|
||||
{
|
||||
return [NSMutableData class];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSMutableData (ModelArchivingMethods)
|
||||
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||
{
|
||||
id data = [unarchiver decodeDataWithName:@"data"];
|
||||
|
||||
[self appendData:data];
|
||||
return self;
|
||||
}
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue