vector.h revision 4ba684c495481036e2cd9ad27ef668841e21493e
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * STL-inspired vector implementation in C
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * @note functions in this file are inline to prevent warnings about
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * unused static functions. I assume that in this day and age a
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * compiler makes its own decisions about whether to actually
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * inline a function.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * @note as this header is included in rdesktop-vrdp, we do not include other
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * required header files here (to wit assert.h, err.h, mem.h and
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * types.h). These must be included first. If this moves to iprt, we
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * should write a wrapper around it doing that.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * @todo can we do more of the type checking at compile time somehow?
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Copyright (C) 2008-2010 Oracle Corporation
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * available from http://www.virtualbox.org. This file is free software;
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * General Public License (GPL) as published by the Free Software
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/*** Helper macros and deinitions ***/
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** The unit by which the vector capacity is increased */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** Calculate a hash of a string of tokens for sanity type checking */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync ((unsigned) \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** Helper macro for @a VECTOR_TOKEN_HASH */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync#define VECTOR_TOKEN_HASH_VALUE(token, place, mul) \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** Helper macro for @a VECTOR_TOKEN_HASH */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync ^ VECTOR_TOKEN_HASH_VALUE(token, place + 1, 0x100) \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync ^ VECTOR_TOKEN_HASH_VALUE(token, place + 2, 0x10000) \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync ^ VECTOR_TOKEN_HASH_VALUE(token, place + 3, 0x1000000)
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** Generic vector structure, used by @a VECTOR_OBJ and @a VECTOR_PTR */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** The number of elements in the vector */ \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** The current capacity of the vector */ \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** The size of an element */ \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** Hash value of the element type */ \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** The elements themselves */ \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** Destructor for elements - takes a pointer to an element. */ \
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync void (*mpfnCleanup)(void *); \
fb98ad2c5db683e0704e0cba88f305e95dc1b73avboxsync/*** Structure definitions ***/
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** A vector of values or objects */
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/** A vector of pointer values. (A handy special case.) */
(void) pvElement;
void *pRealloc;
if (!pRealloc)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
void *pvElement)
int rc2;
return rc2;
return VINF_SUCCESS;
void *pv)
int rc2;
return rc2;
return VINF_SUCCESS;
(void (*)(void*)) pfnCleanup)
(void (*)(void*)) pfnCleanup)
++pIterator)