3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.dogcows.com/chaz/wiki/TheCheat
6 * Copyright (c) 2003-2010, Charles McGarvey et al.
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
13 #import "CheaterTypes.h"
16 TCArray
TCMakeArray( unsigned count
, unsigned size
)
18 TCArray array
= (TCArray
)malloc( sizeof(struct _TCArray
) );
21 array
->_bytes
= malloc( count
* size
);
23 if ( array
->_bytes
) {
24 array
->_count
= count
;
26 array
->_ownsBytes
= YES
;
36 TCArray
TCMakeArrayWithBytes( unsigned count
, unsigned size
, void *bytes
)
38 TCArray array
= TCMakeArray( count
, size
);
40 if ( array
&& bytes
) {
41 memcpy( array
->_bytes
, bytes
, count
* size
);
46 void TCReleaseArray( TCArray array
)
48 if ( array
&& array
->_ownsBytes
) {
49 free( array
->_bytes
);
55 void TCArrayAppendArray( TCArray array
, TCArray other
)
57 unsigned oldCount
= array
->_count
;
58 unsigned count
= oldCount
+ other
->_count
;
60 if ( array
->_size
!= other
->_size
) {
64 TCArrayResize( array
, count
);
65 if ( array
->_count
== count
) {
66 memcpy( array
->_bytes
+ oldCount
* array
->_size
, other
->_bytes
, other
->_count
* other
->_size
);
71 NSString
*TCStringFromArray( TCArray array
)
73 return [NSString stringWithFormat
:@
"{%p,%u,%u}", array
->_bytes
, array
->_count
, array
->_size
];