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) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 
29 #ifndef mrpt_utils_types_H
30 #define mrpt_utils_types_H
31 
32 #include <vector>
33 #include <map>
34 #include <list>
35 #include <string>
36 #include <stdexcept>
37 #include <cstdarg>
38 #include <ctime>
39 
40 #include <mrpt/utils/mrpt_stdint.h> // compiler-independent version of "stdint.h"
41 #include <mrpt/utils/mrpt_inttypes.h> // compiler-independent version of "inttypes.h"
42 
43 // needed here for a few basic types used in Eigen MRPT's plugin:
44 #include <mrpt/math/math_frwds.h>
45 
46 // --------------------------------------------------
47 // Include the Eigen3 library headers, including
48 // MRPT's extensions:
49 // --------------------------------------------------
50 #include <iostream> // These headers are assumed by <mrpt/math/eigen_plugins.h>:
51 #include <fstream>
52 #include <sstream>
53 #ifdef EIGEN_MAJOR_VERSION
54 # error **FATAL ERROR**: MRPT headers must be included before Eigen headers.
55 #endif
56 #ifndef EIGEN_USE_NEW_STDVECTOR
57 # define EIGEN_USE_NEW_STDVECTOR
58 #endif
59 #include <Eigen/Dense>
60 #include <Eigen/StdVector>
61 #include <Eigen/StdDeque>
62 
63 #if !EIGEN_VERSION_AT_LEAST(2,90,0)
64 #error MRPT needs version 3.0.0-beta of Eigen or newer
65 #endif
66 
67 // Template implementations that need to be after all Eigen includes:
68 #include EIGEN_MATRIXBASE_PLUGIN_POST_IMPL
69 // --------------------------------------------------
70 // End of Eigen includes
71 // --------------------------------------------------
72 
73 
74 // This must be put inside any MRPT class that inherits from an Eigen class:
75 #define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_) \
76  /*! Assignment operator from any other Eigen class */ \
77  template<typename OtherDerived> \
78  inline mrpt_autotype & operator= (const Eigen::MatrixBase <OtherDerived>& other) { \
79  /*Base::operator=(other.template cast<typename Base::Scalar>());*/ \
80  Base::operator=(other); \
81  return *this; \
82  } \
83  /*! Constructor from any other Eigen class */ \
84  template<typename OtherDerived> \
85  inline _CLASS_(const Eigen::MatrixBase <OtherDerived>& other) : Base(other.template cast<typename Base::Scalar>()) { } \
86 
87 namespace mrpt
88 {
89  /** The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized constructors that resemble std::vector.
90  * \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
91  * \ingroup mrpt_base_grp
92  */
93  template <typename T>
94  struct dynamicsize_vector : public Eigen::Matrix<T,Eigen::Dynamic,1>
95  {
96  typedef Eigen::Matrix<T,Eigen::Dynamic,1> Base;
99 
100  /** Default constructor: empty vector */
101  inline dynamicsize_vector() : Base() {}
102  /** Constructor, initializes to a given initial size */
103  inline dynamicsize_vector(size_t N) : Base(N,1) { Base::derived().setZero(); }
104  /** Constructor, initializes to a given initial size, all elements to a given value */
105  inline dynamicsize_vector(size_t N, T init_val) : Base(N,1) { Base::derived().assign(init_val); }
106  /** Constructor, initializes from a std::vector<> of scalars */
107  template <typename R>
108  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]; }
109  /** 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 */
110  inline void resize(const size_t N, const T default_val) { Base::derived().resize(N,1); Base::derived().setConstant(default_val); }
111  /** Normal resize of the vector (preserving old contents). */
112  inline void resize(const size_t N) { Base::derived().conservativeResize(N); }
113  /** Reset the vector to a 0-length */
114  inline void clear() { *this = dynamicsize_vector<T>(); }
115  /** DOES NOTHING (it's here for backward compatibility) */
116  inline void reserve(size_t dummy_size) { }
117  };
118 
121 
122  typedef std::vector<int8_t> vector_signed_byte;
123  typedef std::vector<int16_t> vector_signed_word;
124  typedef std::vector<int32_t> vector_int;
125  typedef std::vector<int64_t> vector_long;
126  typedef std::vector<size_t> vector_size_t;
127  typedef std::vector<uint8_t> vector_byte;
128  typedef std::vector<uint16_t> vector_word;
129  typedef std::vector<uint32_t> vector_uint;
130  typedef std::vector<bool> vector_bool; //!< A type for passing a vector of bools.
131  typedef std::vector<std::string> vector_string; //!< A type for passing a vector of strings.
132 
133  /** Helper types for STL containers with Eigen memory allocators. */
134  template <class TYPE1,class TYPE2=TYPE1>
136  {
137  typedef std::pair<TYPE1,TYPE2> pair_t;
138  typedef std::vector<TYPE1, Eigen::aligned_allocator<TYPE1> > vector_t;
139  typedef std::deque<TYPE1, Eigen::aligned_allocator<TYPE1> > deque_t;
140  typedef std::list<TYPE1, Eigen::aligned_allocator<TYPE1> > list_t;
141  typedef std::map<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > map_t;
142  typedef std::multimap<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > multimap_t;
143  };
144 
145  namespace utils
146  {
147  /** For performing type casting from a pointer to its numeric value.
148  */
149  #if defined(_MSC_VER) && (_MSC_VER>=1300)
150  typedef unsigned long long POINTER_TYPE;
151  #else
152  typedef unsigned long POINTER_TYPE;
153  #endif
154 
155  typedef uint64_t TNodeID; //!< The type for node IDs in graphs of different types.
156  typedef std::pair<TNodeID,TNodeID> TPairNodeIDs; //!< A pair of node IDs.
157  #define INVALID_NODEID static_cast<TNodeID>(-1)
158 
159  } // end namespace
160 }
161 
162 #endif
163 



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013