TemplateUtil Namespace Reference


Classes

struct  binary_deref
struct  unary_deref
struct  const_comp_mem_fun_ref_t
struct  const_comp_mem_fun_t
struct  comp_mem_fun_ref_t
struct  comp_mem_fun_t
struct  PtrLess
struct  PtrGreater
struct  PtrLessEq
struct  PtrGreaterEq
struct  PtrEq
struct  PtrNotEq
struct  AlwaysTrueComp
struct  DeleteObj
struct  InheritedFrom

functor converters

template<class Predicate>
unary_deref< Predicate > deref1 (const Predicate &p)
template<class Predicate>
binary_deref< Predicate > deref2 (const Predicate &p)

Member function -> functor converters

template<typename Return, typename T, typename Pred>
const_comp_mem_fun_ref_t<
Return, T, Pred > 
const_comp_mem_fun_ref (Return(T::*f)() const, Pred p)
template<typename Return, typename T, typename Pred>
const_comp_mem_fun_t< Return,
T, Pred > 
const_comp_mem_fun (Return(T::*f)() const, Pred p)
template<typename Return, typename T, typename Pred>
comp_mem_fun_ref_t< Return,
T, Pred > 
comp_mem_fun_ref (Return(T::*f)(), Pred p)
template<typename Return, typename T, typename Pred>
comp_mem_fun_t< Return, T,
Pred > 
comp_mem_fun (Return(T::*f)(), Pred p)

convinience functions

template<typename C, typename Function>
void for_all (C &collection, Function f)
template<typename T, typename Comparator>
void erase_if (T &collection, const Comparator &c)
template<typename T, typename InputIterator, typename Comparator>
void erase_if (T &collection, InputIterator begin, InputIterator end, const Comparator &c)
template<typename C>
void delete_all (C &collection)
template<typename C>
void delete_all_second (C &collection)
template<typename C>
void print_col (C &collection, ostream &os=cout, const char *d="\n")
template<typename C>
void print_ptr_col (C &collection, ostream &os=cout, const char *d="\n")
template<typename C>
void merge_ptr_col (C &dest, const C &source)
template<typename InputIterator, typename T>
InputIterator find_second (InputIterator first, InputIterator last, const T &v)
template<typename InputIterator, typename Type, typename Predicate>
InputIterator find_second_if (InputIterator first, InputIterator last, const Predicate &c)
template<typename InputIterator, typename T>
InputIterator find_first (InputIterator first, InputIterator last, const T &v)
template<typename InputIterator, typename Type, typename Predicate>
InputIterator find_first_if (InputIterator first, InputIterator last, const Predicate &c)
template<typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator copy_if (InputIterator first, InputIterator last, OutputIterator dest, Predicate pred)
template<typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator copy_second_if (InputIterator first, InputIterator last, OutputIterator dest, Predicate pred)

Functions

template<typename type>
const type & max (const type &a, const type &b)
template<typename type>
const type & min (const type &a, const type &b)


Detailed Description

TempateUtil This is a collection of utility operators to make STL easier. All these function are templatized and attempt to follow STL naming conventions and requirements.

A functor is a function that can be used in a STL call. It is usually a class that overrides the operator() to return a boolean value. These are used in STL for sorting and finding values in containers. STL provides base classes unary_function and binary_function for functors that take one or two arguments. Single argument functors are usually used for finding and dual argument functors are used for comparing. To alter the operation of a functor STL provides the function called notl and not2 which will negate the result of the provided functor. This allows the user to write one functor that will perform an operation and the opposite operation. TemplateUtil provides several other functor converters. To use a functor converter, wherever you would use the functor, you call the conversion function on your functor. For example say you wrote a functor called WidgitTypeA that would return true if passed a widget of typeA. And you have a vector of widgets and you want to find the first widget that is not of type A. You could call find(vect.begin(), vect.end(), notl(WidgetTypeA())) The follwoing functor converters are provided:

