Main MRPT website > C++ reference for MRPT 1.5.9
Classes | Namespaces | Macros | Functions
STL extensions and metaprogramming

Detailed Description

Collaboration diagram for STL extensions and metaprogramming:

Classes

class  mrpt::utils::bimap< KEY, VALUE >
 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...
 
struct  mrpt::utils::ci_less
 A case-insensitive comparator struct for usage within STL containers, eg: map<string,string,ci_less> More...
 
class  mrpt::utils::circular_buffer< T >
 A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the underlying storage. More...
 
struct  mrpt::utils::ContainerReadOnlyProxyAccessor< STLCONTAINER >
 A generic proxy accessor template that only allows read-only access to the original binded STL container object. More...
 
class  mrpt::utils::copy_ptr< T >
 Smart pointer for non-polymorphic classes. More...
 
class  mrpt::utils::list_searchable< T >
 This class implements a STL container with features of both, a std::set and a std::list. More...
 
class  mrpt::utils::map_as_vector< KEY, VALUE, VECTOR_T >
 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< TARGET_TYPE >
 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< T >
 An object for making smart pointers unique (ie, making copies if necessary), intended for being used in STL algorithms. More...
 
class  mrpt::utils::metaprogramming::MemoryBypasserIterator< T, U >
 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< T, U1, U2, V >
 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< T, U, V >
 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< T, V >
 This template encapsulates a member function without arguments and a single object into a function. More...
 
class  mrpt::utils::metaprogramming::NonConstBind1st< Op >
 Equivalent of std::bind1st for functions with non-const arguments. More...
 
class  mrpt::utils::metaprogramming::NonConstBind2nd< Op >
 Equivalent of std::bind2nd for functions with non-const arguments. 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::ObjectReadFromStreamToPtrs< ptr_t >
 
struct  mrpt::utils::metaprogramming::ObjectWriteToStream
 An object for writing objects to a stream, intended for being used in STL algorithms. More...
 
class  mrpt::utils::poly_ptr< T >
 Smart pointer for polymorphic classes with a clone() method. More...
 
class  mrpt::utils::poly_ptr_ptr< T >
 Wrapper to a smart pointer to polymorphic classes, capable of handling copy operator, etc. 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

 mrpt::utils::internal
 
 mrpt::utils::metaprogramming
 A set of utility objects for metaprogramming with STL algorithms.
 

Macros

#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. More...
 
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. More...
 
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. More...
 
template<typename U , typename T >
MemoryBypasserIterator< T, U > mrpt::utils::metaprogramming::bypassPointer (const T &baseIterator)
 Sintactic sugar for MemoryBypasserIterator. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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) More...
 
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<class T >
std::string mrpt::utils::getSTLContainerAsString (const T &t)
 Return a STL container in std::string form. More...
 
template<class T >
void mrpt::utils::printSTLContainer (const T &t)
 Print the given vector t. More...
 
template<class T >
void mrpt::utils::printSTLContainerOfContainers (const T &t)
 Print the given STL container of containers t. More...
 
template<class T1 , class T2 >
std::string mrpt::utils::getMapAsString (const std::map< T1, T2 > &m, const std::string &sep=" => ")
 Return contents of map in a string representation. More...
 
template<class T1 , class T2 >
void mrpt::utils::printMap (const std::map< T1, T2 > &m)
 Print the given map m. More...
 
 mrpt::utils::MRPTSTL_SERIALIZABLE_SEQ_CONTAINER (std::vector) MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std
 Template method to serialize a STL pair. More...
 
template<class T1 , class T2 >
CStreammrpt::utils::operator>> (mrpt::utils::CStream &in, std::pair< T1, T2 > &obj)
 Template method to deserialize a STL pair. More...
 

Macro Definition Documentation

◆ MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER

#define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER (   CONTAINER)

Definition at line 56 of file stl_serialization.h.

◆ MRPTSTL_SERIALIZABLE_SEQ_CONTAINER

