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:
Adam Fedor 1999-01-28 18:34:31 +00:00
parent 2059f295a3
commit 6bde69b8ec
13 changed files with 1488 additions and 12 deletions

View file

@ -27,7 +27,7 @@
#define _GNUstep_H_GMAppKit
#include <AppKit/AppKit.h>
#import <extensions/GMArchiver.h>
#import <AppKit/GMArchiver.h>
@interface NSApplication (GMArchiverMethods) <ModelCoding>
@end

View file

@ -0,0 +1,196 @@
/*
GMArchiver.h
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.
*/
/* Portions of the code are based on NSArchiver from libFoundation. See the
COPYING file from libFoundation for copyright information. */
#ifndef __GMArchiver_h__
#define __GMArchiver_h__
#import <Foundation/NSCoder.h>
#import <Foundation/NSHashTable.h>
#import <Foundation/NSMapTable.h>
#import <Foundation/NSGeometry.h>
@class NSString;
@class NSData;
@class NSArray;
@class NSDictionary;
@class NSMutableArray;
@class NSMutableDictionary;
@class GMArchiver;
@class GMUnarchiver;
/* The objects that want to be archived the following protocol. */
@protocol ModelCoding
/* These methods are much like those from the NSCoding protocol.
The difference is that you can specify names for the instance
variables or attributes you encode. The recommended way is not to encode
instance variables but attributes so that an archive file does not
depend on the particular version of a class or on different
instance variable names of the class from another implementation. */
- (void)encodeWithModelArchiver:(GMArchiver*)archiver;
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver;
@end
@interface NSObject (ModelArchivingMethods)
- (id)replacementObjectForModelArchiver:(GMArchiver*)archiver;
- (Class)classForModelArchiver;
+ (id)createObjectForModelUnarchiver:(GMUnarchiver*)unarchiver;
@end
@interface GMArchiver : NSObject
{
NSMutableDictionary* propertyList;
NSMutableArray* topLevelObjects;
id lastObjectRepresentation;
NSMapTable* objects; // object -> name
NSHashTable* conditionals; // conditional objects
NSMapTable* classes; // real classname -> class info
int counter;
int level;
BOOL writingRoot; // YES if encodeRootObject:withName: was sent
BOOL findingConditionals; // YES if finding conditionals
}
/* Initializing an GMArchiver */
- (id)init;
/* Archiving Data */
+ (BOOL)archiveRootObject:(id)rootObject
toFile:(NSString*)path;
- (BOOL)writeToFile:(NSString*)path;
/* Getting the property list representation from the GMArchiver */
- (id)propertyList;
/* Encoding objects */
- (id)encodeRootObject:(id)rootObject withName:(NSString*)name;
- (id)encodeConditionalObject:(id)object withName:(NSString*)name;
- (id)encodeObject:(id)anObject withName:(NSString*)name;
- (id)encodeString:(NSString*)anObject withName:(NSString*)name;
- (id)encodeArray:(NSArray*)array withName:(NSString*)name;
- (id)encodeDictionary:(NSDictionary*)dictionary withName:(NSString*)name;
- (id)encodeData:(NSData*)anObject withName:(NSString*)name;
- (id)encodeClass:(Class)class withName:(NSString*)name;
- (id)encodeSelector:(SEL)selector withName:(NSString*)name;
/* Encoding the most common C types */
- (void)encodeChar:(char)value withName:(NSString*)name;
- (void)encodeUnsignedChar:(unsigned char)value withName:(NSString*)name;
- (void)encodeBOOL:(BOOL)value withName:(NSString*)name;
- (void)encodeShort:(short)value withName:(NSString*)name;
- (void)encodeUnsignedShort:(unsigned short)value withName:(NSString*)name;
- (void)encodeInt:(int)value withName:(NSString*)name;
- (void)encodeUnsignedInt:(unsigned int)value withName:(NSString*)name;
- (void)encodeLong:(long)value withName:(NSString*)name;
- (void)encodeUnsignedLong:(unsigned long)value withName:(NSString*)name;
- (void)encodeFloat:(float)value withName:(NSString*)name;
- (void)encodeDouble:(double)value withName:(NSString*)name;
/* Encoding geometry types */
- (void)encodePoint:(NSPoint)point withName:(NSString*)name;
- (void)encodeSize:(NSSize)size withName:(NSString*)name;
- (void)encodeRect:(NSRect)rect withName:(NSString*)name;
/* Substituting One Class for Another */
- (NSString*)classNameEncodedForTrueClassName:(NSString*)trueName;
- (void)encodeClassName:(NSString*)trueName
intoClassName:(NSString*)inArchiveName;
@end /* GMArchiver */
@interface GMUnarchiver : NSObject
{
NSMutableDictionary* propertyList;
id currentDecodedObjectRepresentation;
NSMutableDictionary* namesToObjects; // object name -> object
int level;
int version;
NSZone* objectZone;
}
/* Initializing an GMUnarchiver */
+ (id)unarchiverWithContentsOfFile:(NSString*)filename;
- (id)initForReadingWithPropertyList:(id)propertyList;
/* Decoding Objects */
+ (id)unarchiveObjectWithName:(NSString*)name
fromPropertyList:(id)propertyList;
+ (id)unarchiveObjectWithName:(NSString*)name fromFile:(NSString*)path;
/* Decoding objects */
- (id)decodeObjectWithName:(NSString*)name;
- (NSString*)decodeStringWithName:(NSString*)name;
- (NSArray*)decodeArrayWithName:(NSString*)name;
- (NSDictionary*)decodeDictionaryWithName:(NSString*)name;
- (NSData*)decodeDataWithName:(NSString*)name;
- (Class)decodeClassWithName:(NSString*)name;
- (SEL)decodeSelectorWithName:(NSString*)name;
/* Decoding the most common C types */
- (char)decodeCharWithName:(NSString*)name;
- (unsigned char)decodeUnsignedCharWithName:(NSString*)name;
- (BOOL)decodeBOOLWithName:(NSString*)name;
- (short)decodeShortWithName:(NSString*)name;
- (unsigned short)decodeUnsignedShortWithName:(NSString*)name;
- (int)decodeIntWithName:(NSString*)name;
- (unsigned int)decodeUnsignedIntWithName:(NSString*)name;
- (long)decodeLongWithName:(NSString*)name;
- (unsigned long)decodeUnsignedLongWithName:(NSString*)name;
- (float)decodeFloatWithName:(NSString*)name;
- (double)decodeDoubleWithName:(NSString*)name;
/* Decoding geometry types */
- (NSPoint)decodePointWithName:(NSString*)name;
- (NSSize)decodeSizeWithName:(NSString*)name;
- (NSRect)decodeRectWithName:(NSString*)name;
/* Managing an GMUnarchiver */
- (BOOL)isAtEnd;
- (NSZone*)objectZone;
- (void)setObjectZone:(NSZone*)zone;
- (unsigned int)systemVersion;
/* Substituting One Class for Another */
+ (NSString*)classNameDecodedForArchiveClassName:(NSString*)nameInArchive;
+ (void)decodeClassName:(NSString*)nameInArchive
asClassName:(NSString*)trueName;
- (NSString*)classNameDecodedForArchiveClassName:(NSString*)nameInArchive;
- (void)decodeClassName:(NSString*)nameInArchive
asClassName:(NSString*)trueName;
- (unsigned int)versionForClassName:(NSString*)className;
@end
#endif /* __GMArchiver_h__ */

