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