Main MRPT website > C++ reference
MRPT logo
Classes | Namespaces | Defines | Functions
STL extensions and metaprogramming
[mrpt-base]
Collaboration diagram for STL extensions and metaprogramming:

Classes

class  mrpt::utils::bimap
 A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std::map's, one for keys and another for values. More...
class  mrpt::utils::circular_buffer
 A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the underlying storage. More...
class  mrpt::utils::list_searchable
 This class implements a STL container with features of both, a std::set and a std::list. More...
class  mrpt::utils::map_as_vector
 A STL-like container which looks and behaves (almost exactly) like a std::map<> but is implemented as a linear std::vector<> indexed by KEY. More...
struct  mrpt::utils::metaprogramming::ObjectDelete
 An object for deleting pointers (intended for STL algorithms) More...
struct  mrpt::utils::metaprogramming::ObjectClear
 An object for clearing an object (invokes its method "->clear()") given a pointer or smart-pointer, intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectClear2
 An object for clearing an object (invokes its method ".clear()") given a pointer or smart-pointer, intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectClearSecond
 An object for clearing an object->second (invokes its method "clear()") given a pointer or smart-pointer, intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectConvert
 An object for transforming between types/classes, intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectMakeUnique
 An object for making smart pointers unique (ie, making copies if necessary), intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectPairMakeUnique
 An object for making smart pointers unique (ie, making copies if necessary), intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectClearUnique
 An object for making smart pointers unique (ie, making copies if necessary), intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectReadFromStream
 An object for reading objects from a stream, intended for being used in STL algorithms. More...
struct  mrpt::utils::metaprogramming::ObjectWriteToStream
 An object for writing objects to a stream, intended for being used in STL algorithms. More...
class  mrpt::utils::metaprogramming::MemoryBypasserIterator
 This class bypasses pointer access in iterators to pointers, thus allowing the use of algorithms that expect an object of class T with containers of T*. More...
class  mrpt::utils::metaprogramming::BinaryMemberFunctionWrapper
 This template encapsulates a binary member function and a single object into a function expecting the two parameters of the member function. More...
class  mrpt::utils::metaprogramming::UnaryMemberFunctionWrapper
 This template encapsulates an unary member function and a single object into a function expecting the parameter of the member function. More...
class  mrpt::utils::metaprogramming::MemberFunctionWrapper
 This template encapsulates a member function without arguments and a single object into a function. More...
class  mrpt::utils::metaprogramming::NonConstBind1st
 Equivalent of std::bind1st for functions with non-const arguments. More...
class  mrpt::utils::metaprogramming::NonConstBind2nd
 Equivalent of std::bind2nd for functions with non-const arguments. More...
struct  mrpt::utils::ci_less
 A case-insensitive comparator struct for usage within STL containers, eg: map<string,string,ci_less> More...
struct  mrpt::utils::map_traits_stdmap
 Traits for using a std::map<> (sparse representation) More...
struct  mrpt::utils::map_traits_map_as_vector
 Traits for using a mrpt::utils::map_as_vector<> (dense, fastest representation) More...

Namespaces

namespace  mrpt::utils::metaprogramming
 

A set of utility objects for metaprogramming with STL algorithms.


Defines

#define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(CONTAINER)
#define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER(CONTAINER)

Functions

template<typename T >
void mrpt::utils::metaprogramming::DeleteContainer (T &container)
 A function which deletes a container of pointers.
template<typename it_src , typename it_dst >
void mrpt::utils::metaprogramming::copy_typecasting (it_src first, it_src last, it_dst target)
 Behaves like std::copy but allows the source and target iterators to be of different types through static typecasting.
template<typename src_container , typename dst_container >
void mrpt::utils::metaprogramming::copy_container_typecasting (const src_container &src, dst_container &trg)
 Copy all the elements in a container (vector, deque, list) into a different one performing the appropriate typecasting.
template<typename U , typename T >
MemoryBypasserIterator< T, U > mrpt::utils::metaprogramming::bypassPointer (const T &baseIterator)
 Sintactic sugar for MemoryBypasserIterator.
template<typename T , typename U1 , typename U2 , typename V >
BinaryMemberFunctionWrapper< T,
U1, U2, V > 
mrpt::utils::metaprogramming::wrapMember (V &obj, T(V::*fun)(U1, U2))
 This function creates a function from an object and a member function.
template<typename T , typename U , typename V >
UnaryMemberFunctionWrapper< T,
U, V > 
mrpt::utils::metaprogramming::wrapMember (V &obj, T(V::*fun)(U))
template<typename T , typename V >
MemberFunctionWrapper< T, V > mrpt::utils::metaprogramming::wrapMember (V &obj, T(V::*fun)(void))
template<typename Op >
NonConstBind1st< Op > mrpt::utils::metaprogramming::nonConstBind1st (Op &o, typename Op::first_argument_type &t)
 Use this function instead of directly calling NonConstBind1st.
