Utility Functions

General-purpose functions. More...

Classes

class  utl::compareFn< T >
 Comparison functor. More...

Defines

#define utl_realloc(x, y, z)   _utl_realloc((void*)x,y,z)
 Front-end for _utl_realloc().
#define utl_strdup(x)   _utl_strdup((const char*)x)
 Front-end for _utl_strdup().

Enumerations

enum  utl::cmp_t {
  utl::cmp_lessThan, utl::cmp_lessThanOrEqualTo, utl::cmp_equalTo, utl::cmp_greaterThan,
  utl::cmp_greaterThanOrEqualTo
}
 Comparison operators. More...
enum  utl::serialize_t {
  utl::ser_readable = 1, utl::ser_compact = 2, utl::ser_nonportable = 4, utl::ser_noflags = 8,
  utl::ser_default = 16
}
 Specifies a serialization mode. More...
enum  utl::find_t { utl::find_any = 0, utl::find_first = 1, utl::find_last = 2, utl::find_ip = 3 }
 Find strategy. More...

Functions

void utl::init ()
 Initialize UTL++.
void utl::deInit ()
 De-initialize UTL++.
void utl::abort (const char *filename, int lineNo, const char *text=NULL)
 Abort the program - output a message to stderr explaining the reason for the failure, and the filename and line number where the abortion occurred.
void utl::abort (const char *text)
 Abort the program - output a message to stderr explaining the reason for the failure.
int utl::compare (bool lhs, bool rhs)
 Compare two boolean values.
void utl::die (const char *filename, int lineNo, const char *text=NULL, int exitCode=1)
 Abort the program - output a message to stderr explaining the reason for the failure, and the filename and line number where the failure occurred.
void utl::die (const char *text, int exitCode=1)
 Abort the program - output a message to stderr explaining the reason for the failure, and the filename and line number where the failure occurred.
uint_t utl::getSerializeMode ()
 Get the default serialization mode (see utl::serialize_t).
void utl::setSerializeMode (uint_t mode)
 Set the default serialization mode (see utl::serialize_t).
void * utl::utl_memcpy (void *dest, const void *src, uint_t n)
 Copy memory from one location to another.
void * utl::_utl_realloc (void *ptr, uint_t size, uint_t newSize)
 Re-allocate the given block.
char * utl::_utl_strdup (const char *str)
 Duplicate the given string.