When using STL there are situation where you want your predicate to operate on member data, or the return values of member functions. For example if you have a class that contains as member data an integer priority and you have a member function that returns that priority. However, that class also contains a time and the operator< for that class compares by that time. Now, if you want to sort a container of this class by the value of the priority, you want your predicate to call the priority function and compare the result of that call. The following functions are provided to create this kind of functor for you. You pass the function pointer of the member function and the predicate that you want to use to compare the return value of the member function. So to sort a vector of your class in ascending order by priority you would call sort(vect.begin(), vect.end(), const_comp_mem_fun_ref(&class::priority, less<int>()) The following member function converters are provided:

MPUTL also provides some standard comparison functors. These functors can be used for sorting containers of pointers. All comparison functors require that the predicate being operated on (the class contained by the container) have operator<() and/or operator==() The following comparison functors are provided:

MPUTL provides some useful unary functors. These operate on a single object:

MPUTL provides some functions that wrap STL calls and other TemplateUtil capabilities to make it easier to call:

TemplateUtil also provides a min and max function that are templatized and thus can be used on any type or class that has the operator<().


Function Documentation

template<typename Return, typename T, typename Pred>
comp_mem_fun_t<Return,T,Pred> TemplateUtil::comp_mem_fun Return(T::*)()  f,
Pred  p
[inline]
 

This is for accessing a non-constant member function operating on a container that contains the class by pointer

Definition at line 281 of file TemplateUtil.h.

template<typename Return, typename T, typename Pred>
comp_mem_fun_ref_t<Return,T,Pred> TemplateUtil::comp_mem_fun_ref Return(T::*)()  f,
Pred  p
[inline]
 

This is for accessing a non-constant member function operating on a container that contains the class by value

Definition at line 255 of file TemplateUtil.h.

template<typename Return, typename T, typename Pred>
const_comp_mem_fun_t<Return,T,Pred> TemplateUtil::const_comp_mem_fun Return(T::*)() const   f,
Pred  p
[inline]
 

This is for accessing a constant member function operating on a container that contains the class by pointer

Definition at line 229 of file TemplateUtil.h.

template<typename Return, typename T, typename Pred>
const_comp_mem_fun_ref_t<Return,T,Pred> TemplateUtil::const_comp_mem_fun_ref Return(T::*)() const   f,
Pred  p
[inline]
 

This is for accessing a constant member function operating on a container that contains the class by value

Definition at line 202 of file TemplateUtil.h.

template<typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator TemplateUtil::copy_if InputIterator  first,
InputIterator  last,
OutputIterator  dest,
Predicate  pred
 

This function will copy a range of values into the destination. You need to have allocated space for the elements prior to calling this function. See the documentation for the STL copy function for more information on how to provide this space This function fills a hole in STL. STL provides find, find_if and copy but no copy_if. Since this implementation is simple but non-obvious it is included here.

Definition at line 584 of file TemplateUtil.h.

template<typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator TemplateUtil::copy_second_if InputIterator  first,
InputIterator  last,
OutputIterator  dest,
Predicate  pred
 

This function will copy the second element of a pair into a new destination. You need to have allocated space for the elements in the destination before calling this function. See the copy_if function above. This function is mostly useful for flattening a map into a vector which contains all the second elements

Definition at line 606 of file TemplateUtil.h.

template<typename C>
void TemplateUtil::delete_all C &  collection  ) 
 

This function will delete all the elements in a collection of pointers and will erase them from the collection. This is a fast way to clean up a collection of pointers that you own.

Definition at line 456 of file TemplateUtil.h.

Referenced by VWorld::cleanup(), VLighting::cleanup(), and MObject::cleanup().

template<typename C>
void TemplateUtil::delete_all_second C &  collection  ) 
 

This is a specialized version of delete_all that operates on maps where the second element is a pointer that needs to be deleted. This function will iterate over the collection deleting the second element and will then erase the collection

Definition at line 471 of file TemplateUtil.h.

Referenced by MWorld::cleanup().

