mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Added keyed geometry encoding methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18472 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ef6c24d415
commit
98ce6de425
3 changed files with 85 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
|||
2004-01-24 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* wHeaders/Foundation/NSKeyedArchiver.h:
|
||||
* Source/NSKeyedArchiver.m:
|
||||
Add keyed version of geometry encoding methods as pointed out by
|
||||
Fred Kiefer.
|
||||
|
||||
2004-01-24 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSKeyedArchiver.m:
|
||||
|
|
|
@ -352,5 +352,37 @@ willReplaceObject: (id)anObject
|
|||
|
||||
@end
|
||||
|
||||
@interface NSCoder (NSGeometryKeyedCoding)
|
||||
/**
|
||||
* Encodes an NSPoint object.
|
||||
*/
|
||||
- (void) encodePoint: (NSPoint)aPoint forKey: (NSString*)aKey;
|
||||
|
||||
/**
|
||||
* Encodes an NSRect object.
|
||||
*/
|
||||
- (void) encodeRect: (NSRect)aRect forKey: (NSString*)aKey;
|
||||
|
||||
/**
|
||||
* Encodes an NSSize object.
|
||||
*/
|
||||
- (void) encodeSize: (NSSize)aSize forKey: (NSString*)aKey;
|
||||
|
||||
/**
|
||||
* Decodes an NSPoint object.
|
||||
*/
|
||||
- (NSPoint) decodePointForKey: (NSString*)aKey;
|
||||
|
||||
/**
|
||||
* Decodes an NSRect object.
|
||||
*/
|
||||
- (NSRect) decodeRectForKey: (NSString*)aKey;
|
||||
|
||||
/**
|
||||
* Decodes an NSSize object.
|
||||
*/
|
||||
- (NSSize) decodeSizeForKey: (NSString*)aKey;
|
||||
@end
|
||||
|
||||
#endif /* STRICT_OPENSTEP */
|
||||
#endif /* __NSKeyedArchiver_h_GNUSTEP_BASE_INCLUDE*/
|
||||
|
|
|
@ -765,3 +765,49 @@ willReplaceObject: (id)anObject
|
|||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation NSCoder (NSGeometryKeyedCoding)
|
||||
- (void) encodePoint: (NSPoint)aPoint forKey: (NSString*)aKey
|
||||
{
|
||||
NSString *val;
|
||||
val = [NSString stringWithFormat: @"{%g, %g}", aPoint.x, aPoint.y];
|
||||
[self encodeObject: val forKey: aKey];
|
||||
}
|
||||
- (void) encodeRect: (NSRect)aRect forKey: (NSString*)aKey
|
||||
{
|
||||
NSString *val;
|
||||
val = [NSString stringWithFormat: @"{{%g, %g}, {%g, %g}}",
|
||||
aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height];
|
||||
[self encodeObject: val forKey: aKey];
|
||||
}
|
||||
- (void) encodeSize: (NSSize)aSize forKey: (NSString*)aKey
|
||||
{
|
||||
NSString *val;
|
||||
val = [NSString stringWithFormat: @"{%g, %g}", aSize.width, aSize.height];
|
||||
[self encodeObject: val forKey: aKey];
|
||||
}
|
||||
- (NSPoint) decodePointForKey: (NSString*)aKey
|
||||
{
|
||||
const char *val = [[self decodeObjectForKey: aKey] UTF8String];
|
||||
NSPoint aPoint;
|
||||
sscanf(val, "{%f, %f}", &aPoint.x, &aPoint.y);
|
||||
return aPoint;
|
||||
}
|
||||
- (NSRect) decodeRectForKey: (NSString*)aKey
|
||||
{
|
||||
const char *val = [[self decodeObjectForKey: aKey] UTF8String];
|
||||
NSRect aRect;
|
||||
sscanf(val, "{{%f, %f}, {%f, %f}}",
|
||||
&aRect.origin.x, &aRect.origin.y, &aRect.size.height, &aRect.size.height);
|
||||
return aRect;
|
||||
}
|
||||
- (NSSize) decodeSizeForKey: (NSString*)aKey
|
||||
{
|
||||
const char *val = [[self decodeObjectForKey: aKey] UTF8String];
|
||||
NSSize aSize;
|
||||
sscanf(val, "{%f, %f}", &aSize.height, &aSize.height);
|
||||
return aSize;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in a new issue