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