| 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software |
| 2 | * |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | * of this software and associated documentation files (the "Software"), to deal |
| 5 | * in the Software without restriction, including without limitation the rights |
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | * copies of the Software, and to permit persons to whom the Software is |
| 8 | * furnished to do so, subject to the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included in |
| 11 | * all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | * SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include "chipmunk/chipmunk_private.h"cxx . . $ `<file>/include/chipmunk/chipmunk_private.h`/ |
| 25 | |
| 26 | |
| 27 | cpArraycxx . . $ cpArray# * |
| 28 | cpArrayNewcxx . . $ cpArrayNew(f90d83c90697c3ae).(int size) |
| 29 | { |
| 30 | cpArraycxx . . $ cpArray# *arr = (cpArraycxx . . $ cpArray# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, sizeof(cpArraycxx . . $ cpArray#)); |
| 31 | |
| 32 | arr->numcxx . . $ cpArray#num. = 0; |
| 33 | arr->maxcxx . . $ cpArray#max. = (size ? size : 4); |
| 34 | arr->arrcxx . . $ cpArray#arr. = (void **)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(arr->maxcxx . . $ cpArray#max., sizeof(void*)); |
| 35 | |
| 36 | return arr; |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | cpArrayFreecxx . . $ cpArrayFree(9f115453462bfa05).(cpArraycxx . . $ cpArray# *arr) |
| 41 | { |
| 42 | if(arr){ |
| 43 | cpfreecxx . . $ `include/chipmunk/chipmunk.h:82:10`!(arr->arrcxx . . $ cpArray#arr.); |
| 44 | arr->arrcxx . . $ cpArray#arr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 45 | |
| 46 | cpfreecxx . . $ `include/chipmunk/chipmunk.h:82:10`!(arr); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(cpArraycxx . . $ cpArray# *arr, void *object) |
| 52 | { |
| 53 | if(arr->numcxx . . $ cpArray#num. == arr->maxcxx . . $ cpArray#max.){ |
| 54 | arr->maxcxx . . $ cpArray#max. = 3*(arr->maxcxx . . $ cpArray#max. + 1)/2; |
| 55 | arr->arrcxx . . $ cpArray#arr. = (void **)cprealloccxx . . $ `include/chipmunk/chipmunk.h:77:10`!(arr->arrcxx . . $ cpArray#arr., arr->maxcxx . . $ cpArray#max.*sizeof(void*)); |
| 56 | } |
| 57 | |
| 58 | arr->arrcxx . . $ cpArray#arr.[arr->numcxx . . $ cpArray#num.] = object; |
| 59 | arr->numcxx . . $ cpArray#num.++; |
| 60 | } |
| 61 | |
| 62 | void * |
| 63 | cpArrayPopcxx . . $ cpArrayPop(deec8af08e758c71).(cpArraycxx . . $ cpArray# *arr) |
| 64 | { |
| 65 | arr->numcxx . . $ cpArray#num.--; |
| 66 | |
| 67 | void *value = arr->arrcxx . . $ cpArray#arr.[arr->numcxx . . $ cpArray#num.]; |
| 68 | arr->arrcxx . . $ cpArray#arr.[arr->numcxx . . $ cpArray#num.] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 69 | |
| 70 | return value; |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | cpArrayDeleteObjcxx . . $ cpArrayDeleteObj(5027a0abedaf1ddc).(cpArraycxx . . $ cpArray# *arr, void *obj) |
| 75 | { |
| 76 | for(int i=0; i<arr->numcxx . . $ cpArray#num.; i++){ |
| 77 | if(arr->arrcxx . . $ cpArray#arr.[i] == obj){ |
| 78 | arr->numcxx . . $ cpArray#num.--; |
| 79 | |
| 80 | arr->arrcxx . . $ cpArray#arr.[i] = arr->arrcxx . . $ cpArray#arr.[arr->numcxx . . $ cpArray#num.]; |
| 81 | arr->arrcxx . . $ cpArray#arr.[arr->numcxx . . $ cpArray#num.] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 82 | |
| 83 | return; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | cpArrayFreeEachcxx . . $ cpArrayFreeEach(d583da02e3252d4f).(cpArraycxx . . $ cpArray# *arr, void (freeFunc)(void*)) |
| 90 | { |
| 91 | for(int i=0; i<arr->numcxx . . $ cpArray#num.; i++) freeFunc(arr->arrcxx . . $ cpArray#arr.[i]); |
| 92 | } |
| 93 | |
| 94 | cpBoolcxx . . $ cpBool# |
| 95 | cpArrayContainscxx . . $ cpArrayContains(a67271b2b33b9265).(cpArraycxx . . $ cpArray# *arr, void *ptr) |
| 96 | { |
| 97 | for(int i=0; i<arr->numcxx . . $ cpArray#num.; i++) |
| 98 | if(arr->arrcxx . . $ cpArray#arr.[i] == ptr) return cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!; |
| 99 | |
| 100 | return cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 101 | } |