jens@0: // jens@0: // ValueArray.h jens@0: // MYUtilities jens@0: // jens@0: // Copyright 2008 Jens Alfke. All rights reserved. jens@0: // jens@0: jens@0: #import jens@0: jens@0: jens@0: @interface ValueArray : NSObject jens@0: { jens@0: unsigned _count; jens@0: size_t _valueSize; jens@0: } jens@0: jens@0: + (ValueArray*) valueArrayWithCount: (unsigned)count valueSize: (size_t)valueSize; jens@0: jens@0: - (unsigned) count; jens@0: - (size_t) valueSize; jens@0: - (const void*) valueAtIndex: (unsigned)i; jens@0: - (void) getValue: (void*)value atIndex: (unsigned)i; jens@0: - (void) setValue: (const void*)value atIndex: (unsigned)i; jens@0: jens@0: @end jens@0: jens@0: jens@0: #define DeclareValueArrayOf(CAPTYPE,TYPE) \ jens@0: @interface CAPTYPE##Array : ValueArray \ jens@0: + (CAPTYPE##Array*) TYPE##ArrayWithCount: (unsigned)count; \ jens@0: - (TYPE) TYPE##AtIndex: (unsigned)index; \ jens@0: - (void) set##CAPTYPE: (TYPE)value atIndex: (unsigned)index; \ jens@0: @end jens@0: jens@0: #define ImplementValueArrayOf(CAPTYPE,TYPE) \ jens@0: @implementation CAPTYPE##Array \ jens@0: + (CAPTYPE##Array*) TYPE##Array##WithCount: (unsigned)count \ jens@0: {return (id)[super valueArrayWithCount: count valueSize: sizeof(TYPE)];} \ jens@0: - (TYPE) TYPE##AtIndex: (unsigned)i; \ jens@0: {NSParameterAssert(i<_count); return ((const TYPE*)object_getIndexedIvars(self))[i];}\ jens@0: - (void) set##CAPTYPE: (TYPE)value atIndex: (unsigned)i \ jens@0: {NSParameterAssert(i<_count); ((TYPE*)object_getIndexedIvars(self))[i] = value;}\ jens@0: @end jens@0: jens@0: jens@0: // Declares IntArray class jens@0: DeclareValueArrayOf(Int,int) jens@0: jens@0: DeclareValueArrayOf(Double,double)