template<typename Op >
NonConstBind2nd< Op > mrpt::utils::metaprogramming::nonConstBind2nd (Op &o, typename Op::second_argument_type &t)
 Do not directly use the NonConstBind2nd class directly.
 mrpt::utils::MRPTSTL_SERIALIZABLE_SEQ_CONTAINER (std::vector) MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std
 Template method to serialize a STL pair.
template<class T1 , class T2 >
CStream & mrpt::utils::operator>> (CStream &in, std::pair< T1, T2 > &obj)
 Template method to deserialize a STL pair.
template<class T , class CONTAINER >
size_t mrpt::utils::find_in_vector (const T &value, const CONTAINER &vect)
 Returns the index of the value "T" in the container "vect" (std::vector,std::deque,etc), or string::npos if not found.
template<class T >
std::list< T >::iterator mrpt::utils::erase_return_next (std::list< T > &cont, typename std::list< T >::iterator &it)
 Calls the standard "erase" method of a STL container, but also returns an iterator to the next element in the container (or end if none)
template<class K , class V >
std::map< K, V >::iterator mrpt::utils::erase_return_next (std::map< K, V > &cont, typename std::map< K, V >::iterator &it)
template<class K , class V >
std::multimap< K, V >::iterator mrpt::utils::erase_return_next (std::multimap< K, V > &cont, typename std::multimap< K, V >::iterator &it)
template<class T >
std::set< T >::iterator mrpt::utils::erase_return_next (std::set< T > &cont, typename std::set< T >::iterator &it)
template<typename T >
std::string mrpt::utils::sprintf_vector (const char *fmt, const std::vector< T > &V)
 Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element.
template<typename Derived >
std::string mrpt::utils::sprintf_vector (const char *fmt, const Eigen::MatrixBase< Derived > &V)
template<typename T >
void mrpt::utils::printf_vector (const char *fmt, const std::vector< T > &V)
 Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element.

Define Documentation

#define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER (   CONTAINER)

Definition at line 89 of file stl_extensions.h.

