1995-03-22 22:29:33 +00:00
|
|
|
/* NSValue.h - Object encapsulation for C types.
|
|
|
|
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Date: Mar 1995
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C Class Library.
|
|
|
|
|
|
|
|
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; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSConcreteValue.h>
|
|
|
|
#include <Foundation/NSCoder.h>
|
1995-03-22 22:29:33 +00:00
|
|
|
|
|
|
|
@implementation NSValue
|
|
|
|
|
|
|
|
// NSCopying
|
1995-04-03 20:07:18 +00:00
|
|
|
/* deepening is done by concrete subclasses */
|
1995-03-22 22:29:33 +00:00
|
|
|
- deepen
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)copyWithZone:(NSZone *)zone
|
|
|
|
{
|
|
|
|
if (NSShouldRetainWithZone(self, zone))
|
|
|
|
return [self retain];
|
|
|
|
else
|
|
|
|
return [[super copyWithZone:zone] deepen];
|
|
|
|
}
|
|
|
|
|
1995-04-03 20:07:18 +00:00
|
|
|
/* Returns the concrete class associated with the type encoding */
|
|
|
|
+ (Class)valueClassWithObjCType:(const char *)type
|
1995-03-22 22:29:33 +00:00
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
Class theClass = [NSConcreteValue class];
|
|
|
|
|
|
|
|
/* Let someone else deal with this error */
|
|
|
|
if (!type)
|
|
|
|
return theClass;
|
|
|
|
|
|
|
|
if (strcmp(@encode(id), type) == 0)
|
|
|
|
theClass = [NSNonretainedObjectValue class];
|
|
|
|
else if (strcmp(@encode(NSPoint), type) == 0)
|
|
|
|
theClass = [NSPointValue class];
|
|
|
|
else if (strcmp(@encode(void *), type) == 0)
|
|
|
|
theClass = [NSPointerValue class];
|
|
|
|
else if (strcmp(@encode(NSRect), type) == 0)
|
|
|
|
theClass = [NSRectValue class];
|
|
|
|
else if (strcmp(@encode(NSSize), type) == 0)
|
|
|
|
theClass = [NSSizeValue class];
|
1995-03-22 22:29:33 +00:00
|
|
|
|
1995-04-03 20:07:18 +00:00
|
|
|
return theClass;
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 20:07:18 +00:00
|
|
|
// Allocating and Initializing
|
|
|
|
|
1995-03-22 22:29:33 +00:00
|
|
|
+ (NSValue *)value:(const void *)value
|
|
|
|
withObjCType:(const char *)type
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
Class theClass = [self valueClassWithObjCType:type];
|
|
|
|
return [[[theClass alloc] initValue:value withObjCType:type]
|
|
|
|
autorelease];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSValue *)valueWithNonretainedObject: (id)anObject
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
return [[[NSNonretainedObjectValue alloc]
|
|
|
|
initValue:&anObject withObjCType:@encode(id)]
|
|
|
|
autorelease];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSValue *)valueWithPoint:(NSPoint)point
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
return [[[NSPointValue alloc]
|
|
|
|
initValue:&point withObjCType:@encode(NSPoint)]
|
|
|
|
autorelease];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSValue *)valueWithPointer:(const void *)pointer
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
return [[[NSPointerValue alloc]
|
|
|
|
initValue:&pointer withObjCType:@encode(void*)]
|
|
|
|
autorelease];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSValue *)valueWithRect:(NSRect)rect
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
return [[[NSRectValue alloc] initValue:&rect withObjCType:@encode(NSRect)]
|
|
|
|
autorelease];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSValue *)valueWithSize:(NSSize)size
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
return [[[NSSizeValue alloc] initValue:&size withObjCType:@encode(NSSize)]
|
|
|
|
autorelease];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accessing Data
|
1995-04-03 20:07:18 +00:00
|
|
|
/* All the rest of these methods must be implemented by a subclass */
|
1995-03-22 22:29:33 +00:00
|
|
|
- (void)getValue:(void *)value
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
[self doesNotRecognizeSelector:_cmd];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (const char *)objCType
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
[self doesNotRecognizeSelector:_cmd];
|
|
|
|
return 0;
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 20:07:18 +00:00
|
|
|
// FIXME: Is this an error or an exception???
|
1995-03-22 22:29:33 +00:00
|
|
|
- (id)nonretainedObjectValue
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
[self doesNotRecognizeSelector:_cmd];
|
|
|
|
return 0;
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void *)pointerValue
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
[self doesNotRecognizeSelector:_cmd];
|
|
|
|
return 0;
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)rectValue
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
[self doesNotRecognizeSelector:_cmd];
|
|
|
|
return NSMakeRect(0,0,0,0);
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)sizeValue
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
[self doesNotRecognizeSelector:_cmd];
|
|
|
|
return NSMakeSize(0,0);
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPoint)pointValue
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
[self doesNotRecognizeSelector:_cmd];
|
|
|
|
return NSMakePoint(0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NSCoding (done by subclasses)
|
|
|
|
- classForCoder
|
|
|
|
{
|
|
|
|
return [self class];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)encodeWithCoder:(NSCoder *)coder
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
//FIXME [super encodeWithCoder:coder];
|
1995-03-22 22:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithCoder:(NSCoder *)coder
|
|
|
|
{
|
1995-04-03 20:07:18 +00:00
|
|
|
//FIXME self = [super initWithCoder:coder];
|
1995-03-22 22:29:33 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|