Util: Add Vector copy
Vicki Pfau vi@endrift.com
Tue, 07 Feb 2017 13:52:05 -0800
1 files changed,
7 insertions(+),
1 deletions(-)
jump to
M
include/mgba-util/vector.h
→
include/mgba-util/vector.h
@@ -27,7 +27,8 @@ void NAME ## Shift(struct NAME* vector, size_t location, size_t difference); \
void NAME ## Unshift(struct NAME* vector, size_t location, size_t difference); \ void NAME ## EnsureCapacity(struct NAME* vector, size_t capacity); \ size_t NAME ## Size(const struct NAME* vector); \ - size_t NAME ## Index(const struct NAME* vector, const TYPE* member); + size_t NAME ## Index(const struct NAME* vector, const TYPE* member); \ + void NAME ## Copy(struct NAME* dest, const struct NAME* src); #define DEFINE_VECTOR(NAME, TYPE) \ void NAME ## Init(struct NAME* vector, size_t capacity) { \@@ -84,6 +85,11 @@ return vector->size; \
} \ size_t NAME ## Index(const struct NAME* vector, const TYPE* member) { \ return member - (const TYPE*) vector->vector; \ + } \ + void NAME ## Copy(struct NAME* dest, const struct NAME* src) { \ + NAME ## EnsureCapacity(dest, src->size); \ + memcpy(dest->vector, src->vector, src->size * sizeof(TYPE)); \ + dest->size = src->size; \ } \ CXX_GUARD_END