Panda3D
epvector.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 epvector.h
10  * @author drose
11  * @date 2011-12-19
12  */
13 
14 #ifndef EPVECTOR_H
15 #define EPVECTOR_H
16 
17 #include "pvector.h"
18 
19 #if defined(HAVE_EIGEN) && defined(_WIN32) && !defined(_WIN64) && !defined(CPPPARSER)
20 
21 #include <Eigen/StdVector>
22 
23 /**
24  * Unfortunately, on Windows, std::vector can't be used for classes with
25  * explicitly alignment requirements, due to a minor mistake in the template
26  * definition (one of the vector methods receives a concrete object, which the
27  * compiler flags as an error, even if the method is never called).
28  *
29  * As a workaround, Eigen provides their own specialization of vector, using
30  * their own aligned allocator. We define that here as epvector, which is
31  * meant to be a drop-in replacement for pvector for classes that include a
32  * linmath object that requires alignment. Unfortunately, this means we can't
33  * use the Panda allocator, so memory allocated for this vector class won't be
34  * tracked as part of Panda's memory tracking system. Them's the breaks,
35  * kids.
36  */
37 template<class Type>
38 class epvector : public std::vector<Type, Eigen::aligned_allocator<Type> > {
39 public:
40  typedef Eigen::aligned_allocator<Type> allocator;
41  typedef std::vector<Type, allocator> base_class;
42  typedef typename base_class::size_type size_type;
43 
44  epvector(TypeHandle type_handle = pvector_type_handle) : base_class(allocator()) { }
45  epvector(const epvector<Type> &copy) : base_class(copy) { }
46  epvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator()) { }
47  epvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator()) { }
48  epvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator()) { }
49 };
50 
51 #else // HAVE_EIGEN
52 #define epvector pvector
53 #endif // HAVE_EIGEN
54 
55 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81