168
Model/GMArchiveObjects.m Normal file
View 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

1096
Model/GMArchiver.m Normal file

File diff suppressed because it is too large Load diff

View file

@ -37,7 +37,8 @@ endif
#APP_NAME = test
libgmodel_OBJC_FILES = IMCustomObject.m IMConnectors.m IMLoading.m GMAppKit.m
libgmodel_OBJC_FILES = IMCustomObject.m IMConnectors.m IMLoading.m GMAppKit.m \
GMArchiver.m
libgmodel_HEADER_FILES_DIR = ../Headers/AppKit
libgmodel_HEADER_FILES_INSTALL_DIR = /gnustep/gui/AppKit
libgmodel_HEADER_FILES = IMConnectors.h IMCustomObject.h IMLoading.h GMAppKit.h
@ -59,7 +60,7 @@ ADDITIONAL_CPPFLAGS += $(RUNTIME_DEFINE) $(GUI_DEFINE) $(BACKEND_DEFINE)
ADDITIONAL_LIB_DIRS += -L$(GNUSTEP_OBJ_DIR)
ADDITIONAL_TOOL_LIBS += -lgmodel -lFoundationExt
ADDITIONAL_TOOL_LIBS += -lgmodel
ADDITIONAL_OBJC_FLAGS += $(BACKEND_DEFINE)
# Additional include directories the compiler should search
@ -69,7 +70,7 @@ ADDITIONAL_INCLUDE_DIRS = -I../Headers -I../Headers/gnustep
# systems where building a shared library requires to pass to the linker
# all the libraries the target library depends upon.
LIBRARIES_DEPEND_UPON = -lFoundationExt $(FND_LIBS) $(GUI_LIBS) \
LIBRARIES_DEPEND_UPON = $(FND_LIBS) $(GUI_LIBS) \
$(BACKEND_LIBS) $(SYSTEM_LIBS)
-include GNUmakefile.local

