// Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 #pragma once #include "alloc.h" #include namespace embree { class Device; template class vector_t { public: typedef T value_type; typedef T* iterator; typedef const T* const_iterator; __forceinline vector_t () : size_active(0), size_alloced(0), items(nullptr) {} __forceinline explicit vector_t (size_t sz) : size_active(0), size_alloced(0), items(nullptr) { internal_resize_init(sz); } template __forceinline explicit vector_t (M alloc, size_t sz) : alloc(alloc), size_active(0), size_alloced(0), items(nullptr) { internal_resize_init(sz); } __forceinline vector_t (Device* alloc) : vector_t(alloc,0) {} __forceinline vector_t(void* data, size_t bytes) : size_active(0), size_alloced(bytes/sizeof(T)), items((T*)data) {} __forceinline ~vector_t() { clear(); } __forceinline vector_t (const vector_t& other) { size_active = other.size_active; size_alloced = other.size_alloced; items = alloc.allocate(size_alloced); for (size_t i=0; i 0); return items[0]; }; __forceinline T& back () const { assert(size_active > 0); return items[size_active-1]; }; __forceinline T* data() { return items; }; __forceinline const T* data() const { return items; }; /******************** Modifiers **************************/ __forceinline void push_back(const T& nt) { const T v = nt; // need local copy as input reference could point to this vector internal_resize(size_active,internal_grow_size(size_active+1)); ::new (&items[size_active++]) T(v); } __forceinline void pop_back() { assert(!empty()); size_active--; items[size_active].~T(); } __forceinline void clear() { /* destroy elements */ for (size_t i=0; i using vector = vector_t>; /*! vector class that performs aligned allocations */ template using avector = vector_t::value> >; /*! vector class that performs OS allocations */ template using ovector = vector_t >; /*! vector class with externally managed data buffer */ template using evector = vector_t>; }