mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
More tidying up for consistency with gui libs
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8568 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
47218c499c
commit
559db76abd
9 changed files with 137 additions and 105 deletions
12
ChangeLog
12
ChangeLog
|
@ -2,6 +2,18 @@
|
|||
|
||||
* Source/GSXML.m: ([-GSXMLDocument setRoot:]) set root node to be
|
||||
owned by libxml, so we don't free it's memory ourselves.
|
||||
* Headers/gnustep/base/NSValue.h: Added range methods.
|
||||
* Source/GNUmakefile: Rename value files to GS prefix and remove
|
||||
concrete value header.
|
||||
* Source/Makefile.postamble: Build GS value files. rather than NS
|
||||
* Source/NSValue.m: Added range meethods and updated for change to
|
||||
naming conventions.
|
||||
* Testing/values.m: Added range check
|
||||
* Source/GSTemplateValue.m: Renamed for consistency.
|
||||
* Source/GSValue.m: ditto
|
||||
* Headers/gnustep/base/NSConcreteValue.h: private info removed
|
||||
* Source/NSCTemplateValue.m: Renamed for consistency
|
||||
* Source/NSConcreteValue.m: ditto
|
||||
|
||||
2001-01-10 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/* NSConcreteValue - Interface for Concrete NSValue classes
|
||||
|
||||
Copyright (C) 1993,1994,1995,1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Mar 1995
|
||||
|
||||
This file is part of the GNUstep Base 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSConcreteValue_OBJECT_INCLUDE
|
||||
#define __NSConcreteValue_OBJECT_INCLUDE
|
||||
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
@interface NSConcreteValue : NSValue
|
||||
{
|
||||
void *data;
|
||||
char *objctype;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSNonretainedObjectValue : NSValue
|
||||
{
|
||||
id data;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSPointValue : NSValue
|
||||
{
|
||||
NSPoint data;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSPointerValue : NSValue
|
||||
{
|
||||
void *data;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSRectValue : NSValue
|
||||
{
|
||||
NSRect data;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSSizeValue : NSValue
|
||||
{
|
||||
NSSize data;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -37,6 +37,7 @@
|
|||
+ (NSValue*) valueWithNonretainedObject: (id)anObject;
|
||||
+ (NSValue*) valueWithPoint: (NSPoint)point;
|
||||
+ (NSValue*) valueWithPointer: (const void*)pointer;
|
||||
+ (NSValue*) valueWithRange: (NSRange)range;
|
||||
+ (NSValue*) valueWithRect: (NSRect)rect;
|
||||
+ (NSValue*) valueWithSize: (NSSize)size;
|
||||
|
||||
|
@ -54,6 +55,7 @@
|
|||
- (const char*) objCType;
|
||||
- (id) nonretainedObjectValue;
|
||||
- (void*) pointerValue;
|
||||
- (NSRange) rangeValue;
|
||||
- (NSRect) rectValue;
|
||||
- (NSSize) sizeValue;
|
||||
- (NSPoint) pointValue;
|
||||
|
|
|
@ -152,6 +152,7 @@ GSHTTPURLHandle.m \
|
|||
GSMime.m \
|
||||
GSSet.m \
|
||||
GSString.m \
|
||||
GSValue.m \
|
||||
NSAttributedString.m \
|
||||
NSArchiver.m \
|
||||
NSArray.m \
|
||||
|
@ -165,7 +166,6 @@ NSCharacterSet.m \
|
|||
NSClassDescription.m \
|
||||
NSCoder.m \
|
||||
NSCopyObject.m \
|
||||
NSConcreteValue.m \
|
||||
NSCountedSet.m \
|
||||
NSConnection.m \
|
||||
NSData.m \
|
||||
|
@ -244,8 +244,8 @@ BASE_MFILES += GSFFCallInvocation.m
|
|||
endif
|
||||
|
||||
NSVALUE_MFILES = \
|
||||
NSValue0.m NSValue1.m NSValue2.m NSValue3.m \
|
||||
NSValue4.m
|
||||
GSValue0.m GSValue1.m GSValue2.m GSValue3.m \
|
||||
GSValue4.m GSValue5.m
|
||||
NSNUMBER_MFILES = \
|
||||
NSNumber0.m NSNumber1.m NSNumber2.m NSNumber3.m \
|
||||
NSNumber4.m NSNumber5.m NSNumber6.m NSNumber7.m \
|
||||
|
@ -254,7 +254,7 @@ NSNUMBER_MFILES = \
|
|||
|
||||
BASE_OTHER_SRCFILES = \
|
||||
NSConcreteNumber.m \
|
||||
NSCTemplateValue.m \
|
||||
GSTemplateValue.m \
|
||||
dld-load.h \
|
||||
hpux-load.h \
|
||||
null-load.h \
|
||||
|
@ -278,7 +278,6 @@ NSCharacterSet.h \
|
|||
NSClassDescription.h \
|
||||
NSCoder.h \
|
||||
NSConcreteNumber.h \
|
||||
NSConcreteValue.h \
|
||||
NSConnection.h \
|
||||
NSData.h \
|
||||
NSDate.h \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# line 1 "NSCTemplateValue.m" /* So gdb knows which file we are in */
|
||||
/* NSCTemplateValue - Object encapsulation for C types.
|
||||
# line 1 "GSTemplateValue.m" /* So gdb knows which file we are in */
|
||||
/* GSTemplateValue - Object encapsulation for C types.
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
|
@ -23,38 +23,73 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <Foundation/NSConcreteValue.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSObjCRuntime.h>
|
||||
#include <base/preface.h>
|
||||
|
||||
|
||||
/* This file should be run through a preprocessor with the macro TYPE_ORDER
|
||||
defined to a number from 0 to 4 cooresponding to each value type */
|
||||
#if TYPE_ORDER == 0
|
||||
# define NSCTemplateValue NSNonretainedObjectValue
|
||||
@interface GSNonretainedObjectValue : NSValue
|
||||
{
|
||||
id data;
|
||||
}
|
||||
@end
|
||||
# define GSTemplateValue GSNonretainedObjectValue
|
||||
# define TYPE_METHOD nonretainedObjectValue
|
||||
# define TYPE_NAME id
|
||||
#elif TYPE_ORDER == 1
|
||||
# define NSCTemplateValue NSPointValue
|
||||
@interface GSPointValue : NSValue
|
||||
{
|
||||
NSPoint data;
|
||||
}
|
||||
@end
|
||||
# define GSTemplateValue GSPointValue
|
||||
# define TYPE_METHOD pointValue
|
||||
# define TYPE_NAME NSPoint
|
||||
#elif TYPE_ORDER == 2
|
||||
# define NSCTemplateValue NSPointerValue
|
||||
@interface GSPointerValue : NSValue
|
||||
{
|
||||
void *data;
|
||||
}
|
||||
@end
|
||||
# define GSTemplateValue GSPointerValue
|
||||
# define TYPE_METHOD pointerValue
|
||||
# define TYPE_NAME void *
|
||||
#elif TYPE_ORDER == 3
|
||||
# define NSCTemplateValue NSRectValue
|
||||
# define GSTemplateValue GSRangeValue
|
||||
@interface GSRangeValue : NSValue
|
||||
{
|
||||
NSRange data;
|
||||
}
|
||||
@end
|
||||
# define TYPE_METHOD rangeValue
|
||||
# define TYPE_NAME NSRange
|
||||
#elif TYPE_ORDER == 4
|
||||
@interface GSRectValue : NSValue
|
||||
{
|
||||
NSRect data;
|
||||
}
|
||||
@end
|
||||
# define GSTemplateValue GSRectValue
|
||||
# define TYPE_METHOD rectValue
|
||||
# define TYPE_NAME NSRect
|
||||
#elif TYPE_ORDER == 4
|
||||
# define NSCTemplateValue NSSizeValue
|
||||
#elif TYPE_ORDER == 5
|
||||
@interface GSSizeValue : NSValue
|
||||
{
|
||||
NSSize data;
|
||||
}
|
||||
@end
|
||||
# define GSTemplateValue GSSizeValue
|
||||
# define TYPE_METHOD sizeValue
|
||||
# define TYPE_NAME NSSize
|
||||
#endif
|
||||
|
||||
@implementation NSCTemplateValue
|
||||
@implementation GSTemplateValue
|
||||
|
||||
// Allocating and Initializing
|
||||
|
||||
|
@ -110,13 +145,19 @@
|
|||
else
|
||||
return NO;
|
||||
#elif TYPE_ORDER == 3
|
||||
if (data.location == val.location
|
||||
&& data.length == val.length)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
#elif TYPE_ORDER == 4
|
||||
if (data.origin.x == val.origin.x && data.origin.y == val.origin.y
|
||||
&& data.size.width == val.size.width
|
||||
&& data.size.height == val.size.height)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
#elif TYPE_ORDER == 4
|
||||
#elif TYPE_ORDER == 5
|
||||
if (data.width == val.width && data.height == val.height)
|
||||
return YES;
|
||||
else
|
||||
|
@ -145,6 +186,8 @@
|
|||
#elif TYPE_ORDER == 2
|
||||
return (unsigned)(gsaddr)data;
|
||||
#elif TYPE_ORDER == 3
|
||||
return (data.length ^ data.location);
|
||||
#elif TYPE_ORDER == 4
|
||||
union {
|
||||
double d;
|
||||
unsigned char c[sizeof(double)];
|
||||
|
@ -156,7 +199,7 @@
|
|||
for (i = 0; i < sizeof(double); i++)
|
||||
hash += val.c[i];
|
||||
return hash;
|
||||
#elif TYPE_ORDER == 4
|
||||
#elif TYPE_ORDER == 5
|
||||
union {
|
||||
double d;
|
||||
unsigned char c[sizeof(double)];
|
||||
|
@ -191,8 +234,10 @@
|
|||
#elif TYPE_ORDER == 2
|
||||
return [NSString stringWithFormat: @"{pointer = %p;}", data];
|
||||
#elif TYPE_ORDER == 3
|
||||
return NSStringFromRect(data);
|
||||
return NSStringFromRange(data);
|
||||
#elif TYPE_ORDER == 4
|
||||
return NSStringFromRect(data);
|
||||
#elif TYPE_ORDER == 5
|
||||
return NSStringFromSize(data);
|
||||
#endif
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* NSConcreteValue - Object encapsulation for C types.
|
||||
/* GSValue - Object encapsulation for C types.
|
||||
Copyright (C) 1993,1994,1995,1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <Foundation/NSConcreteValue.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
@ -31,11 +31,18 @@
|
|||
#include <Foundation/NSObjCRuntime.h>
|
||||
#include <base/preface.h>
|
||||
|
||||
@interface GSValue : NSValue
|
||||
{
|
||||
void *data;
|
||||
char *objctype;
|
||||
}
|
||||
@end
|
||||
|
||||
/* This is the real, general purpose value object. I've implemented all the
|
||||
methods here (like pointValue) even though most likely, other concrete
|
||||
subclasses were created to handle these types */
|
||||
|
||||
@implementation NSConcreteValue
|
||||
@implementation GSValue
|
||||
|
||||
// Allocating and Initializing
|
||||
|
||||
|
@ -108,13 +115,13 @@
|
|||
return NO;
|
||||
if (GSObjCClass(aValue) != GSObjCClass(self))
|
||||
return NO;
|
||||
if (strcmp(objctype, ((NSConcreteValue*)aValue)->objctype) != 0)
|
||||
if (strcmp(objctype, ((GSValue*)aValue)->objctype) != 0)
|
||||
return NO;
|
||||
else
|
||||
{
|
||||
unsigned size = objc_sizeof_type(objctype);
|
||||
|
||||
if (memcmp(((NSConcreteValue*)aValue)->data, data, size) != 0)
|
||||
if (memcmp(((GSValue*)aValue)->data, data, size) != 0)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
|
@ -108,7 +108,7 @@ after-uninstall::
|
|||
# Things to do after distcleaning
|
||||
after-distclean::
|
||||
rm -f mframe/mframe.h Foundation \
|
||||
NSNumber[0-9]*.m NSValue[0-9]*.m o_*_bas.m
|
||||
NSNumber[0-9]*.m GSValue[0-9]*.m o_*_bas.m
|
||||
rm -rf $(GNUSTEP_TARGET_DIR)/config.h
|
||||
rm -rf $(GNUSTEP_TARGET_DIR)/mframe.h
|
||||
rm -rf $(GNUSTEP_TARGET_DIR)/GSConfig.h
|
||||
|
@ -121,10 +121,10 @@ after-distclean::
|
|||
# after-check::
|
||||
|
||||
# Creation of NSValue and NSNumber concrete classes from templates
|
||||
$(NSVALUE_MFILES) : NSCTemplateValue.m
|
||||
$(NSVALUE_MFILES) : GSTemplateValue.m
|
||||
rm -f $@
|
||||
echo '#define TYPE_ORDER' `echo $@ | sed -e "s,[^0-9],,g"` >$@
|
||||
cat $(srcdir)/NSCTemplateValue.m >> $@
|
||||
cat $(srcdir)/GSTemplateValue.m >> $@
|
||||
$(NSNUMBER_MFILES) : NSConcreteNumber.m
|
||||
rm -f $@
|
||||
echo '#define TYPE_ORDER' `echo $@ | sed -e "s,[^0-9],,g"` >$@
|
||||
|
|
|
@ -23,16 +23,25 @@
|
|||
|
||||
#include <config.h>
|
||||
#include <base/preface.h>
|
||||
#include <Foundation/NSConcreteValue.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSZone.h>
|
||||
|
||||
@class GSValue;
|
||||
@class GSNonretainedObjectValue;
|
||||
@class GSPointValue;
|
||||
@class GSPointerValue;
|
||||
@class GSRangeValue;
|
||||
@class GSRectValue;
|
||||
@class GSSizeValue;
|
||||
|
||||
static Class abstractClass;
|
||||
static Class concreteClass;
|
||||
static Class nonretainedObjectValueClass;
|
||||
static Class pointValueClass;
|
||||
static Class pointerValueClass;
|
||||
static Class rangeValueClass;
|
||||
static Class rectValueClass;
|
||||
static Class sizeValueClass;
|
||||
|
||||
|
@ -44,12 +53,13 @@ static Class sizeValueClass;
|
|||
if (self == [NSValue class])
|
||||
{
|
||||
abstractClass = self;
|
||||
concreteClass = [NSConcreteValue class];
|
||||
nonretainedObjectValueClass = [NSNonretainedObjectValue class];
|
||||
pointValueClass = [NSPointValue class];
|
||||
pointerValueClass = [NSPointerValue class];
|
||||
rectValueClass = [NSRectValue class];
|
||||
sizeValueClass = [NSSizeValue class];
|
||||
concreteClass = [GSValue class];
|
||||
nonretainedObjectValueClass = [GSNonretainedObjectValue class];
|
||||
pointValueClass = [GSPointValue class];
|
||||
pointerValueClass = [GSPointerValue class];
|
||||
rangeValueClass = [GSRangeValue class];
|
||||
rectValueClass = [GSRectValue class];
|
||||
sizeValueClass = [GSSizeValue class];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,6 +106,8 @@ static Class sizeValueClass;
|
|||
theClass = pointValueClass;
|
||||
else if (strcmp(@encode(void *), type) == 0)
|
||||
theClass = pointerValueClass;
|
||||
else if (strcmp(@encode(NSRange), type) == 0)
|
||||
theClass = rangeValueClass;
|
||||
else if (strcmp(@encode(NSRect), type) == 0)
|
||||
theClass = rectValueClass;
|
||||
else if (strcmp(@encode(NSSize), type) == 0)
|
||||
|
@ -132,7 +144,7 @@ static Class sizeValueClass;
|
|||
{
|
||||
NSValue *theObj;
|
||||
|
||||
theObj = [NSNonretainedObjectValue allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [nonretainedObjectValueClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &anObject objCType: @encode(id)];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
@ -141,7 +153,7 @@ static Class sizeValueClass;
|
|||
{
|
||||
NSValue *theObj;
|
||||
|
||||
theObj = [NSPointValue allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [pointValueClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &point objCType: @encode(NSPoint)];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
@ -150,16 +162,25 @@ static Class sizeValueClass;
|
|||
{
|
||||
NSValue *theObj;
|
||||
|
||||
theObj = [NSPointerValue allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [pointerValueClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &pointer objCType: @encode(void*)];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSValue*) valueWithRange: (NSRange)range
|
||||
{
|
||||
NSValue *theObj;
|
||||
|
||||
theObj = [rangeValueClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &range objCType: @encode(NSRange)];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSValue*) valueWithRect: (NSRect)rect
|
||||
{
|
||||
NSValue *theObj;
|
||||
|
||||
theObj = [NSRectValue allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [rectValueClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &rect objCType: @encode(NSRect)];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
@ -168,7 +189,7 @@ static Class sizeValueClass;
|
|||
{
|
||||
NSValue *theObj;
|
||||
|
||||
theObj = [NSSizeValue allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [sizeValueClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &size objCType: @encode(NSSize)];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
@ -252,6 +273,12 @@ static Class sizeValueClass;
|
|||
return 0;
|
||||
}
|
||||
|
||||
- (NSRange) rangeValue
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NSMakeRange(0,0);
|
||||
}
|
||||
|
||||
- (NSRect) rectValue
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
int main()
|
||||
{
|
||||
NSPoint p;
|
||||
NSRange range;
|
||||
NSRect rect;
|
||||
NSValue *v1, *v2;
|
||||
NSNumber *nc, *ns, *n1, *n2, *n3, *n4, *n5;
|
||||
|
@ -78,6 +79,12 @@ printf("nc compare:ns is %d\n", [nc compare:ns]);
|
|||
v1 = [NSValue valueWithNonretainedObject:v2];
|
||||
[[v1 nonretainedObjectValue] getValue:&p];
|
||||
printf("point is %f %f\n", p.x, p.y);
|
||||
range = NSMakeRange(1, 103);
|
||||
range = NSIntersectionRange(range, NSMakeRange(2, 73));
|
||||
v1 = [NSValue valueWithRange:range];
|
||||
printf("Encoding for range is %s\n", [v1 objCType]);
|
||||
range = [v1 rangeValue];
|
||||
printf("Range is %u %u\n", range.location, range.length);
|
||||
|
||||
printf("Try getting a null NSValue, should get a NSLog error message:\n");
|
||||
v2 = [NSValue value:NULL withObjCType:@encode(int)];
|
||||
|
|
Loading…
Reference in a new issue