1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ValueArray.h Sun Jul 13 10:45:42 2008 -0700
1.3 @@ -0,0 +1,49 @@
1.4 +//
1.5 +// ValueArray.h
1.6 +// MYUtilities
1.7 +//
1.8 +// Copyright 2008 Jens Alfke. All rights reserved.
1.9 +//
1.10 +
1.11 +#import <Cocoa/Cocoa.h>
1.12 +
1.13 +
1.14 +@interface ValueArray : NSObject <NSCoding>
1.15 +{
1.16 + unsigned _count;
1.17 + size_t _valueSize;
1.18 +}
1.19 +
1.20 ++ (ValueArray*) valueArrayWithCount: (unsigned)count valueSize: (size_t)valueSize;
1.21 +
1.22 +- (unsigned) count;
1.23 +- (size_t) valueSize;
1.24 +- (const void*) valueAtIndex: (unsigned)i;
1.25 +- (void) getValue: (void*)value atIndex: (unsigned)i;
1.26 +- (void) setValue: (const void*)value atIndex: (unsigned)i;
1.27 +
1.28 +@end
1.29 +
1.30 +
1.31 +#define DeclareValueArrayOf(CAPTYPE,TYPE) \
1.32 + @interface CAPTYPE##Array : ValueArray \
1.33 + + (CAPTYPE##Array*) TYPE##ArrayWithCount: (unsigned)count; \
1.34 + - (TYPE) TYPE##AtIndex: (unsigned)index; \
1.35 + - (void) set##CAPTYPE: (TYPE)value atIndex: (unsigned)index; \
1.36 + @end
1.37 +
1.38 +#define ImplementValueArrayOf(CAPTYPE,TYPE) \
1.39 + @implementation CAPTYPE##Array \
1.40 + + (CAPTYPE##Array*) TYPE##Array##WithCount: (unsigned)count \
1.41 + {return (id)[super valueArrayWithCount: count valueSize: sizeof(TYPE)];} \
1.42 + - (TYPE) TYPE##AtIndex: (unsigned)i; \
1.43 + {NSParameterAssert(i<_count); return ((const TYPE*)object_getIndexedIvars(self))[i];}\
1.44 + - (void) set##CAPTYPE: (TYPE)value atIndex: (unsigned)i \
1.45 + {NSParameterAssert(i<_count); ((TYPE*)object_getIndexedIvars(self))[i] = value;}\
1.46 + @end
1.47 +
1.48 +
1.49 +// Declares IntArray class
1.50 +DeclareValueArrayOf(Int,int)
1.51 +
1.52 +DeclareValueArrayOf(Double,double)