CrystalSpace

Public API Reference

csArrayCmp< T, K > Class Template Reference
[Containers]

A functor template which encapsulates a key and a comparison function for use with key-related csArray searching methods, such as FindKey() and FindSortedKey(). More...

#include <csutil/array.h>

List of all members.

Public Types

typedef int(* CF )(T const &, K const &)
 Type of the comparison function which compares a key against an element contained in a csArray.

Public Member Functions

 csArrayCmp (csArrayCmp const &o)
 Construct a functor from another functor.
 csArrayCmp (K const &k, CF c=DefaultCompare)
 Construct a functor from a search key and a comparison function.
 operator CF () const
 Return the comparison function with which this functor was constructed.
 operator K const & () const
 Return the key with which this functor was constructed.
int operator() (T const &r) const
 Invoke the functor.
csArrayCmpoperator= (csArrayCmp const &o)
 Assign another functor to this one.

Static Public Member Functions

static int DefaultCompare (T const &r, K const &k)
 Compare two objects of the same type or different types (T and K).

Detailed Description

template<class T, class K>
class csArrayCmp< T, K >

A functor template which encapsulates a key and a comparison function for use with key-related csArray searching methods, such as FindKey() and FindSortedKey().

Being a template instaniated upon two (possibly distinct) types, this allows the searching methods to perform type-safe searches even when the search key type differs from the contained element type. The supplied search function defines the relationship between the search key and the contained element.

Definition at line 58 of file array.h.


Member Typedef Documentation

template<class T, class K>
typedef int(* csArrayCmp< T, K >::CF)(T const &, K const &)

Type of the comparison function which compares a key against an element contained in a csArray.

T is the type of the contained element. K is the type of the search key.

Definition at line 66 of file array.h.


Constructor & Destructor Documentation

template<class T, class K>
csArrayCmp< T, K >::csArrayCmp ( K const &  k,
CF  c = DefaultCompare 
) [inline]

Construct a functor from a search key and a comparison function.

Definition at line 68 of file array.h.

template<class T, class K>
csArrayCmp< T, K >::csArrayCmp ( csArrayCmp< T, K > const &  o  )  [inline]

Construct a functor from another functor.

Definition at line 70 of file array.h.


Member Function Documentation

template<class T, class K>
static int csArrayCmp< T, K >::DefaultCompare ( T const &  r,
K const &  k 
) [inline, static]

Compare two objects of the same type or different types (T and K).

Parameters:
r Reference to the element to which the key should be compared.
k Reference to the key to which the element should be compared.
Returns:
Zero if the key matches the element; less-than-zero if the element is less than the key; greater-than-zero if the element is greater than the key.
Remarks:
Assumes the presence of T::operator<(K) and K::operator<(T). Default comparison function if client does not supply one.

Definition at line 97 of file array.h.

template<class T, class K>
csArrayCmp< T, K >::operator CF (  )  const [inline]

Return the comparison function with which this functor was constructed.

Definition at line 84 of file array.h.

template<class T, class K>
csArrayCmp< T, K >::operator K const & (  )  const [inline]

Return the key with which this functor was constructed.

Definition at line 86 of file array.h.

template<class T, class K>
int csArrayCmp< T, K >::operator() ( T const &  r  )  const [inline]

Invoke the functor.

Parameters:
r Reference to the element to which the stored key should be compared.
Returns:
Zero if the key matches the element; less-than-zero if the element is less than the key; greater-than-zero if the element is greater than the key.

Definition at line 82 of file array.h.

template<class T, class K>
csArrayCmp& csArrayCmp< T, K >::operator= ( csArrayCmp< T, K > const &  o  )  [inline]

Assign another functor to this one.

Definition at line 72 of file array.h.


The documentation for this class was generated from the following file:

Generated for Crystal Space 2.1 by doxygen 1.6.1