JASSv2
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
JASS::pointer_box< TYPE > Class Template Reference

A boxed pointer object used so that comparison operators work on the value pointed to rather than the pointer. More...

#include <pointer_box.h>

Collaboration diagram for JASS::pointer_box< TYPE >:
Collaboration graph
[legend]

Public Member Functions

 pointer_box ()
 Constructor.
 
 pointer_box (TYPE *to)
 Constructor. More...
 
int compare (const pointer_box< TYPE > to) const
 Compare for less than, equal, or greater than. More...
 
bool operator< (const pointer_box< TYPE > to) const
 Compare for less than (*a < *b) || (*a == *b && a < b). More...
 
bool operator< (TYPE *to) const
 Compare for less than (*a < *b) || (*a == *b && a < b). More...
 
bool operator<= (const pointer_box< TYPE > to) const
 Compare for less than or equal to. More...
 
bool operator> (const pointer_box< TYPE > to) const
 Compare for greater than. More...
 
bool operator>= (const pointer_box< TYPE > to) const
 Compare for greater than or equal to. More...
 
bool operator== (const pointer_box< TYPE > to) const
 Compare for equal to. More...
 
bool operator!= (const pointer_box< TYPE > to) const
 Compare for not equal to. More...
 
TYPE * pointer () const
 Return the pointer this box holds. More...
 
TYPE * operator-> () const
 Pointer to member operator. More...
 
TYPE & operator* () const
 Value of operator. More...
 

Static Public Member Functions

static int cmp (const pointer_box< TYPE > first, const pointer_box< TYPE > to)
 Compare for less than, equal, or greater than. More...
 
static bool less_than (TYPE *first, TYPE *to)
 Compare for less than (*a < *b) || (*a == *b && a < b). More...
 
static bool less_than (TYPE *first, const pointer_box< TYPE > to)
 Compare for less than (*a < *b) || (*a == *b && a < b). More...
 
static bool greater_than (TYPE *first, TYPE *to)
 Compare for more than (*a > *b) || (*a == *b && a > b). More...
 
static bool greater_than (TYPE *first, pointer_box< TYPE > to)
 Compare for more than (*a > *b) || (*a == *b && a > b). More...
 
static void unittest (void)
 Unit test this class.
 

Private Attributes

TYPE * element
 We actually store a reference to the object rather than a pointer, but they're the same size.
 

Detailed Description

template<typename TYPE>
class JASS::pointer_box< TYPE >

A boxed pointer object used so that comparison operators work on the value pointed to rather than the pointer.

All the usual pointer operations should work, except for comparisons which compare to the value pointed to rather than the pointer itself. This is useful when, for example, an ordered conatiner is being used to store pointers (or, for example, std::sort() an array of pointers based on the values those pointers point to). Note, ties are broken on the value of the pointer - that means that if the pointers are into an array then the earlier memeber of the array compares to less than the

Constructor & Destructor Documentation

◆ pointer_box()

template<typename TYPE>
JASS::pointer_box< TYPE >::pointer_box ( TYPE *  to)
inline

Constructor.

Parameters
to[in] The object we are being a pointer to.

Member Function Documentation

◆ cmp()

template<typename TYPE>
static int JASS::pointer_box< TYPE >::cmp ( const pointer_box< TYPE >  first,
const pointer_box< TYPE >  to 
)
inlinestatic

Compare for less than, equal, or greater than.

Parameters
first[in] The object we are Compareing to.
to[in] The object we are Compareing to.
Returns
-ve for less, 0 for equal, +ve for greater.

◆ compare()

template<typename TYPE>
int JASS::pointer_box< TYPE >::compare ( const pointer_box< TYPE >  to) const
inline

Compare for less than, equal, or greater than.

Parameters
to[in] The object we are Compareing to.
Returns
-ve for less, 0 for equal, +ve for greater.

◆ greater_than() [1/2]

template<typename TYPE>
static bool JASS::pointer_box< TYPE >::greater_than ( TYPE *  first,
TYPE *  to 
)
inlinestatic

Compare for more than (*a > *b) || (*a == *b && a > b).

Parameters
first[in] This object
to[in] The object we are comparing to.
Returns
true or false.

◆ greater_than() [2/2]

template<typename TYPE>
static bool JASS::pointer_box< TYPE >::greater_than ( TYPE *  first,
pointer_box< TYPE >  to 
)
inlinestatic

Compare for more than (*a > *b) || (*a == *b && a > b).

Parameters
first[in] This object
to[in] The object we are comparing to.
Returns
true or false.

◆ less_than() [1/2]

template<typename TYPE>
static bool JASS::pointer_box< TYPE >::less_than ( TYPE *  first,
TYPE *  to 
)
inlinestatic

Compare for less than (*a < *b) || (*a == *b && a < b).

Parameters
first[in] This object
to[in] The object we are comparing to.
Returns
true or false.

◆ less_than() [2/2]

template<typename TYPE>
static bool JASS::pointer_box< TYPE >::less_than ( TYPE *  first,
const pointer_box< TYPE >  to 
)
inlinestatic

Compare for less than (*a < *b) || (*a == *b && a < b).

Parameters
first[in] This object
to[in] The object we are comparing to.
Returns
true or false.

◆ operator!=()

template<typename TYPE>
bool JASS::pointer_box< TYPE >::operator!= ( const pointer_box< TYPE >  to) const
inline

Compare for not equal to.

Parameters
to[in] The object we are Compareing to.
Returns
true or false.

◆ operator*()

template<typename TYPE>
TYPE& JASS::pointer_box< TYPE >::operator* ( ) const
inline

Value of operator.

Returns
A reference to the value stored in the object

◆ operator->()

template<typename TYPE>
TYPE* JASS::pointer_box< TYPE >::operator-> ( ) const
inline

Pointer to member operator.

Returns
A pointer to the object

◆ operator<() [1/2]

template<typename TYPE>
bool JASS::pointer_box< TYPE >::operator< ( const pointer_box< TYPE >  to) const
inline

Compare for less than (*a < *b) || (*a == *b && a < b).

Parameters
to[in] The object we are comparing to.
Returns
true or false.

◆ operator<() [2/2]

template<typename TYPE>
bool JASS::pointer_box< TYPE >::operator< ( TYPE *  to) const
inline

Compare for less than (*a < *b) || (*a == *b && a < b).

Parameters
to[in] The object we are comparing to.
Returns
true or false.

◆ operator<=()

template<typename TYPE>
bool JASS::pointer_box< TYPE >::operator<= ( const pointer_box< TYPE >  to) const
inline

Compare for less than or equal to.

Parameters
to[in] The object we are Compareing to.
Returns
true or false.

◆ operator==()

template<typename TYPE>
bool JASS::pointer_box< TYPE >::operator== ( const pointer_box< TYPE >  to) const
inline

Compare for equal to.

Parameters
to[in] The object we are Compareing to.
Returns
true or false.

◆ operator>()

template<typename TYPE>
bool JASS::pointer_box< TYPE >::operator> ( const pointer_box< TYPE >  to) const
inline

Compare for greater than.

Parameters
to[in] The object we are Compareing to.
Returns
true or false.

◆ operator>=()

template<typename TYPE>
bool JASS::pointer_box< TYPE >::operator>= ( const pointer_box< TYPE >  to) const
inline

Compare for greater than or equal to.

Parameters
to[in] The object we are Compareing to.
Returns
true or false.

◆ pointer()

template<typename TYPE>
TYPE* JASS::pointer_box< TYPE >::pointer ( ) const
inline

Return the pointer this box holds.

Returns
The boxed pointer

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