template<class Predicate>
unary_deref<Predicate> TemplateUtil::deref1 const Predicate &  p  ) 
 

Definition at line 166 of file TemplateUtil.h.

template<class Predicate>
binary_deref<Predicate> TemplateUtil::deref2 const Predicate &  p  ) 
 

Definition at line 171 of file TemplateUtil.h.

template<typename T, typename InputIterator, typename Comparator>
void TemplateUtil::erase_if T &  collection,
InputIterator  begin,
InputIterator  end,
const Comparator &  c
 

This function takes a collection, a range and a comparator. This is the same as the prior erase if, but only operates over a range of values in the collection

Definition at line 443 of file TemplateUtil.h.

template<typename T, typename Comparator>
void TemplateUtil::erase_if T &  collection,
const Comparator &  c
 

This function takes a collection and a comparator and will remove all elements in the collection for which the comparator returns true. It will also erase those elements from the collection. This function just wraps a call to col.erase(remove_if(col.begin(), col.end(), comparator)

Definition at line 431 of file TemplateUtil.h.

template<typename InputIterator, typename T>
InputIterator TemplateUtil::find_first InputIterator  first,
InputIterator  last,
const T &  v
 

This will find the first element in a collection of pairs where the first element of the pair matches the given value. Do not use this on maps as the built in methods are more efficient

Definition at line 551 of file TemplateUtil.h.

template<typename InputIterator, typename Type, typename Predicate>
InputIterator TemplateUtil::find_first_if InputIterator  first,
InputIterator  last,
const Predicate &  c
 

This is just like the above find_first except that instead of calling the operator==() it uses the given predicate

Definition at line 565 of file TemplateUtil.h.

template<typename InputIterator, typename T>
InputIterator TemplateUtil::find_second InputIterator  first,
InputIterator  last,
const T &  v
 

Works like find, but instead of looking at iterator, it uses iterator->second For vectors of pairs or maps.

Definition at line 522 of file TemplateUtil.h.

template<typename InputIterator, typename Type, typename Predicate>
InputIterator TemplateUtil::find_second_if InputIterator  first,
InputIterator  last,
const Predicate &  c
 

Works like find_if, but instead of looking at iterator, it uses iterator->second For vectors of pairs or maps.

Definition at line 536 of file TemplateUtil.h.

template<typename C, typename Function>
void TemplateUtil::for_all C &  collection,
Function  f
 

This function takes a collection and a function to be called on all the elements in that collection. This function just wraps a call to for_each(col.begin(), col.end(), func)

Definition at line 418 of file TemplateUtil.h.

template<typename type>
const type& TemplateUtil::max const type &  a,
const type &  b
 

This function will return the larger of the two arguments as determined by the operator<

Definition at line 625 of file TemplateUtil.h.

template<typename C>
void TemplateUtil::merge_ptr_col C &  dest,
const C &  source
 

This function works just like the mergeCol function in HCL. That is it calls the hclone() function on all the elements in the source collection and pushes them onto the end of the destination collection.

Definition at line 510 of file TemplateUtil.h.

template<typename type>
const type& TemplateUtil::min const type &  a,
const type &  b
 

This function will return the smaller of the two arguments as determined by the operator<

Definition at line 635 of file TemplateUtil.h.

Referenced by VControlPanel::updateGUI().

template<typename C>
void TemplateUtil::print_col C &  collection,
ostream &  os = cout,
const char *  d = "\n"
 

This function will send all the elements in a collection to the provided output stream (defaults to cout) separated by the provided char* (defaults to "\n"). Note that your elements need to override the operator<<() for this to work

Definition at line 485 of file TemplateUtil.h.

template<typename C>
void TemplateUtil::print_ptr_col C &  collection,
ostream &  os = cout,
const char *  d = "\n"
 

This function works just like the above print col, but it operates on a collection of pointers.

Definition at line 496 of file TemplateUtil.h.


Generated on Sat Dec 3 10:48:35 2005 for Robotics by  doxygen 1.4.5