Panda3D
 All Classes Functions Variables Enumerations
pvector.h
00001 // Filename: pvector.h
00002 // Created by:  drose (05Jun01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PVECTOR_H
00016 #define PVECTOR_H
00017 
00018 #include <vector>
00019 
00020 #include "dtoolbase.h"
00021 #include "pallocator.h"
00022 #include "register_type.h"
00023 
00024 #ifndef USE_STL_ALLOCATOR
00025 // If we're not using custom allocators, just use the standard class
00026 // definition.
00027 #define pvector vector
00028 
00029 #else
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : pvector
00033 // Description : This is our own Panda specialization on the default
00034 //               STL vector.  Its main purpose is to call the hooks
00035 //               for MemoryUsage to properly track STL-allocated
00036 //               memory.
00037 ////////////////////////////////////////////////////////////////////
00038 template<class Type>
00039 class pvector : public vector<Type, pallocator_array<Type> > {
00040 public:
00041   typedef pallocator_array<Type> allocator;
00042   typedef vector<Type, allocator> base_class;
00043   typedef TYPENAME base_class::size_type size_type;
00044 
00045   pvector(TypeHandle type_handle = pvector_type_handle) : base_class(allocator(type_handle)) { }
00046   pvector(const pvector<Type> &copy) : base_class(copy) { }
00047   pvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator(type_handle)) { }
00048   pvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator(type_handle)) { }
00049   pvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator(type_handle)) { }
00050 };
00051 
00052 #endif  // USE_STL_ALLOCATOR
00053 
00054 #if defined(HAVE_EIGEN) && defined(_WIN32) && !defined(CPPPARSER)
00055 
00056 #include <Eigen/StdVector>
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //       Class : epvector
00060 // Description : Unfortunately, on Windows, std::vector can't be used
00061 //               for classes with explicitly alignment requirements,
00062 //               due to a minor mistake in the template definition
00063 //               (one of the vector methods receives a concrete
00064 //               object, which the compiler flags as an error, even if
00065 //               the method is never called).
00066 //
00067 //               As a workaround, Eigen provides their own
00068 //               specialization of vector, using their own aligned
00069 //               allocator.  We define that here as epvector, which is
00070 //               meant to be a drop-in replacement for pvector for
00071 //               classes that include a linmath object that requires
00072 //               alignment.  Unfortunately, this means we can't use
00073 //               the Panda allocator, so memory allocated for this
00074 //               vector class won't be tracked as part of Panda's
00075 //               memory tracking system.  Them's the breaks, kids.
00076 ////////////////////////////////////////////////////////////////////
00077 template<class Type>
00078 class epvector : public vector<Type, Eigen::aligned_allocator<Type> > {
00079 public:
00080   typedef Eigen::aligned_allocator<Type> allocator;
00081   typedef vector<Type, allocator> base_class;
00082   typedef TYPENAME base_class::size_type size_type;
00083 
00084   epvector(TypeHandle type_handle = pvector_type_handle) : base_class(allocator()) { }
00085   epvector(const epvector<Type> &copy) : base_class(copy) { }
00086   epvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator()) { }
00087   epvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator()) { }
00088   epvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator()) { }
00089 };
00090 
00091 #else  // HAVE_EIGEN
00092 #define epvector pvector
00093 #endif  // HAVE_EIGEN
00094 
00095 #endif
00096 
 All Classes Functions Variables Enumerations