Panda3D
pvector.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pvector.h
10  * @author drose
11  * @date 2001-06-05
12  */
13 
14 #ifndef PVECTOR_H
15 #define PVECTOR_H
16 
17 #include <vector>
18 
19 #include "dtoolbase.h"
20 #include "pallocator.h"
21 #include "register_type.h"
22 
23 #ifndef USE_STL_ALLOCATOR
24 // If we're not using custom allocators, just use the standard class
25 // definition.
26 #define pvector vector
27 
28 #elif defined(CPPPARSER)
29 // Simplified definition to speed up Interrogate parsing.
30 template<class Type>
31 class pvector : public std::vector<Type> {
32 };
33 
34 #else
35 
36 /**
37  * This is our own Panda specialization on the default STL vector. Its main
38  * purpose is to call the hooks for MemoryUsage to properly track STL-
39  * allocated memory.
40  */
41 template<class Type>
42 class pvector : public std::vector<Type, pallocator_array<Type> > {
43 public:
45  typedef std::vector<Type, allocator> base_class;
46  typedef typename base_class::size_type size_type;
47 
48  explicit pvector(TypeHandle type_handle = pvector_type_handle) : base_class(allocator(type_handle)) { }
49  pvector(const pvector<Type> &copy) : base_class(copy) { }
50  pvector(pvector<Type> &&from) noexcept : base_class(std::move(from)) {};
51  explicit pvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator(type_handle)) { }
52  explicit pvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator(type_handle)) { }
53  pvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator(type_handle)) { }
54 
55  pvector<Type> &operator =(const pvector<Type> &copy) {
56  base_class::operator =(copy);
57  return *this;
58  }
59 
60  pvector<Type> &operator =(pvector<Type> &&from) noexcept {
61  base_class::operator =(std::move(from));
62  return *this;
63  }
64 };
65 
66 #endif // USE_STL_ALLOCATOR
67 
68 #endif
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.