#define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER (   CONTAINER)
Value:
/** Template method to serialize a sequential STL container */ \
template <class T,class _Ax> \
CStream& operator << (mrpt::utils::CStream& out, const CONTAINER<T,_Ax> &obj) \
{ \
out << std::string(#CONTAINER) << mrpt::utils::TTypeName<T>::get(); \
out << static_cast<uint32_t>(obj.size()); \
std::for_each( obj.begin(), obj.end(), mrpt::utils::metaprogramming::ObjectWriteToStream(&out) ); \
return out; \
} \
/** Template method to deserialize a sequential STL container */ \
template <class T,class _Ax> \
CStream& operator >> (mrpt::utils::CStream& in, CONTAINER<T,_Ax> &obj) \
{ \
obj.clear(); \
std::string pref,stored_T; \
in >> pref; \
if (pref!=#CONTAINER) THROW_EXCEPTION_FMT("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 != mrpt::utils::TTypeName<T>::get() ) THROW_EXCEPTION_FMT("Error: serialized container %s< %s != %s >",#CONTAINER,stored_T.c_str(),TTypeName<T>::get().c_str() ) \
uint32_t n; \
in >> n; \
obj.resize(n); \
std::for_each( obj.begin(), obj.end(), mrpt::utils::metaprogramming::ObjectReadFromStream(&in) ); \
return in; \
}
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:47
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
An object for writing objects to a stream, intended for being used in STL algorithms.
GLdouble s
Definition: glext.h:3602
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
CStream & operator>>(mrpt::utils::CStream &in, std::pair< T1, T2 > &obj)
Template method to deserialize a STL pair.
GLsizei const GLchar ** string
Definition: glext.h:3919
GLuint in
Definition: glext.h:6301

Definition at line 28 of file stl_serialization.h.

Function Documentation

◆ bypassPointer()

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 225 of file metaprogramming.h.

◆ copy_container_typecasting()

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

Definition at line 138 of file metaprogramming.h.

Referenced by mrpt::nav::CAbstractPTGBasedReactive::build_movement_candidate(), and TEST().

◆ copy_typecasting()

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 121 of file metaprogramming.h.

◆ DeleteContainer()

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

A function which deletes a container of pointers.

Definition at line 38 of file metaprogramming.h.

◆ erase_return_next() [1/4]

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 37 of file stl_containers_utils.h.

Referenced by mrpt::vision::TSequenceFeatureObservations::decimateCameraFrames(), and mrpt::hmtslam::CHMTSLAM::LSLAM_process_message_from_AA().

◆ erase_return_next() [2/4]

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 43 of file stl_containers_utils.h.

◆ erase_return_next() [3/4]

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 51 of file stl_containers_utils.h.

◆ erase_return_next() [4/4]

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 59 of file stl_containers_utils.h.

◆ find_in_vector()

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 27 of file stl_containers_utils.h.

References mrpt::math::distance().

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

◆ getMapAsString()

template<class T1 , class T2 >
std::string mrpt::utils::getMapAsString ( const std::map< T1, T2 > &  m,
const std::string sep = " => " 
)

Return contents of map in a string representation.

Parameters
[in]mTemplate map
[in]sepString that seperates visually each key and its value. Defaults to " => "
Returns
std::string representation of map

Definition at line 111 of file stl_containers_utils.h.

Referenced by mrpt::utils::printMap().

◆ getSTLContainerAsString()

template<class T >
std::string mrpt::utils::getSTLContainerAsString ( const T &  t)

◆ MRPTSTL_SERIALIZABLE_SEQ_CONTAINER()

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

Template method to serialize a STL pair.

Definition at line 92 of file stl_serialization.h.

References mrpt::utils::TTypeName< T >::get().

◆ nonConstBind1st()

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 309 of file metaprogramming.h.

◆ nonConstBind2nd()

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 328 of file metaprogramming.h.

◆ operator>>()

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

Template method to deserialize a STL pair.

Definition at line 146 of file stl_serialization.h.

References mrpt::format(), mrpt::utils::TTypeName< T >::get(), and THROW_EXCEPTION.

◆ printMap()

template<class T1 , class T2 >
void mrpt::utils::printMap ( const std::map< T1, T2 > &  m)

Print the given map m.

Parameters
[in]mTemplate map

Definition at line 130 of file stl_containers_utils.h.

References mrpt::utils::getMapAsString().

◆ printSTLContainer()

template<class T >
void mrpt::utils::printSTLContainer ( const T &  t)

Print the given vector t.

Parameters
[in]tTemplate vector

Definition at line 85 of file stl_containers_utils.h.

References mrpt::utils::getSTLContainerAsString().

Referenced by mrpt::utils::printSTLContainerOfContainers().

◆ printSTLContainerOfContainers()

template<class T >
void mrpt::utils::printSTLContainerOfContainers ( const T &  t)

Print the given STL container of containers t.

Parameters
[in]tTemplate STL container (containing other containers)

Definition at line 94 of file stl_containers_utils.h.

References mrpt::utils::printSTLContainer().

◆ wrapMember() [1/3]

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 283 of file metaprogramming.h.

◆ wrapMember() [2/3]

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 286 of file metaprogramming.h.

◆ wrapMember() [3/3]

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

Definition at line 289 of file metaprogramming.h.




Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020