gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FastVector.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #pragma once
20 
21 #include <vector>
22 #include <boost/serialization/nvp.hpp>
23 #include <boost/serialization/vector.hpp>
24 
25 #include <gtsam/base/FastList.h>
26 #include <gtsam/base/FastSet.h>
27 
28 namespace gtsam {
29 
37 template<typename VALUE>
38 class FastVector: public std::vector<VALUE, typename internal::FastDefaultVectorAllocator<VALUE>::type> {
39 
40 public:
41 
42  typedef std::vector<VALUE, typename internal::FastDefaultVectorAllocator<VALUE>::type> Base;
43 
46 
48  explicit FastVector(size_t size) : Base(size) {}
49 
51  explicit FastVector(size_t size, const VALUE& initial) : Base(size, initial) {}
52 
54  template<typename INPUTITERATOR>
55  explicit FastVector(INPUTITERATOR first, INPUTITERATOR last) {
56  // This if statement works around a bug in boost pool allocator and/or
57  // STL vector where if the size is zero, the pool allocator will allocate
58  // huge amounts of memory.
59  if(first != last)
60  Base::assign(first, last);
61  }
62 
65  if(x.size() > 0)
66  Base::assign(x.begin(), x.end());
67  }
68 
71  if(x.size() > 0)
72  Base::assign(x.begin(), x.end());
73  }
74 
76  FastVector(const Base& x) : Base(x) {}
77 
79  template<typename ALLOCATOR>
80  FastVector(const std::vector<VALUE, ALLOCATOR>& x)
81  {
82  // This if statement works around a bug in boost pool allocator and/or
83  // STL vector where if the size is zero, the pool allocator will allocate
84  // huge amounts of memory.
85  if(x.size() > 0)
86  Base::assign(x.begin(), x.end());
87  }
88 
90  operator std::vector<VALUE>() const {
91  return std::vector<VALUE>(this->begin(), this->end());
92  }
93 
94 private:
96  friend class boost::serialization::access;
97  template<class ARCHIVE>
98  void serialize(ARCHIVE & ar, const unsigned int version) {
99  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
100  }
101 
102 };
103 
104 }
FastVector(const FastSet< VALUE > &x)
Copy constructor from a FastSet.
Definition: FastVector.h:70
FastVector(const std::vector< VALUE, ALLOCATOR > &x)
Copy constructor from a standard STL container.
Definition: FastVector.h:80
A thin wrapper around std::set that uses boost's fast_pool_allocator.
A thin wrapper around std::list that uses boost's fast_pool_allocator.
FastVector(const Base &x)
Copy constructor from the base class.
Definition: FastVector.h:76
FastVector()
Default constructor.
Definition: FastVector.h:45
FastVector(size_t size, const VALUE &initial)
Constructor from size and initial values.
Definition: FastVector.h:51
FastVector(size_t size)
Constructor from size.
Definition: FastVector.h:48
FastVector(INPUTITERATOR first, INPUTITERATOR last)
Constructor from a range, passes through to base class.
Definition: FastVector.h:55
Definition: FastSet.h:49
Definition: FastList.h:38
FastVector(const FastList< VALUE > &x)
Copy constructor from a FastList.
Definition: FastVector.h:64
Definition: FastVector.h:38