Panda3D
epvector.h
1 // Filename: epvector.h
2 // Created by: drose (19Dec11)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EPVECTOR_H
16 #define EPVECTOR_H
17 
18 #include "pvector.h"
19 
20 #if defined(HAVE_EIGEN) && defined(_WIN32) && !defined(_WIN64) && !defined(CPPPARSER)
21 
22 #include <Eigen/StdVector>
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : epvector
26 // Description : Unfortunately, on Windows, std::vector can't be used
27 // for classes with explicitly alignment requirements,
28 // due to a minor mistake in the template definition
29 // (one of the vector methods receives a concrete
30 // object, which the compiler flags as an error, even if
31 // the method is never called).
32 //
33 // As a workaround, Eigen provides their own
34 // specialization of vector, using their own aligned
35 // allocator. We define that here as epvector, which is
36 // meant to be a drop-in replacement for pvector for
37 // classes that include a linmath object that requires
38 // alignment. Unfortunately, this means we can't use
39 // the Panda allocator, so memory allocated for this
40 // vector class won't be tracked as part of Panda's
41 // memory tracking system. Them's the breaks, kids.
42 ////////////////////////////////////////////////////////////////////
43 template<class Type>
44 class epvector : public vector<Type, Eigen::aligned_allocator<Type> > {
45 public:
46  typedef Eigen::aligned_allocator<Type> allocator;
47  typedef vector<Type, allocator> base_class;
48  typedef TYPENAME base_class::size_type size_type;
49 
50  epvector(TypeHandle type_handle = pvector_type_handle) : base_class(allocator()) { }
51  epvector(const epvector<Type> &copy) : base_class(copy) { }
52  epvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator()) { }
53  epvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator()) { }
54  epvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator()) { }
55 };
56 
57 #else // HAVE_EIGEN
58 #define epvector pvector
59 #endif // HAVE_EIGEN
60 
61 #endif
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85