sipxportlib  Version 3.3
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
UtlContainable Class Referenceabstract

#include <UtlContainable.h>

Inheritance diagram for UtlContainable:
Inheritance graph
[legend]

Public Member Functions

virtual ~UtlContainable ()
 
virtual UtlContainableType getContainableType () const =0
 
virtual unsigned hash () const =0
 Calculate a hash code for this object. More...
 
unsigned directHash () const
 Provides a hash function that uses the object pointer as the hash value. More...
 
virtual int compareTo (UtlContainable const *) const =0
 Compare this object to another object. More...
 
virtual UtlBoolean isEqual (UtlContainable const *) const
 Test this object to another object for equality. More...
 
virtual UtlBoolean isInstanceOf (const UtlContainableType type) const
 Determine if this object is a derivative of the specified UtlContainableType. More...
 

Static Public Member Functions

static unsigned stringHash (char const *value)
 Provides a hash function appropriate for null-terminated string values. More...
 
static UtlBoolean areSameTypes (const UtlContainableType type1, const UtlContainableType type2)
 Are UtlContainable types the same. More...
 

Static Public Attributes

static const UtlContainableType TYPE = "UtlContainable"
 

Detailed Description

An UtlContainable object is an abstract object that serves as the base class for anything that can be contained in one of the UtlContainer- derived classes. One of the largest values of a UtlContainable-derived object is the ability for any UtlContainer to destroy objects, sort objects, etc.

Constructor & Destructor Documentation

~UtlContainable ( )
virtual

< Class type used for runtime checking Destructor

Member Function Documentation

virtual UtlContainableType getContainableType ( ) const
pure virtual
virtual unsigned hash ( ) const
pure virtual

Calculate a hash code for this object.

The hash method should return a value that is a function of the key used to locate the object. As much as possible, hash values should be uniformly distributed over the range of legal unsigned values.

Requirements
if A.isEqual(B) then A.hash() must == B.hash()

Implemented in UtlString, OsTimer, OsMsg, OsContact, UtlContainer, UtlInt, UtlIntPtr, UtlLongLongInt, UtlVoidPtr, UtlBool, UtlDateTime, UtlContainablePair, DbEntry, and UtlContainableAtomic.

unsigned directHash ( ) const

Provides a hash function that uses the object pointer as the hash value.

This may be used by any UtlContainable class for which generating a value hash is difficult or not meaningful. Note that pointer values, since they are not uniformly distributed, probably make poor hash codes so this should not be used normally.

See also
stringHash

To use this, define your hash function as just:

unsigned int Foo::hash() const
{
return directHash();
}

If you use directHash as the hash method, you probably want to use pointer comparison as the compareTo method:

int Foo::compareTo(UtlContainable const* inVal) const
{
   int result ;
   result =
      this > other ? 1 :
      this < other ? -1 :
      0;
   return result;
}
unsigned stringHash ( char const *  value)
static

Provides a hash function appropriate for null-terminated string values.

To use this, define your hash function as just:

Foo hash()
{
return stringHash(value);
}
virtual int compareTo ( UtlContainable const *  ) const
pure virtual

Compare this object to another object.

Results of comparison to an object not of the same UtlContainableType may be undefined.

Returns
0 if equal, < 0 if less then and >0 if greater.
Requirements
  • if A.compareTo(B) == 0 then B.compareTo(A) must be == 0
  • if A.compareTo(B) < 0 then B.compareTo(A) must be > 0
  • if A.compareTo(B) > 0 then B.compareTo(A) must be < 0
  • if A.compareTo(B) < 0 and B.compareTo(C) < 0 then A.compareTo(C) must be < 0 etc.

Results for comparing with a non-like object are undefined, other than that it must return non-equal. Note that a copy of an object might not compare equal to the original, unless the definition of its type requires it.

Implemented in UtlString, OsTimer, OsMsg, OsContact, UtlContainer, UtlInt, UtlIntPtr, UtlVoidPtr, UtlLongLongInt, UtlBool, UtlDateTime, UtlContainablePair, DbEntry, and UtlContainableAtomic.

UtlBoolean isEqual ( UtlContainable const *  compareContainable) const
virtual

Test this object to another object for equality.

Results for objects not of the same UtlContainableType may be undefined.

A default implementation of this is provided that should be adequate for any UtlContainableType.

Reimplemented in UtlString, OsContact, UtlInt, UtlIntPtr, and UtlLongLongInt.

UtlBoolean areSameTypes ( const UtlContainableType  type1,
const UtlContainableType  type2 
)
static

Are UtlContainable types the same.

UtlBoolean isInstanceOf ( const UtlContainableType  type) const
virtual

Determine if this object is a derivative of the specified UtlContainableType.

Determine if this object is an instance of the designated runtime class identifer or one of its derivatives. For example:

if (pMyObject->isInstanceOf(UtlInt::TYPE))
{
    ...
}

If you want to determine if this object is exactly the same type as the given type (i.e. not a deriviative) use the following:

if(myObject->getContainableType() == UtlInt::TYPE)
{
    ...
}
Returns
TRUE/FALSE if this object is of the given type or a derivative of the given type.

Reimplemented in UtlString, UtlInt, UtlIntPtr, UtlBool, and UtlCopyableContainable.

Member Data Documentation

const UtlContainableType TYPE = "UtlContainable"
static