mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
([Coder -initForWritingToStream:withFormatVersion:cStreamClass:
cStreamFormatVersion:]): New method. ([Coder -initForWritingToFile:withFormatVersion:cStreamClass: cStreamFormatVersion:]): New method. ([Coder -initForWritingToFile:filenamewithCStreamClass:cStreamClass]): New method. ([Coder +encodeRootObject:withName:nametoStream:]): New method. ([Coder +encodeRootObject:withName:nametoFile:filename]): New method. ([Coder +decodeObjectWithName:namefromStream:]): New method. ([Coder +decodeObjectWithName:namefromFile:filename]): New method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@819 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6991e266a7
commit
8675874d91
1 changed files with 88 additions and 49 deletions
137
Source/Coder.m
137
Source/Coder.m
|
@ -157,8 +157,8 @@ my_object_is_class(id object)
|
||||||
|
|
||||||
/* Initialization. */
|
/* Initialization. */
|
||||||
|
|
||||||
/* This is the designated sub-initializer.
|
/* This is the designated initializer.
|
||||||
Don't call it yourself.
|
But, don't call it yourself.
|
||||||
Do override it and call [super...] in subclasses. */
|
Do override it and call [super...] in subclasses. */
|
||||||
- _initWithCStream: (id <CStreaming>) cs
|
- _initWithCStream: (id <CStreaming>) cs
|
||||||
formatVersion: (int) version
|
formatVersion: (int) version
|
||||||
|
@ -181,6 +181,22 @@ my_object_is_class(id object)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is the designated sub-initializer for all "writing" coders. */
|
||||||
|
- initForWritingToStream: (id <Streaming>) s
|
||||||
|
withFormatVersion: (int) version
|
||||||
|
cStreamClass: (Class) cStreamClass
|
||||||
|
cStreamFormatVersion: (int) cStreamFormatVersion
|
||||||
|
{
|
||||||
|
[self _initWithCStream: [[cStreamClass alloc]
|
||||||
|
initForWritingToStream: s
|
||||||
|
withFormatVersion: cStreamFormatVersion]
|
||||||
|
formatVersion: version
|
||||||
|
isDecoding: NO];
|
||||||
|
[self writeSignature];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is the designated sub-initializer for all "reading" coders. */
|
||||||
+ coderReadingFromStream: (id <Streaming>) stream
|
+ coderReadingFromStream: (id <Streaming>) stream
|
||||||
{
|
{
|
||||||
id cs = [CStream cStreamReadingFromStream: stream];
|
id cs = [CStream cStreamReadingFromStream: stream];
|
||||||
|
@ -199,54 +215,43 @@ my_object_is_class(id object)
|
||||||
return [new_coder autorelease];
|
return [new_coder autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ coderReadingFromFile: (id <String>) filename
|
/* ..Writing... methods */
|
||||||
{
|
|
||||||
return [self coderReadingFromStream:
|
|
||||||
[[[StdioStream alloc] initWithFilename:filename fmode:"r"]
|
|
||||||
autorelease]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- initForReadingFromStream: (id <Streaming>) stream
|
|
||||||
formatVersion: (int)version
|
|
||||||
{
|
|
||||||
[self notImplemented:_cmd];
|
|
||||||
[self _initWithCStream: [[[[[self class] defaultCStreamClass] alloc]
|
|
||||||
initForWritingToStream: stream]
|
|
||||||
autorelease]
|
|
||||||
formatVersion: version
|
|
||||||
isDecoding: YES];
|
|
||||||
/* Model this after [CStream -initForReading...] */
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- initForReadingFromStream: (id <Streaming>) s
|
|
||||||
{
|
|
||||||
return [self initForReadingFromStream: s
|
|
||||||
formatVersion: DEFAULT_FORMAT_VERSION];
|
|
||||||
}
|
|
||||||
|
|
||||||
- initForReadingFromFile: (id <String>) filename
|
|
||||||
{
|
|
||||||
return [self initForReadingFromStream:
|
|
||||||
[StdioStream streamWithFilename: filename
|
|
||||||
fmode: "r"]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- initForWritingToStream: (id <Streaming>) s
|
- initForWritingToStream: (id <Streaming>) s
|
||||||
formatVersion: (int) version
|
withCStreamClass: (Class) cStreamClass
|
||||||
{
|
{
|
||||||
[self _initWithCStream: [[[self class] defaultCStreamClass]
|
return [self initForWritingToStream: s
|
||||||
cStreamWritingToStream: s]
|
withFormatVersion: DEFAULT_FORMAT_VERSION
|
||||||
formatVersion: version
|
cStreamClass: cStreamClass
|
||||||
isDecoding: NO];
|
cStreamFormatVersion: [cStreamClass defaultFormatVersion]];
|
||||||
[self writeSignature];
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- initForWritingToStream: (id <Streaming>) s
|
- initForWritingToStream: (id <Streaming>) s
|
||||||
{
|
{
|
||||||
return [self initForWritingToStream: s
|
return [self initForWritingToStream: s
|
||||||
formatVersion: DEFAULT_FORMAT_VERSION];
|
withCStreamClass: [[self class] defaultCStreamClass]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- initForWritingToFile: (id <String>) filename
|
||||||
|
withFormatVersion: (int) version
|
||||||
|
cStreamClass: (Class) cStreamClass
|
||||||
|
cStreamFormatVersion: (int) cStreamFormatVersion
|
||||||
|
{
|
||||||
|
return [self initForWritingToStream: [StdioStream
|
||||||
|
streamWithFilename: filename
|
||||||
|
fmode: "w"]
|
||||||
|
withFormatVersion: version
|
||||||
|
cStreamClass: cStreamClass
|
||||||
|
cStreamFormatVersion: cStreamFormatVersion];
|
||||||
|
}
|
||||||
|
|
||||||
|
- initForWritingToFile: (id <String>) filename
|
||||||
|
withCStreamClass: (Class) cStreamClass
|
||||||
|
{
|
||||||
|
return [self initForWritingToStream: [StdioStream
|
||||||
|
streamWithFilename: filename
|
||||||
|
fmode: "w"]
|
||||||
|
withCStreamClass: cStreamClass];
|
||||||
}
|
}
|
||||||
|
|
||||||
- initForWritingToFile: (id <String>) filename
|
- initForWritingToFile: (id <String>) filename
|
||||||
|
@ -269,26 +274,60 @@ my_object_is_class(id object)
|
||||||
fmode: "w"]];
|
fmode: "w"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- init
|
+ (BOOL) encodeRootObject: anObject
|
||||||
|
withName: (id <String>) name
|
||||||
|
toStream: (id <Streaming>)stream
|
||||||
{
|
{
|
||||||
[self shouldNotImplement:_cmd];
|
id c = [[Coder alloc] initForWritingToStream: stream];
|
||||||
return self;
|
[c encodeRootObject: anObject withName: name];
|
||||||
|
[c closeCoder];
|
||||||
|
[c release];
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ decodeObjectFromStream: (id <Streaming>)stream
|
+ (BOOL) encodeRootObject: anObject
|
||||||
|
withName: (id <String>) name
|
||||||
|
toFile: (id <String>) filename
|
||||||
|
{
|
||||||
|
return [self encodeRootObject: anObject
|
||||||
|
withName: name
|
||||||
|
toStream: [StdioStream streamWithFilename: filename
|
||||||
|
fmode: "w"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ..Reading... methods */
|
||||||
|
|
||||||
|
+ coderReadingFromFile: (id <String>) filename
|
||||||
|
{
|
||||||
|
return [self coderReadingFromStream:
|
||||||
|
[StdioStream streamWithFilename: filename
|
||||||
|
fmode: "r"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ decodeObjectWithName: (id <String> *) name
|
||||||
|
fromStream: (id <Streaming>)stream;
|
||||||
{
|
{
|
||||||
id c, o;
|
id c, o;
|
||||||
c = [self coderReadingFromStream:stream];
|
c = [self coderReadingFromStream:stream];
|
||||||
[c decodeObjectAt: &o withName: NULL];
|
[c decodeObjectAt: &o withName: name];
|
||||||
return [o autorelease];
|
return [o autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ decodeObjectFromFile: (id <String>) filename
|
+ decodeObjectWithName: (id <String> *) name
|
||||||
|
fromFile: (id <String>) filename;
|
||||||
{
|
{
|
||||||
return [self decodeObjectFromStream:
|
return [self decodeObjectWithName: name
|
||||||
|
fromStream:
|
||||||
[StdioStream streamWithFilename:filename fmode: "r"]];
|
[StdioStream streamWithFilename:filename fmode: "r"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- init
|
||||||
|
{
|
||||||
|
/* Or should we provide some kind of default? */
|
||||||
|
[self shouldNotImplement:_cmd];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Functions and methods for keeping cross-references
|
/* Functions and methods for keeping cross-references
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue