author | Jens Alfke <jens@mooseyard.com> |
Tue May 05 11:09:06 2009 -0700 (2009-05-05) | |
changeset 28 | 206903ba35a5 |
permissions | -rw-r--r-- |
jens@0 | 1 |
// |
jens@0 | 2 |
// ValueArray.h |
jens@0 | 3 |
// MYUtilities |
jens@0 | 4 |
// |
jens@0 | 5 |
// Copyright 2008 Jens Alfke. All rights reserved. |
jens@0 | 6 |
// |
jens@0 | 7 |
|
jens@0 | 8 |
#import <Cocoa/Cocoa.h> |
jens@0 | 9 |
|
jens@0 | 10 |
|
jens@0 | 11 |
@interface ValueArray : NSObject <NSCoding> |
jens@0 | 12 |
{ |
jens@0 | 13 |
unsigned _count; |
jens@0 | 14 |
size_t _valueSize; |
jens@0 | 15 |
} |
jens@0 | 16 |
|
jens@0 | 17 |
+ (ValueArray*) valueArrayWithCount: (unsigned)count valueSize: (size_t)valueSize; |
jens@0 | 18 |
|
jens@0 | 19 |
- (unsigned) count; |
jens@0 | 20 |
- (size_t) valueSize; |
jens@0 | 21 |
- (const void*) valueAtIndex: (unsigned)i; |
jens@0 | 22 |
- (void) getValue: (void*)value atIndex: (unsigned)i; |
jens@0 | 23 |
- (void) setValue: (const void*)value atIndex: (unsigned)i; |
jens@0 | 24 |
|
jens@0 | 25 |
@end |
jens@0 | 26 |
|
jens@0 | 27 |
|
jens@0 | 28 |
#define DeclareValueArrayOf(CAPTYPE,TYPE) \ |
jens@0 | 29 |
@interface CAPTYPE##Array : ValueArray \ |
jens@0 | 30 |
+ (CAPTYPE##Array*) TYPE##ArrayWithCount: (unsigned)count; \ |
jens@0 | 31 |
- (TYPE) TYPE##AtIndex: (unsigned)index; \ |
jens@0 | 32 |
- (void) set##CAPTYPE: (TYPE)value atIndex: (unsigned)index; \ |
jens@0 | 33 |
@end |
jens@0 | 34 |
|
jens@0 | 35 |
#define ImplementValueArrayOf(CAPTYPE,TYPE) \ |
jens@0 | 36 |
@implementation CAPTYPE##Array \ |
jens@0 | 37 |
+ (CAPTYPE##Array*) TYPE##Array##WithCount: (unsigned)count \ |
jens@0 | 38 |
{return (id)[super valueArrayWithCount: count valueSize: sizeof(TYPE)];} \ |
jens@0 | 39 |
- (TYPE) TYPE##AtIndex: (unsigned)i; \ |
jens@0 | 40 |
{NSParameterAssert(i<_count); return ((const TYPE*)object_getIndexedIvars(self))[i];}\ |
jens@0 | 41 |
- (void) set##CAPTYPE: (TYPE)value atIndex: (unsigned)i \ |
jens@0 | 42 |
{NSParameterAssert(i<_count); ((TYPE*)object_getIndexedIvars(self))[i] = value;}\ |
jens@0 | 43 |
@end |
jens@0 | 44 |
|
jens@0 | 45 |
|
jens@0 | 46 |
// Declares IntArray class |
jens@0 | 47 |
DeclareValueArrayOf(Int,int) |
jens@0 | 48 |
|
jens@0 | 49 |
DeclareValueArrayOf(Double,double) |