#define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER (   CONTAINER)
Value:
/** Template method to serialize a sequential STL container  */ \
                        template <class T,class _Ax> \
                        CStream& operator << (CStream& out, const CONTAINER<T,_Ax> &obj) \
                        { \
                                out << string(#CONTAINER) << TTypeName<T>::get(); \
                                out << static_cast<uint32_t>(obj.size()); \
                                for_each( obj.begin(), obj.end(), ObjectWriteToStream(&out) ); \
                                return out; \
                        } \
                        /** Template method to deserialize a sequential STL container */ \
                        template <class T,class _Ax>  \
                        CStream& operator >> (CStream& in, CONTAINER<T,_Ax> &obj) \
                        { \
                                obj.clear(); \
                                string pref,stored_T; \
                                in >> pref; \
                                if (pref!=#CONTAINER) THROW_EXCEPTION(format("Error: serialized container %s<%s>'s preambles is wrong: '%s'",#CONTAINER,TTypeName<T>::get().c_str(),pref.c_str() )) \
                                in >> stored_T; \
                                if (stored_T != TTypeName<T>::get() ) THROW_EXCEPTION(format("Error: serialized container %s< %s != %s >",#CONTAINER,stored_T.c_str(),TTypeName<T>::get().c_str() )) \
                                uint32_t n; \
                                in >> n; \
                                obj.resize(n); \
                                for_each( obj.begin(), obj.end(), ObjectReadFromStream(&in) ); \
                                return in; \
                        }

Definition at line 61 of file stl_extensions.h.


Function Documentation

template<typename U , typename T >
MemoryBypasserIterator<T,U> mrpt::utils::metaprogramming::bypassPointer ( const T &  baseIterator) [inline]

Sintactic sugar for MemoryBypasserIterator.

For example, having the following declarations: vector<double *> vec; void modifyVal(double &v); The following sentence is not legal: for_each(vec.begin(),vec.end(),&modifyVal) But this one is: for_each(bypassPointer(vec.begin()),bypassPointer(vec.end()),&modifyVal)

Definition at line 272 of file metaprogramming.h.

template<typename src_container , typename dst_container >
void mrpt::utils::metaprogramming::copy_container_typecasting ( const src_container &  src,
dst_container &  trg 
) [inline]

Copy all the elements in a container (vector, deque, list) into a different one performing the appropriate typecasting.

The target container is automatically resized to the appropriate size, and previous contents are lost. This can be used to assign std::vector's of different types:

   std::vector<int>    vi(10);
   std::vector<float>  vf;
   vf = vi;   // Compiler error
   mrpt::utils::metaprogramming::copy_container_typecasting(v1,vf);  // Ok

Definition at line 185 of file metaprogramming.h.

Referenced by mrpt::opengl::CAngularObservationMesh::FTrace2D::operator()().

template<typename it_src , typename it_dst >
void mrpt::utils::metaprogramming::copy_typecasting ( it_src  first,
it_src  last,
it_dst  target 
) [inline]

Behaves like std::copy but allows the source and target iterators to be of different types through static typecasting.

Note:
As in std::copy, the target iterator must point to the first "slot" where to put the first transformed element, and sufficient space must be allocated in advance.
See also:
copy_container_typecasting

Definition at line 168 of file metaprogramming.h.

template<typename T >
void mrpt::utils::metaprogramming::DeleteContainer ( T &  container) [inline]

A function which deletes a container of pointers.

Definition at line 54 of file metaprogramming.h.

template<class T >
std::list<T>::iterator mrpt::utils::erase_return_next ( std::list< T > &  cont,
typename std::list< T >::iterator it 
) [inline]

Calls the standard "erase" method of a STL container, but also returns an iterator to the next element in the container (or end if none)

Definition at line 205 of file stl_extensions.h.

template<class K , class V >
std::map<K,V>::iterator mrpt::utils::erase_return_next ( std::map< K, V > &  cont,
typename std::map< K, V >::iterator it 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 210 of file stl_extensions.h.

template<class K , class V >
std::multimap<K,V>::iterator mrpt::utils::erase_return_next ( std::multimap< K, V > &  cont,
typename std::multimap< K, V >::iterator it 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 217 of file stl_extensions.h.

template<class T >
std::set<T>::iterator mrpt::utils::erase_return_next ( std::set< T > &  cont,
typename std::set< T >::iterator it 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 224 of file stl_extensions.h.

template<class T , class CONTAINER >
size_t mrpt::utils::find_in_vector ( const T &  value,
const CONTAINER &  vect 
)

Returns the index of the value "T" in the container "vect" (std::vector,std::deque,etc), or string::npos if not found.

Definition at line 196 of file stl_extensions.h.

References mrpt::math::distance().

Referenced by mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration(), and mrpt::graphslam::optimize_graph_spa_levmarq().

mrpt::utils::MRPTSTL_SERIALIZABLE_SEQ_CONTAINER ( std::vector  )

Template method to serialize a STL pair.

Definition at line 125 of file stl_extensions.h.

References MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER.

template<typename Op >
NonConstBind1st<Op> mrpt::utils::metaprogramming::nonConstBind1st ( Op &  o,
typename Op::first_argument_type &  t 
) [inline]

Use this function instead of directly calling NonConstBind1st.

Definition at line 356 of file metaprogramming.h.

References t().

template<typename Op >
NonConstBind2nd<Op> mrpt::utils::metaprogramming::nonConstBind2nd ( Op &  o,
typename Op::second_argument_type &  t 
) [inline]

Do not directly use the NonConstBind2nd class directly.

Use this function.

Definition at line 375 of file metaprogramming.h.

References t().

template<class T1 , class T2 >
CStream& mrpt::utils::operator>> ( CStream &  in,
std::pair< T1, T2 > &  obj 
)

Template method to deserialize a STL pair.

Definition at line 179 of file stl_extensions.h.

References THROW_EXCEPTION, and mrpt::format().

template<typename T >
void mrpt::utils::printf_vector ( const char *  fmt,
const std::vector< T > &  V 
)

Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element.

Definition at line 262 of file stl_extensions.h.

References mrpt::utils::sprintf_vector().

template<typename T >
std::string mrpt::utils::sprintf_vector ( const char *  fmt,
const std::vector< T > &  V 
)

Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element.

Definition at line 233 of file stl_extensions.h.

References mrpt::format().

Referenced by mrpt::math::CLevenbergMarquardtTempl::execute(), and mrpt::utils::printf_vector().

template<typename Derived >
std::string mrpt::utils::sprintf_vector ( const char *  fmt,
const Eigen::MatrixBase< Derived > &  V 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 247 of file stl_extensions.h.

References mrpt::format().

template<typename T , typename U1 , typename U2 , typename V >
BinaryMemberFunctionWrapper<T,U1,U2,V> mrpt::utils::metaprogramming::wrapMember ( V &  obj,
T(V::*)(U1, U2)  fun 
) [inline]

This function creates a function from an object and a member function.

It has three overloads, for zero, one and two parameters in the function.

Definition at line 330 of file metaprogramming.h.

template<typename T , typename U , typename V >
UnaryMemberFunctionWrapper<T,U,V> mrpt::utils::metaprogramming::wrapMember ( V &  obj,
T(V::*)(U)  fun 
) [inline]

Definition at line 333 of file metaprogramming.h.

template<typename T , typename V >
MemberFunctionWrapper<T,V> mrpt::utils::metaprogramming::wrapMember ( V &  obj,
T(V::*)(void)  fun 
) [inline]

Definition at line 336 of file metaprogramming.h.




Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011