View file

@ -27,3 +27,6 @@ before-libgmodel-all:: \
../Headers/gnustep/gui/%.h: %.h
cp $^ $@
# Additional dependencies
$(GNUSTEP_OBJ_DIR)/GMArchiver.o: GMArchiveObjects.m

View file

@ -28,7 +28,7 @@
#import <Foundation/NSCoder.h>
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <extensions/GMArchiver.h>
#import <AppKit/GMArchiver.h>
#import "IBClasses.h"
#import "Translator.h"
#import "IMConnectors.h"

View file

@ -26,11 +26,23 @@
#include <string.h>
#import <AppKit/NSActionCell.h>
#include <extensions/GMArchiver.h>
#include <extensions/objc-runtime.h>
#include <AppKit/GMArchiver.h>
#include "AppKit/IMCustomObject.h"
#include "IMConnectors.h"
#if GNU_RUNTIME
#include <objc/objc-api.h>
#include <objc/Protocol.h>
#include <objc/encoding.h>
#else /* NeXT_RUNTIME */
#include <objc/objc-class.h>
#include <extensions/objc-api.h>
#include <extensions/encoding.h>
#endif
static void
object_set_instance_variable (id anObject,
const char* variableName,

View file

@ -24,7 +24,7 @@
*/
#import <Foundation/NSObjCRuntime.h>
#include <extensions/GMArchiver.h>
#include <AppKit/GMArchiver.h>
#include "AppKit/IMCustomObject.h"
@implementation NSObject(ModelUnarchiving)

View file

@ -28,7 +28,7 @@
#import <Foundation/NSFileManager.h>
#import <Foundation/NSPathUtilities.h>
#include <extensions/GMArchiver.h>
#include <AppKit/GMArchiver.h>
#include "AppKit/IMLoading.h"
#include "AppKit/IMCustomObject.h"

View file

@ -32,7 +32,7 @@
#import <Foundation/NSNotification.h>
#import <AppKit/AppKit.h>
#import <extensions/GMArchiver.h>
#import <AppKit/GMArchiver.h>
#import "AppKit/IMLoading.h"
#import "IBClasses.h"
#import "Translator.h"

View file

@ -47,7 +47,7 @@
#include <AppKit/IMLoading.h>
#include <AppKit/GMAppKit.h>
#include <extensions/GMArchiver.h>
#include <AppKit/GMArchiver.h>

View file

@ -44,7 +44,7 @@
#include <Foundation/NSFileManager.h>
#include <AppKit/NSMatrix.h>
#include <AppKit/IMLoading.h>
#include <extensions/GMArchiver.h>
#include <AppKit/GMArchiver.h>
// toDo:
// - interactive directory creation in SavePanel