aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils/vector.h
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2010-11-17 17:55:17 +0100
committerDavid 'Digit' Turner <digit@android.com>2010-11-17 17:55:17 +0100
commit4c0f745dc80d392fddea23eb8d4d7d86425ce0c6 (patch)
tree5da693710d1a3e81a7af3590619c8cbc6c7942d8 /android/utils/vector.h
parent44e750e6d0375543f0d91d0a68432ae9c8489ccd (diff)
downloadexternal_qemu-4c0f745dc80d392fddea23eb8d4d7d86425ce0c6.zip
external_qemu-4c0f745dc80d392fddea23eb8d4d7d86425ce0c6.tar.gz
external_qemu-4c0f745dc80d392fddea23eb8d4d7d86425ce0c6.tar.bz2
Update android/utils/ with misc. new features.
This introduces a few new features to android/utils/ that will be used in later patches. + <android/utils/assert.h> to handle assertions + <android/utils/vector.h> to handle dynamic arrays + <android/utils/reflist.h> slightly updated (more docs) + <android/utils/refset.h> implements a set of pointers Change-Id: Iebc14cfefd1c0e8aaecda9958a980d40f0be610a
Diffstat (limited to 'android/utils/vector.h')
-rw-r--r--android/utils/vector.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/android/utils/vector.h b/android/utils/vector.h
new file mode 100644
index 0000000..e591055
--- /dev/null
+++ b/android/utils/vector.h
@@ -0,0 +1,80 @@
+/* Copyright (C) 2009 The Android Open Source Project
+**
+** This software is licensed under the terms of the GNU General Public
+** License version 2, as published by the Free Software Foundation, and
+** may be copied, distributed, and modified under those terms.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+*/
+#ifndef _ANDROID_UTILS_VECTOR_H
+#define _ANDROID_UTILS_VECTOR_H
+
+#include "android/utils/system.h"
+#include "android/utils/assert.h"
+
+#define AVECTOR_DECL(ctype,name) \
+ ctype* name; \
+ unsigned num_##name; \
+ unsigned max_##name \
+
+#define AVECTOR_SIZE(obj,name) \
+ (obj)->num_##name
+
+#define AVECTOR_INIT(obj,name) \
+ do { \
+ (obj)->name = NULL; \
+ (obj)->num_##name = 0; \
+ (obj)->max_##name = 0; \
+ } while (0)
+
+#define AVECTOR_INIT_ALLOC(obj,name,count) \
+ do { \
+ AARRAY_NEW0( (obj)->name, (count) ); \
+ (obj)->num_##name = 0; \
+ (obj)->max_##name = (count); \
+ } while (0)
+
+#define AVECTOR_DONE(obj,name) \
+ do { \
+ AFREE((obj)->name); \
+ (obj)->num_##name = 0; \
+ (obj)->max_##name = 0; \
+ } while (0)
+
+#define AVECTOR_AT(obj,name,index) \
+ (&(obj)->name[(index)])
+
+#define AVECTOR_REALLOC(obj,name,newMax) \
+ do { \
+ AARRAY_RENEW((obj)->name,newMax); \
+ (obj)->max_##name = (newMax); \
+ } while(0)
+
+#define AVECTOR_ENSURE(obj,name,newCount) \
+ do { \
+ unsigned _newCount = (newCount); \
+ if (_newCount > (obj)->max_##name) \
+ AASSERT_LOC(); \
+ _avector_ensure( (void**)&(obj)->name, sizeof((obj)->name[0]), \
+ &(obj)->max_##name, _newCount ); \
+ } while (0);
+
+extern void _avector_ensure( void** items, size_t itemSize,
+ unsigned* pMaxItems, unsigned newCount );
+
+#define AVECTOR_FOREACH(obj,name,itemptr,statement) \
+ do { \
+ unsigned __vector_nn = 0; \
+ unsigned __vector_max = (obj)->num_##name; \
+ for ( ; __vector_nn < __vector_max; __vector_nn++ ) { \
+ itemptr = &(obj)->name[__vector_nn]; \
+ statement; \
+ } \
+ } while (0);
+
+/* */
+
+#endif /* _ANDROID_UTILS_VECTOR_H */