Blender  V2.93
util_vector.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __UTIL_VECTOR_H__
18 #define __UTIL_VECTOR_H__
19 
20 #include <cassert>
21 #include <cstring>
22 #include <vector>
23 
26 #include "util/util_types.h"
27 
29 
30 /* Own subclass-ed version of std::vector. Subclass is needed because:
31  *
32  * - Use own allocator which keeps track of used/peak memory.
33  * - Have method to ensure capacity is re-set to 0.
34  */
35 template<typename value_type, typename allocator_type = GuardedAllocator<value_type>>
36 class vector : public std::vector<value_type, allocator_type> {
37  public:
38  typedef std::vector<value_type, allocator_type> BaseClass;
39 
40  /* Inherit all constructors from base class. */
41  using BaseClass::vector;
42 
43  /* Try as hard as possible to use zero memory. */
44  void free_memory()
45  {
47  BaseClass::swap(empty);
48  }
49 
50  /* Some external API might demand working with std::vector. */
51  operator std::vector<value_type>()
52  {
53  return std::vector<value_type>(this->begin(), this->end());
54  }
55 };
56 
58 
59 #endif /* __UTIL_VECTOR_H__ */
void swap(T &a, T &b)
Definition: Common.h:33
std::vector< value_type, allocator_type > BaseClass
Definition: util_vector.h:38
void free_memory()
Definition: util_vector.h:44
#define CCL_NAMESPACE_END
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
Definition: vector.h:39