void utl::serialize (bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boolean.
void utl::serialize (int8_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an 8-bit integer.
void utl::serialize (char &c, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a character.
void utl::serialize (uint8_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an 8-bit unsigned character.
void utl::serialize (int16_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a 16-bit integer.
void utl::serialize (uint16_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an unsigned 16-bit integer.
void utl::serialize (int32_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a 32-bit integer.
void utl::serialize (uint32_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an unsigned 32-bit integer.
void utl::serialize (long &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a long integer.
void utl::serialize (ulong_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an unsigned long integer.
void utl::serialize (double &n, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a double-precision floating point number.
void utl::serialize (Object &object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an object.
template<class T>
void utl::arrayGrow (T *&array, T *&arrayPtr, T *&arrayLim, ulong_t &arraySize, ulong_t minSize=ulong_t_max, ulong_t maxGrowth=K(1024))
 Grow an array.
template<class T>
void utl::arrayGrow (T *&array, ulong_t &arraySize, ulong_t minSize=ulong_t_max, ulong_t maxGrowth=K(1024), const T *defVal=NULL)
 Grow an array.
template<class T>
utl::min (const T &lhs, const T &rhs)
 Given two objects of the same type, determine the minimum.
template<class T>
utl::max (const T &lhs, const T &rhs)
 Given two objects of the same type, determine the maximum.
template<class T>
T * utl::clone (const T *object)
 Create a clone of the given object.
template<class T>
int utl::compare (const T &lhs, const T &rhs)
 Compare two objects of the same type.
template<class T>
int utl::compare (const T *lhs, const T *rhs, uint_t len)
 Compare two same-length arrays of objects of the same type.
template<class T>
int utl::compare (const T *lhs, uint_t lhsLen, const T *rhs, uint_t rhsLen)
 Compare two arrays of objects of the same type.
bool utl::cmpPredicate (int cmpRes, uint_t cmpOp)
 Determine whether the given comparison result is consistent with the given comparison operator.
template<class T>
void utl::copy (T *dest, const T *src, uint_t len)
 Copy one array of objects to another.
template<class T>
utl::roundUp (const T &v, const T &m)
 Round the given value v up to the nearest multiple of m.
template<class T>
utl::roundDown (const T &v, const T &m)
 Round the given value v down to the nearest multiple of m.
void utl::utl_memzero (void *ptr, uint_t size)
 Zero out a block of memory.
template<class T>
void utl::serialize (T *array, uint_t len, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an array.
template<class T>
void utl::serialize (T *&object, Stream &stream, uint_t io, uint_t mode)
 Serialize an object (boxed serialization).
template<class T>
void utl::serializeNullable (T *&p_object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a nullable object.
template<class T>
void utl::serializeBoxed (T *&p_object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boxed object.
int utl::cmp (const Object *lhs, const Object *rhs, const Ordering *ordering=NULL)
 Compare two objects.
int utl::cmpNullable (const Object *lhs, const Object *rhs, const Ordering *ordering=NULL)
 Compare two objects.
int utl::compare (const Object *lhs, const Object *rhs, const Ordering *ordering=NULL)
 Compare two objects.
int utl::compareNullable (const Object *lhs, const Object *rhs, const Ordering *ordering=NULL)
 Compare two objects.
template<class T>
void utl::swap (T *array, uint_t lhsIdx, uint_t rhsIdx)
 Swap two elements of the given array.
template<class T>
void utl::swap (T *array, uint_t lhsIdx, uint_t rhsIdx, uint_t size)
 Swap two sections of the given array.

Detailed Description

General-purpose functions.


Enumeration Type Documentation

enum utl::cmp_t

Comparison operators.

Enumerator:
cmp_lessThan  less-than
cmp_lessThanOrEqualTo  less-than-or-equal-to
cmp_equalTo  equal-to
cmp_greaterThan  greater-than
cmp_greaterThanOrEqualTo  greater-than-or-equal-to

Definition at line 26 of file Object.h.

Specifies a serialization mode.

See also:
Object::serialize
Enumerator:
ser_readable  human-readable, portable representation
ser_compact  space-efficient, portable representation
ser_nonportable  nonportable, time-efficient representation
ser_noflags  do not serialize flags
ser_default  default representation (via getSerializeMode())

Definition at line 36 of file util.h.

Find strategy.

Enumerator:
find_any  find any matching object
find_first  find first matching object
find_last  find last matching object
find_ip  find insertion point

Definition at line 13 of file util_inl.h.


Function Documentation

void utl::init (  ) 

void utl::deInit (  ) 

De-initialize UTL++.

This function is called by Application's destructor, so when your application class inherits from Application (as recommended) you won't need to worry about calling this function.

void utl::abort ( const char *  filename,
int  lineNo,
const char *  text = NULL 
)

Abort the program - output a message to stderr explaining the reason for the failure, and the filename and line number where the abortion occurred.

On a UNIX platform, this will also cause a core dump to be generated.

Parameters:
filename filename where abortion occurred
lineNo line number where abortion occurred
text message explaining the reason for the failure

void utl::abort ( const char *  text  ) 

Abort the program - output a message to stderr explaining the reason for the failure.

On a UNIX platform, this will also cause a core dump to be generated.

Parameters:
text message explaining the reason for the failure

int utl::compare ( bool  lhs,
bool  rhs 
)

Compare two boolean values.

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side boolean value
rhs right-hand-side boolean value

Referenced by utl::VectorMD< T >::compare(), utl::Vector< T >::compare(), utl::compare(), utl::Span< T, D >::compare(), and utl::Number< T >::compare().

void utl::die ( const char *  filename,
int  lineNo,
const char *  text = NULL,
int  exitCode = 1 
)

Abort the program - output a message to stderr explaining the reason for the failure, and the filename and line number where the failure occurred.

Unlike abort, die exits with a given error code instead of dumping core.

Parameters:
filename filename where failure occurred
lineNo line number where failure occurred
text message explaining the reason for the failure
exitCode exit code

void utl::die ( const char *  text,
int  exitCode = 1 
)

Abort the program - output a message to stderr explaining the reason for the failure, and the filename and line number where the failure occurred.

Unlike abort, die exits with a given error code instead of dumping core.

Parameters:
text message explaining the reason for the failure
exitCode exit code

uint_t utl::getSerializeMode (  ) 

Get the default serialization mode (see utl::serialize_t).

See also:
Object::serialize

Referenced by utl::serialize().

void utl::setSerializeMode ( uint_t  mode  ) 

Set the default serialization mode (see utl::serialize_t).

See also:
Object::serialize

void* utl::utl_memcpy ( void *  dest,
const void *  src,
uint_t  n 
)

Copy memory from one location to another.

Correct behavior is guaranteed even when the source and destination regions overlap.

Returns:
address destination address
Parameters:
dest destination address
src source address
n number of bytes to copy

void* utl::_utl_realloc ( void *  ptr,
uint_t  size,
uint_t  newSize 
)

Re-allocate the given block.

The macro utl_realloc provides convenient access to this function.

Returns:
address of re-allocated block
Parameters:
ptr address of block to re-allocate
size current size of block
newSize new size of block

char* utl::_utl_strdup ( const char *  str  ) 

Duplicate the given string.

The macro utl_strdup provides convenient access to this function.

Returns:
address of newly allocated block
Parameters:
str string to duplicate

void utl::serialize ( bool &  b,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a boolean.

Parameters:
b boolean to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

Referenced by utl::VectorMD< T >::serialize(), utl::Vector< T >::serialize(), and utl::Span< T, D >::serialize().

void utl::serialize ( int8_t &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize an 8-bit integer.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( char &  c,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a character.

Parameters:
c character to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( uint8_t &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize an 8-bit unsigned character.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( int16_t &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a 16-bit integer.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( uint16_t &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize an unsigned 16-bit integer.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( int32_t &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a 32-bit integer.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( uint32_t &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize an unsigned 32-bit integer.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( long &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a long integer.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( ulong_t &  i,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize an unsigned long integer.

Parameters:
i integer to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( double &  n,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a double-precision floating point number.

Parameters:
n double to serialize to/from stream
stream stream to serialize to/from
io see io_t
mode see serialize_t

void utl::serialize ( Object &  object,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize an object.

Parameters:
object object to serialize to/from stream
stream stream to serialize to/from
io io_rd : serializeIn(), io_wr : serializeOut()
mode see serialize_t

template<class T>
void utl::arrayGrow ( T *&  array,
T *&  arrayPtr,
T *&  arrayLim,
ulong_t &  arraySize,
ulong_t  minSize = ulong_t_max,
ulong_t  maxGrowth = K(1024) 
) [inline]

Grow an array.

Parameters:
array array to grow
arrayPtr index into array
arrayLim end of array
arraySize size of array
minSize minimum size
maxGrowth limit growth

Definition at line 35 of file util_inl.h.

References utl::arrayGrow().

template<class T>
void utl::arrayGrow ( T *&  array,
ulong_t &  arraySize,
ulong_t  minSize = ulong_t_max,
ulong_t  maxGrowth = K(1024),
const T *  defVal = NULL 
) [inline]

Grow an array.

Parameters:
array array to grow
arraySize array size
minSize grow to at least this size
maxGrowth (optional) limit growth
defVal (optional) default value for new objects

Definition at line 62 of file util_inl.h.

References utl::ulong_t_max.

Referenced by utl::arrayGrow().

template<class T>
T utl::min ( const T &  lhs,
const T &  rhs 
) [inline]

Given two objects of the same type, determine the minimum.

Returns:
lhs if lhs < rhs, otherwise rhs
Parameters:
lhs left-hand-side object
rhs right-hand-side object

Definition at line 120 of file util_inl.h.

Referenced by utl::compare(), utl::ArithmeticEncoder::decode(), utl::Span< utl::Time, utl::Duration >::merge(), utl::multiKeyQuickSort(), utl::Span< T, D >::overlap(), utl::Span< T, D >::overlapSize(), and utl::Time::Time().

template<class T>
T utl::max ( const T &  lhs,
const T &  rhs 
) [inline]

Given two objects of the same type, determine the maximum.

Returns:
lhs if lhs > rhs, otherwise rhs
Parameters:
lhs left-hand-side object
rhs right-hand-side object

Definition at line 143 of file util_inl.h.

Referenced by utl::BoyerMooreSearch< T >::find(), utl::Span< utl::Time, utl::Duration >::merge(), utl::Span< T, D >::overlap(), and utl::Span< T, D >::overlapSize().

template<class T>
T* utl::clone ( const T *  object  )  [inline]

Create a clone of the given object.

Returns:
newly created copy (NULL if object == NULL)
Parameters:
object object to clone

Definition at line 165 of file util_inl.h.

Referenced by utl::SpanCol< uint_t, uint_t >::add(), utl::Collection::add(), utl::Array::add(), utl::ComparisonPredicate::ComparisonPredicate(), utl::TRandIt< T >::copy(), utl::TFwdIt< T >::copy(), utl::TBidIt< T >::copy(), utl::Array::set(), and utl::UnaryPredicate::setObject().

template<class T>
int utl::compare ( const T &  lhs,
const T &  rhs 
) [inline]

Compare two objects of the same type.

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side object
rhs right-hand-side object

Definition at line 185 of file util_inl.h.

template<class T>
int utl::compare ( const T *  lhs,
const T *  rhs,
uint_t  len 
) [inline]

Compare two same-length arrays of objects of the same type.

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side sequence
rhs right-hand-side sequence
len lhs and rhs sequence length

Definition at line 234 of file util_inl.h.

References utl::compare().

template<class T>
int utl::compare ( const T *  lhs,
uint_t  lhsLen,
const T *  rhs,
uint_t  rhsLen 
) [inline]

Compare two arrays of objects of the same type.

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side sequence
lhsLen lhs sequence length
rhs right-hand-side sequence
rhsLen rhs sequence length

Definition at line 261 of file util_inl.h.

References utl::compare(), and utl::min().

bool utl::cmpPredicate ( int  cmpRes,
uint_t  cmpOp 
) [inline]

Determine whether the given comparison result is consistent with the given comparison operator.

Returns:
true if cmpRes is consistent with cmpOp, false otherwise
Parameters:
cmpRes comparison result (see compare(), cmp(), etc.)
cmpOp comparison operator (see cmp_t)

Definition at line 289 of file util_inl.h.

References utl::cmp_greaterThan, and utl::cmp_lessThan.

template<class T>
void utl::copy ( T *  dest,
const T *  src,
uint_t  len 
) [inline]

Copy one array of objects to another.

Parameters:
dest destination sequence
src source sequence
len source sequence length

Definition at line 313 of file util_inl.h.

Referenced by utl::VectorMD< T >::copy().

template<class T>
T utl::roundUp ( const T &  v,
const T &  m 
) [inline]

Round the given value v up to the nearest multiple of m.

Returns:
if v is already a multiple of m, then return v, otherwise return v + (v % m)
Parameters:
v value to round up
m rounding factor

Definition at line 334 of file util_inl.h.

template<class T>
T utl::roundDown ( const T &  v,
const T &  m 
) [inline]

Round the given value v down to the nearest multiple of m.

Returns:
if v is already a multiple of m, then return v, otherwise return v - (v % m)
Parameters:
v value to round down
m rounding factor

Definition at line 353 of file util_inl.h.

void utl::utl_memzero ( void *  ptr,
uint_t  size 
) [inline]

Zero out a block of memory.

Parameters:
ptr address of block
size size of block

Definition at line 367 of file util_inl.h.

template<class T>
void utl::serialize ( T *  array,
uint_t  len,
Stream &  stream,
uint_t  io,
uint_t  mode = ser_default 
) [inline]

Serialize an array.

Parameters:
array array to serialize to/from stream
len array length
stream stream to serialize to/from
io see io_t
mode see serialize_t

Definition at line 385 of file util_inl.h.

References utl::getSerializeMode(), utl::ser_default, and utl::serialize().

template<class T>
void utl::serialize ( T *&  object,
Stream &  stream,
uint_t  io,
uint_t  mode 
) [inline]

Serialize an object (boxed serialization).

Parameters:
object object to serialize
stream stream to serialize to/from
io see io_t
mode see serialize_t

Definition at line 412 of file util_inl.h.

References utl::serializeBoxed().

Referenced by utl::Vector< T >::serialize(), utl::serialize(), utl::ObjectSpan< T, D >::serialize(), utl::Span< T, D >::serialize(), utl::Number< T >::serialize(), utl::Collection::serialize(), and utl::Object::serializeIn().

int utl::cmp ( const Object *  lhs,
const Object *  rhs,
const Ordering *  ordering = NULL 
) [inline]

Compare two objects.

If an Ordering is given it will be used, otherwise Object::cmp() will perform the comparison.

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side object
rhs right-hand-side object
ordering (optional) ordering

Definition at line 497 of file util_inl.h.

References ASSERTD, and utl::Object::cmp().

Referenced by utl::GreaterThanOrEqualTo::eval(), utl::GreaterThan::eval(), utl::LessThanOrEqualTo::eval(), utl::LessThan::eval(), utl::EqualTo::eval(), utl::multiKeyInsertionSort(), utl::multiKeyMedianOfThree(), utl::multiKeyQuickSort(), utl::Object::operator!=(), utl::Ordering::operator()(), utl::Object::operator<(), utl::Object::operator<=(), utl::Object::operator==(), utl::Object::operator>(), and utl::Object::operator>=().

int utl::cmpNullable ( const Object *  lhs,
const Object *  rhs,
const Ordering *  ordering = NULL 
) [inline]

Compare two objects.

This function is just like cmp, but it can deal with one or both of the objects being NULL. If one object is NULL, the other is considered greater. If they are both NULL, they are considered equal. Otherwise, its behavior is identical to that of cmp.

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side object
rhs right-hand-side object
ordering (optional) ordering

Definition at line 523 of file util_inl.h.

References utl::Object::cmp().

Referenced by utl::RCobject::cmp(), and utl::ComparisonPredicate::cmp().

int utl::compare ( const Object *  lhs,
const Object *  rhs,
const Ordering *  ordering = NULL 
) [inline]

Compare two objects.

If an Ordering is given it will be used, otherwise Object::compare() will perform the comparison.

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side object
rhs right-hand-side object
ordering (optional) ordering

Definition at line 551 of file util_inl.h.

References ASSERTD, and utl::Object::compare().

int utl::compareNullable ( const Object *  lhs,
const Object *  rhs,
const Ordering *  ordering = NULL 
) [inline]

Compare two objects.

This function is just like compare(), but it can deal with one or both of the objects being NULL. If one object is NULL, the other is considered greater. If they are both NULL, they are considered equal. Otherwise, its behavior is identical to that of compare().

Returns:
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters:
lhs left-hand-side object
rhs right-hand-side object
ordering (optional) ordering to use

Definition at line 578 of file util_inl.h.

References utl::Object::compare().

Referenced by utl::TRandIt< T >::compare(), utl::TFwdIt< T >::compare(), utl::TBidIt< T >::compare(), and utl::RCobject::compare().

template<class T>
void utl::swap ( T *  array,
uint_t  lhsIdx,
uint_t  rhsIdx 
) [inline]

Swap two elements of the given array.

Parameters:
array given array
lhsIdx index of lhs element
rhsIdx index of rhs element

Definition at line 605 of file util_inl.h.

Referenced by utl::multiKeyQuickSort().

template<class T>
void utl::swap ( T *  array,
uint_t  lhsIdx,
uint_t  rhsIdx,
uint_t  size 
) [inline]

Swap two sections of the given array.

Parameters:
array given array
lhsIdx index of lhs segment
rhsIdx index of rhs segment
size size of segments to be swapped

Definition at line 624 of file util_inl.h.


Generated on Tue May 26 16:53:05 2009 for libUTL++ by  doxygen 1.5.6