diff options
Diffstat (limited to '3rdparty/bx/include/tinystl/buffer.h')
-rw-r--r-- | 3rdparty/bx/include/tinystl/buffer.h | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/3rdparty/bx/include/tinystl/buffer.h b/3rdparty/bx/include/tinystl/buffer.h index 31654c64119..5fac2291486 100644 --- a/3rdparty/bx/include/tinystl/buffer.h +++ b/3rdparty/bx/include/tinystl/buffer.h @@ -1,5 +1,5 @@ /*- - * Copyright 2012 Matthew Endsley + * Copyright 2012-1015 Matthew Endsley * All rights reserved * * Redistribution and use in source and binary forms, with or without @@ -55,6 +55,18 @@ namespace tinystl { } template<typename T> + static inline void buffer_fill_urange_traits(T* first, T* last, pod_traits<T, false>) { + for (; first < last; ++first) + new(placeholder(), first) T(); + } + + template<typename T> + static inline void buffer_fill_urange_traits(T* first, T* last, pod_traits<T, true>) { + for (; first < last; ++first) + *first = T(); + } + + template<typename T> static inline void buffer_fill_urange_traits(T* first, T* last, const T& value, pod_traits<T, false>) { for (; first < last; ++first) new(placeholder(), first) T(value); @@ -106,6 +118,11 @@ namespace tinystl { } template<typename T> + static inline void buffer_fill_urange(T* first, T* last) { + buffer_fill_urange_traits(first, last, pod_traits<T>()); + } + + template<typename T> static inline void buffer_fill_urange(T* first, T* last, const T& value) { buffer_fill_urange_traits(first, last, value, pod_traits<T>()); } @@ -138,6 +155,15 @@ namespace tinystl { } template<typename T, typename Alloc> + static inline void buffer_resize(buffer<T, Alloc>* b, size_t size) { + buffer_reserve(b, size); + + buffer_fill_urange(b->last, b->first + size); + buffer_destroy_range(b->first + size, b->last); + b->last = b->first + size; + } + + template<typename T, typename Alloc> static inline void buffer_resize(buffer<T, Alloc>* b, size_t size, const T& value) { buffer_reserve(b, size); @@ -169,22 +195,34 @@ namespace tinystl { } template<typename T, typename Alloc> - static inline void buffer_insert(buffer<T, Alloc>* b, T* where, const T* first, const T* last) { + static inline T* buffer_insert_common(buffer<T, Alloc>* b, T* where, size_t count) { const size_t offset = (size_t)(where - b->first); - const size_t newsize = (size_t)((b->last - b->first) + (last - first)); + const size_t newsize = (size_t)((b->last - b->first) + count); if (b->first + newsize > b->capacity) buffer_reserve(b, (newsize * 3) / 2); where = b->first + offset; - const size_t count = (size_t)(last - first); if (where != b->last) buffer_bmove_urange(where + count, where, b->last); + b->last = b->first + newsize; + + return where; + } + + template<typename T, typename Alloc, typename Param> + static inline void buffer_insert(buffer<T, Alloc>* b, T* where, const Param* first, const Param* last) { + where = buffer_insert_common(b, where, last - first); for (; first != last; ++first, ++where) new(placeholder(), where) T(*first); + } - b->last = b->first + newsize; + template<typename T, typename Alloc> + static inline void buffer_insert(buffer<T, Alloc>* b, T* where, size_t count) { + where = buffer_insert_common(b, where, count); + for (size_t i = 0; i < count; ++i) + new(placeholder(), where) T(); } template<typename T, typename Alloc> |