1 |
|
|
// |
2 |
|
|
// Copyright (c) 2016-2020 CNRS INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#ifndef __pinocchio_container_aligned_vector_hpp__ |
6 |
|
|
#define __pinocchio_container_aligned_vector_hpp__ |
7 |
|
|
|
8 |
|
|
#include <vector> |
9 |
|
|
#include <Eigen/StdVector> |
10 |
|
|
|
11 |
|
|
#define PINOCCHIO_ALIGNED_STD_VECTOR(Type) \ |
12 |
|
|
::pinocchio::container::aligned_vector<Type> |
13 |
|
|
// std::vector<Type,Eigen::aligned_allocator<Type> > |
14 |
|
|
|
15 |
|
|
namespace pinocchio |
16 |
|
|
{ |
17 |
|
|
namespace container |
18 |
|
|
{ |
19 |
|
|
|
20 |
|
|
/// |
21 |
|
|
/// \brief Specialization of an std::vector with an aligned allocator. This specialization might be used when the type T is or contains some Eigen members. |
22 |
|
|
/// |
23 |
|
|
/// \tparam T Type of the elements. |
24 |
|
|
/// |
25 |
|
|
template<typename T> |
26 |
|
|
struct aligned_vector : public std::vector<T, Eigen::aligned_allocator<T> > |
27 |
|
|
{ |
28 |
|
|
typedef ::std::vector<T, Eigen::aligned_allocator<T> > vector_base; |
29 |
|
|
typedef const vector_base & const_vector_base_ref; |
30 |
|
|
typedef vector_base & vector_base_ref; |
31 |
|
|
|
32 |
|
|
typedef T value_type; |
33 |
|
|
typedef typename vector_base::allocator_type allocator_type; |
34 |
|
|
typedef typename vector_base::size_type size_type; |
35 |
|
|
typedef typename vector_base::iterator iterator; |
36 |
|
|
|
37 |
|
1789 |
explicit aligned_vector(const allocator_type & a = allocator_type()) : vector_base(a) {} |
38 |
|
|
template<typename InputIterator> |
39 |
|
1 |
aligned_vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) |
40 |
✓✗✓✗
|
1 |
: vector_base(first, last, a) {} |
41 |
|
7204 |
aligned_vector(const aligned_vector & c) : vector_base(c) {} |
42 |
|
11558 |
explicit aligned_vector(size_type num, const value_type & val) |
43 |
✓✗ |
23116 |
: vector_base(num, val) {} |
44 |
|
1083 |
explicit aligned_vector(size_type num) |
45 |
✓✗ |
2132 |
: vector_base(num) {} |
46 |
|
|
aligned_vector(iterator start, iterator end) : vector_base(start, end) {} |
47 |
|
180 |
aligned_vector & operator=(const aligned_vector& x) |
48 |
|
180 |
{ vector_base::operator=(x); return *this; } |
49 |
|
|
|
50 |
|
|
vector_base & base() { return *static_cast<vector_base*>(this); } |
51 |
|
1638 |
const vector_base & base() const { return *static_cast<const vector_base*>(this); } |
52 |
|
|
|
53 |
|
|
}; // struct aligned_vector |
54 |
|
|
|
55 |
|
|
template<class T> |
56 |
|
410 |
bool operator==(const aligned_vector<T>& lhs, const aligned_vector<T>& rhs) |
57 |
|
|
{ |
58 |
|
410 |
return lhs.base() == rhs.base(); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
} // namespace container |
62 |
|
|
|
63 |
|
|
} // namespace pinocchio |
64 |
|
|
|
65 |
|
|
#endif // ifndef __pinocchio_container_aligned_vector_hpp__ |