/src/Geometry_Eigen/Eigen/src/StlSupport/details.h

http://github.com/Akranar/daguerreo · C Header · 99 lines · 57 code · 14 blank · 28 comment · 0 complexity · 4bbbc75465fa9a225c138bfaa0eb312d MD5 · raw file

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. // Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com>
  6. //
  7. // Eigen is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU Lesser General Public
  9. // License as published by the Free Software Foundation; either
  10. // version 3 of the License, or (at your option) any later version.
  11. //
  12. // Alternatively, you can redistribute it and/or
  13. // modify it under the terms of the GNU General Public License as
  14. // published by the Free Software Foundation; either version 2 of
  15. // the License, or (at your option) any later version.
  16. //
  17. // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
  18. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  19. // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU Lesser General Public
  23. // License and a copy of the GNU General Public License along with
  24. // Eigen. If not, see <http://www.gnu.org/licenses/>.
  25. #ifndef EIGEN_STL_DETAILS_H
  26. #define EIGEN_STL_DETAILS_H
  27. #ifndef EIGEN_ALIGNED_ALLOCATOR
  28. #define EIGEN_ALIGNED_ALLOCATOR Eigen::aligned_allocator
  29. #endif
  30. namespace Eigen {
  31. // This one is needed to prevent reimplementing the whole std::vector.
  32. template <class T>
  33. class aligned_allocator_indirection : public EIGEN_ALIGNED_ALLOCATOR<T>
  34. {
  35. public:
  36. typedef size_t size_type;
  37. typedef ptrdiff_t difference_type;
  38. typedef T* pointer;
  39. typedef const T* const_pointer;
  40. typedef T& reference;
  41. typedef const T& const_reference;
  42. typedef T value_type;
  43. template<class U>
  44. struct rebind
  45. {
  46. typedef aligned_allocator_indirection<U> other;
  47. };
  48. aligned_allocator_indirection() {}
  49. aligned_allocator_indirection(const aligned_allocator_indirection& ) : EIGEN_ALIGNED_ALLOCATOR<T>() {}
  50. aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<T>& ) {}
  51. template<class U>
  52. aligned_allocator_indirection(const aligned_allocator_indirection<U>& ) {}
  53. template<class U>
  54. aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR<U>& ) {}
  55. ~aligned_allocator_indirection() {}
  56. };
  57. #ifdef _MSC_VER
  58. // sometimes, MSVC detects, at compile time, that the argument x
  59. // in std::vector::resize(size_t s,T x) won't be aligned and generate an error
  60. // even if this function is never called. Whence this little wrapper.
  61. #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) \
  62. typename Eigen::internal::conditional< \
  63. Eigen::internal::is_arithmetic<T>::value, \
  64. T, \
  65. Eigen::internal::workaround_msvc_stl_support<T> \
  66. >::type
  67. namespace internal {
  68. template<typename T> struct workaround_msvc_stl_support : public T
  69. {
  70. inline workaround_msvc_stl_support() : T() {}
  71. inline workaround_msvc_stl_support(const T& other) : T(other) {}
  72. inline operator T& () { return *static_cast<T*>(this); }
  73. inline operator const T& () const { return *static_cast<const T*>(this); }
  74. template<typename OtherT>
  75. inline T& operator=(const OtherT& other)
  76. { T::operator=(other); return *this; }
  77. inline workaround_msvc_stl_support& operator=(const workaround_msvc_stl_support& other)
  78. { T::operator=(other); return *this; }
  79. };
  80. }
  81. #else
  82. #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) T
  83. #endif
  84. }
  85. #endif // EIGEN_STL_DETAILS_H