Main MRPT website > C++ reference
MRPT logo
base/include/mrpt/utils/types.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (c) 2005-2013, Individual contributors, see AUTHORS file |
7  | Copyright (c) 2005-2013, MAPIR group, University of Malaga |
8  | Copyright (c) 2012-2013, University of Almeria |
9  | All rights reserved. |
10  | |
11  | Redistribution and use in source and binary forms, with or without |
12  | modification, are permitted provided that the following conditions are |
13  | met: |
14  | * Redistributions of source code must retain the above copyright |
15  | notice, this list of conditions and the following disclaimer. |
16  | * Redistributions in binary form must reproduce the above copyright |
17  | notice, this list of conditions and the following disclaimer in the |
18  | documentation and/or other materials provided with the distribution. |
19  | * Neither the name of the copyright holders nor the |
20  | names of its contributors may be used to endorse or promote products |
21  | derived from this software without specific prior written permission.|
22  | |
23  | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24  | 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
25  | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR|
26  | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
27  | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL|
28  | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR|
29  | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30  | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
31  | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32  | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33  | POSSIBILITY OF SUCH DAMAGE. |
34  +---------------------------------------------------------------------------+ */
35 
36 #ifndef mrpt_utils_types_H
37 #define mrpt_utils_types_H
38 
39 #include <vector>
40 #include <map>
41 #include <list>
42 #include <string>
43 #include <stdexcept>
44 #include <cstdarg>
45 #include <ctime>
46 
47 #include <mrpt/utils/mrpt_stdint.h> // compiler-independent version of "stdint.h"
48 #include <mrpt/utils/mrpt_inttypes.h> // compiler-independent version of "inttypes.h"
49 
50 // needed here for a few basic types used in Eigen MRPT's plugin:
51 #include <mrpt/math/math_frwds.h>
52 
53 // --------------------------------------------------
54 // Include the Eigen3 library headers, including
55 // MRPT's extensions:
56 // --------------------------------------------------
57 #include <iostream> // These headers are assumed by <mrpt/math/eigen_plugins.h>:
58 #include <fstream>
59 #include <sstream>
60 #ifdef EIGEN_MAJOR_VERSION
61 # error **FATAL ERROR**: MRPT headers must be included before Eigen headers.
62 #endif
63 #ifndef EIGEN_USE_NEW_STDVECTOR
64 # define EIGEN_USE_NEW_STDVECTOR
65 #endif
66 #include <Eigen/Dense>
67 #include <Eigen/StdVector>
68 #include <Eigen/StdDeque>
69 
70 #if !EIGEN_VERSION_AT_LEAST(2,90,0)
71 #error MRPT needs version 3.0.0-beta of Eigen or newer
72 #endif
73 
74 // Template implementations that need to be after all Eigen includes:
75 #include EIGEN_MATRIXBASE_PLUGIN_POST_IMPL
76 // --------------------------------------------------
77 // End of Eigen includes
78 // --------------------------------------------------
79 
80 
81 // This must be put inside any MRPT class that inherits from an Eigen class:
82 #define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_) \
83  /*! Assignment operator from any other Eigen class */ \
84  template<typename OtherDerived> \
85  inline mrpt_autotype & operator= (const Eigen::MatrixBase <OtherDerived>& other) { \
86  /*Base::operator=(other.template cast<typename Base::Scalar>());*/ \
87  Base::operator=(other); \
88  return *this; \
89  } \
90  /*! Constructor from any other Eigen class */ \
91  template<typename OtherDerived> \
92  inline _CLASS_(const Eigen::MatrixBase <OtherDerived>& other) : Base(other.template cast<typename Base::Scalar>()) { } \
93 
94 namespace mrpt
95 {
96  /** The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized constructors that resemble std::vector.
97  * \note For a summary and classification of all MRPT vector, array and matrix classes see: http://www.mrpt.org/Matrices_vectors_arrays_and_Linear_Algebra_MRPT_and_Eigen_classes
98  * \ingroup mrpt_base_grp
99  */
100  template <typename T>
101  struct dynamicsize_vector : public Eigen::Matrix<T,Eigen::Dynamic,1>
102  {
103  typedef T value_type;
104  typedef Eigen::Matrix<T,Eigen::Dynamic,1> Base;
107 
108  /** Default constructor: empty vector */
109  inline dynamicsize_vector() : Base() {}
110  /** Constructor, initializes to a given initial size */
111  inline dynamicsize_vector(size_t N) : Base(N,1) { Base::derived().setZero(); }
112  /** Constructor, initializes to a given initial size, all elements to a given value */
113  inline dynamicsize_vector(size_t N, T init_val) : Base(N,1) { Base::derived().assign(init_val); }
114  /** Constructor, initializes from a std::vector<> of scalars */
115  template <typename R>
116  inline dynamicsize_vector(const std::vector<R>& v) : Base(v.size(),1) { for (size_t i=0;i<v.size();i++) (*this)[i]=v[i]; }
117  /** Overloaded resize method that mimics std::vector::resize(SIZE,DEFAULT_VALUE) instead of resize(nrows,ncols) \note This method exists for backward compatibility in MRPT */
118  inline void resize(const size_t N, const T default_val) { if (static_cast<size_t>(Base::derived().size())!=N) Base::derived().resize(N,1); Base::derived().setConstant(default_val); }
119  /** Normal resize of the vector (preserving old contents). */
120  inline void resize(const size_t N) { if (static_cast<size_t>(Base::derived().size())!=N) Base::derived().conservativeResize(N); }
121  /** Reset the vector to a 0-length */
122  inline void clear() { *this = dynamicsize_vector<T>(); }
123  /** DOES NOTHING (it's here for backward compatibility) */
124  inline void reserve(size_t dummy_size) { }
125  };
126 
129 
130  typedef std::vector<int8_t> vector_signed_byte;
131  typedef std::vector<int16_t> vector_signed_word;
132  typedef std::vector<int32_t> vector_int;
133  typedef std::vector<int64_t> vector_long;
134  typedef std::vector<size_t> vector_size_t;
135  typedef std::vector<uint8_t> vector_byte;
136  typedef std::vector<uint16_t> vector_word;
137  typedef std::vector<uint32_t> vector_uint;
138  typedef std::vector<bool> vector_bool; //!< A type for passing a vector of bools.
139  typedef std::vector<std::string> vector_string; //!< A type for passing a vector of strings.
140 
141  /** Helper types for STL containers with Eigen memory allocators. */
142  template <class TYPE1,class TYPE2=TYPE1>
144  {
145  typedef std::pair<TYPE1,TYPE2> pair_t;
146  typedef std::vector<TYPE1, Eigen::aligned_allocator<TYPE1> > vector_t;
147  typedef std::deque<TYPE1, Eigen::aligned_allocator<TYPE1> > deque_t;
148  typedef std::list<TYPE1, Eigen::aligned_allocator<TYPE1> > list_t;
149  typedef std::map<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > map_t;
150  typedef std::multimap<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > multimap_t;
151  };
152 
153  namespace utils
154  {
155  /** For performing type casting from a pointer to its numeric value.
156  */
157  #if defined(_MSC_VER) && (_MSC_VER>=1300)
158  typedef unsigned long long POINTER_TYPE;
159  #else
160  typedef unsigned long POINTER_TYPE;
161  #endif
162 
163  typedef uint64_t TNodeID; //!< The type for node IDs in graphs of different types.
164  typedef std::pair<TNodeID,TNodeID> TPairNodeIDs; //!< A pair of node IDs.
165  #define INVALID_NODEID static_cast<mrpt::utils::TNodeID>(-1)
166 
167  } // end namespace
168 }
169 
170 #endif
171 
std::vector< int32_t > vector_int
unsigned long POINTER_TYPE
For performing type casting from a pointer to its numeric value.
void reserve(size_t dummy_size)
DOES NOTHING (it&#39;s here for backward compatibility)
uint64_t TNodeID
The type for node IDs in graphs of different types.
Eigen::Matrix< T, Eigen::Dynamic, 1 > Base
std::map< TYPE1, TYPE2, std::less< TYPE1 >, Eigen::aligned_allocator< std::pair< const TYPE1, TYPE2 > > > map_t
std::vector< bool > vector_bool
A type for passing a vector of bools.
std::deque< TYPE1, Eigen::aligned_allocator< TYPE1 > > deque_t
std::vector< int8_t > vector_signed_byte
void clear()
Reset the vector to a 0-length.
std::vector< int16_t > vector_signed_word
std::vector< int64_t > vector_long
Helper types for STL containers with Eigen memory allocators.
std::vector< size_t > vector_size_t
#define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_)
dynamicsize_vector(size_t N)
Constructor, initializes to a given initial size.
The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...
std::vector< uint8_t > vector_byte
dynamicsize_vector(size_t N, T init_val)
Constructor, initializes to a given initial size, all elements to a given value.
dynamicsize_vector< double > vector_double
std::pair< TNodeID, TNodeID > TPairNodeIDs
A pair of node IDs.
void resize(const size_t N)
Normal resize of the vector (preserving old contents).
void resize(const size_t N, const T default_val)
Overloaded resize method that mimics std::vector::resize(SIZE,DEFAULT_VALUE) instead of resize(nrows...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
size_t size(const MATRIXLIKE &m, int dim)
Definition: bits.h:72
dynamicsize_vector(const std::vector< R > &v)
Constructor, initializes from a std::vector<> of scalars.
std::vector< uint16_t > vector_word
std::multimap< TYPE1, TYPE2, std::less< TYPE1 >, Eigen::aligned_allocator< std::pair< const TYPE1, TYPE2 > > > multimap_t
std::vector< uint32_t > vector_uint
dynamicsize_vector< float > vector_float
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
std::vector< std::string > vector_string
A type for passing a vector of strings.
std::list< TYPE1, Eigen::aligned_allocator< TYPE1 > > list_t



Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo