|
libUTL++
|
General-purpose functions. More...
Classes | |
| class | utl::compareFn< T > |
| Comparison functor. More... | |
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_default = 8 } |
| 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::realloc (void *ptr, size_t size, size_t newSize) |
| Re-allocate the given block. | |
| char * | 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. | |
| size_t | utl::allocatedSize (const Object *object) |
| Create a clone of the given object. | |
| template<typename T > | |
| void | utl::arrayGrow (T *&array, size_t &arraySize, size_t minSize=size_t_max, size_t maxGrowth=size_t_max, const T *defVal=NULL) |
| Grow an array. | |
| template<typename T > | |
| void | utl::arrayGrow (T *&array, T *&arrayPtr, T *&arrayLim, size_t minSize=size_t_max, size_t maxGrowth=size_t_max) |
| Grow an array. | |
| template<typename T > | |
| const T & | utl::min (const T &lhs, const T &rhs) |
| Given two objects of the same type, determine the minimum. | |
| template<typename T > | |
| const T & | utl::max (const T &lhs, const T &rhs) |
| Given two objects of the same type, determine the maximum. | |
| template<typename T > | |
| T & | utl::cast (const utl::Object &object) |
| Safely cast an object to the desired type. | |
| template<typename T > | |
| T * | utl::clone (const T *object) |
| Create a clone of the given object. | |
| template<typename T > | |
| int | utl::compare (const T &lhs, const T &rhs) |
| Compare two objects of the same type. | |
| template<typename T > | |
| int | utl::compare (const T *lhs, const T *rhs, size_t len) |
| Compare two same-length arrays of objects of the same type. | |
| template<typename T > | |
| int | utl::compare (const T *lhs, size_t lhsLen, const T *rhs, size_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<typename T > | |
| void | utl::copy (T *dest, const T *src, size_t len) |
| Copy one array of objects to another. | |
| template<typename T > | |
| T | utl::roundUp (const T &v, const T &m) |
| Round the given value v up to the nearest multiple of m. | |
| template<typename T > | |
| T | utl::roundDown (const T &v, const T &m) |
| Round the given value v down to the nearest multiple of m. | |
| template<typename T > | |
| void | utl::serialize (T *array, size_t len, Stream &stream, uint_t io, uint_t mode=ser_default) |
| Serialize an array. | |
| template<typename T > | |
| void | utl::serialize (T *&object, Stream &stream, uint_t io, uint_t mode) |
| Serialize an object (boxed serialization). | |
| template<typename T > | |
| void | utl::serializeNullable (T *&p_object, Stream &stream, uint_t io, uint_t mode=ser_default) |
| Serialize a nullable object. | |
| template<typename T > | |
| void | utl::serializeBoxed (T *&p_object, Stream &stream, uint_t io, uint_t mode=ser_default) |
| Serialize a boxed object. | |
| 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<typename T > | |
| void | utl::swap (T *array, size_t lhsIdx, size_t rhsIdx) |
| Swap two elements of the given array. | |
| template<typename T > | |
| void | utl::swap (T *array, size_t lhsIdx, size_t rhsIdx, size_t size) |
| Swap two sections of the given array. | |
General-purpose functions.
| enum utl::cmp_t |
| enum utl::serialize_t |
Specifies a serialization mode.
| ser_readable |
human-readable, portable representation |
| ser_compact |
space-efficient, portable representation |
| ser_nonportable |
nonportable, time-efficient representation |
| ser_default |
default representation (via getSerializeMode()) |
| enum utl::find_t |
Find strategy.
| 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 17 of file util_inl.h.
| void utl::init | ( | ) |
Initialize UTL++.
This function is called by Application's constructor, so when your application class inherits from Application (as recommended) you won't need to worry about calling this function.
Referenced by utl::Allocator::Allocator(), utl::AutoPtr< T >::AutoPtr(), utl::BinTreeBfsIt::BinTreeBfsIt(), utl::BinTreeNode::BinTreeNode(), utl::BitArray::BitArray(), utl::BitArrayElem::BitArrayElem(), utl::BoyerMooreSearch< T >::BoyerMooreSearch(), utl::BtreeIt::BtreeIt(), utl::BWTencoder::BWTencoder(), utl::CmdLineArgs::CmdLineArgs(), utl::DBresultIterator::DBresultIterator(), utl::Directory::Directory(), utl::ExtArray::ExtArray(), utl::ExtCache::ExtCache(), utl::ExtCacheIt::ExtCacheIt(), utl::FileSpec::FileSpec(), utl::FSobject::FSobject(), utl::Hashtable::Hashtable(), utl::Heap::Heap(), utl::HuffmanEncoder::HuffmanEncoder(), utl::IOmux::IOmux(), utl::ListNode::ListNode(), utl::LZencoder::LZencoder(), utl::MemStream::MemStream(), utl::NetServer::NetServer(), utl::ObjectCache::ObjectCache(), utl::ObjectRegistry::ObjectRegistry(), utl::Regex::Regex(), utl::RLencoder::RLencoder(), utl::Semaphore::Semaphore(), utl::SkipList::SkipList(), utl::SlistNode::SlistNode(), utl::SyslogStream::SyslogStream(), utl::URI::URI(), utl::Vector< T >::Vector(), and utl::Vertex::Vertex().
| 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.
Referenced by utl::AutoPtr< T >::~AutoPtr().
| 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.
| 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.
| text | message explaining the reason for the failure |
| int utl::compare | ( | bool | lhs, |
| bool | rhs | ||
| ) |
Compare two boolean values.
| lhs | left-hand-side boolean value |
| rhs | right-hand-side boolean value |
Referenced by utl::TBidIt< T >::compare(), utl::TFwdIt< T >::compare(), utl::TRandIt< T >::compare(), utl::VectorMD< T >::compare(), utl::Number< T >::compare(), utl::Span< T, D >::compare(), utl::Vector< T >::compare(), utl::compare(), utl::Object::operator!=(), utl::String::operator!=(), utl::compareFn< T >::operator()(), utl::Object::operator<(), utl::String::operator<(), utl::Object::operator<=(), utl::String::operator<=(), utl::Object::operator==(), utl::String::operator==(), utl::Object::operator>(), utl::String::operator>(), utl::Object::operator>=(), and utl::String::operator>=().
| 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.
| 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.
| text | message explaining the reason for the failure |
| exitCode | exit code |
| uint_t utl::getSerializeMode | ( | ) |
Get the default serialization mode (see utl::serialize_t).
Referenced by utl::serialize().
| void utl::setSerializeMode | ( | uint_t | mode | ) |
Set the default serialization mode (see utl::serialize_t).
| void* utl::realloc | ( | void * | ptr, |
| size_t | size, | ||
| size_t | newSize | ||
| ) |
Re-allocate the given block.
| ptr | address of block to re-allocate |
| size | current size of block |
| newSize | new size of block |
| char* utl::strdup | ( | const char * | str | ) |
Duplicate the given string.
| str | string to duplicate |
| void utl::serialize | ( | bool & | b, |
| Stream & | stream, | ||
| uint_t | io, | ||
| uint_t | mode = ser_default |
||
| ) |
Serialize a boolean.
| 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::Number< T >::serialize(), utl::Span< T, D >::serialize(), utl::Vector< T >::serialize(), utl::serialize(), and utl::Object::serializeIn().
| void utl::serialize | ( | int8_t & | i, |
| Stream & | stream, | ||
| uint_t | io, | ||
| uint_t | mode = ser_default |
||
| ) |
Serialize an 8-bit integer.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| object | object to serialize to/from stream |
| stream | stream to serialize to/from |
| io | io_rd : serializeIn(), io_wr : serializeOut() |
| mode | see serialize_t |
|
inline |
Create a clone of the given object.
| object | object to clone |
Definition at line 34 of file util_inl.h.
| void utl::arrayGrow | ( | T *& | array, |
| size_t & | arraySize, | ||
| size_t | minSize = size_t_max, |
||
| size_t | maxGrowth = size_t_max, |
||
| const T * | defVal = NULL |
||
| ) |
Grow an array.
| 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 53 of file util_inl.h.
References utl::size_t_max.
Referenced by utl::arrayGrow().
| void utl::arrayGrow | ( | T *& | array, |
| T *& | arrayPtr, | ||
| T *& | arrayLim, | ||
| size_t | minSize = size_t_max, |
||
| size_t | maxGrowth = size_t_max |
||
| ) |
Grow an array.
| array | array to grow |
| arrayPtr | index into array |
| arrayLim | end of array |
| minSize | minimum size |
| maxGrowth | limit growth |
Definition at line 102 of file util_inl.h.
References utl::arrayGrow().
| const T& utl::min | ( | const T & | lhs, |
| const T & | rhs | ||
| ) |
Given two objects of the same type, determine the minimum.
| lhs | left-hand-side object |
| rhs | right-hand-side object |
Definition at line 127 of file util_inl.h.
Referenced by utl::compare(), utl::ArithmeticEncoder::decode(), utl::Span< Time, Duration >::merge(), utl::multiKeyQuickSort(), utl::Span< T, D >::overlap(), utl::Span< T, D >::overlapSize(), utl::Vector< T >::reverse(), and utl::Time::Time().
| const T& utl::max | ( | const T & | lhs, |
| const T & | rhs | ||
| ) |
Given two objects of the same type, determine the maximum.
| lhs | left-hand-side object |
| rhs | right-hand-side object |
Definition at line 141 of file util_inl.h.
Referenced by utl::BoyerMooreSearch< T >::find(), utl::Span< Time, Duration >::merge(), utl::Span< T, D >::overlap(), and utl::Span< T, D >::overlapSize().
| T& utl::cast | ( | const utl::Object & | object | ) |
Safely cast an object to the desired type.
| object | object to clone |
Definition at line 154 of file util_inl.h.
| T* utl::clone | ( | const T * | object | ) |
Create a clone of the given object.
| object | object to clone |
Definition at line 170 of file util_inl.h.
Referenced by utl::SpanCol< size_t, size_t >::add(), utl::Collection::add(), utl::Array::add(), utl::Collection::addOrUpdate(), utl::ComparisonPredicate::ComparisonPredicate(), utl::TBidIt< T >::copy(), utl::TRandIt< T >::copy(), utl::TFwdIt< T >::copy(), utl::Array::set(), and utl::UnaryPredicate::setObject().
|
inline |
Compare two objects of the same type.
| lhs | left-hand-side object |
| rhs | right-hand-side object |
Definition at line 187 of file util_inl.h.
| int utl::compare | ( | const T * | lhs, |
| const T * | rhs, | ||
| size_t | len | ||
| ) |
Compare two same-length arrays of objects of the same type.
| lhs | left-hand-side sequence |
| rhs | right-hand-side sequence |
| len | lhs and rhs sequence length |
Definition at line 227 of file util_inl.h.
References utl::compare().
| int utl::compare | ( | const T * | lhs, |
| size_t | lhsLen, | ||
| const T * | rhs, | ||
| size_t | rhsLen | ||
| ) |
Compare two arrays of objects of the same type.
| lhs | left-hand-side sequence |
| lhsLen | lhs sequence length |
| rhs | right-hand-side sequence |
| rhsLen | rhs sequence length |
Definition at line 254 of file util_inl.h.
References utl::compare(), and utl::min().
|
inline |
Determine whether the given comparison result is consistent with the given comparison operator.
| cmpRes | comparison result (see compare(), cmp(), etc.) |
| cmpOp | comparison operator (see cmp_t) |
Definition at line 282 of file util_inl.h.
References utl::cmp_greaterThan, and utl::cmp_lessThan.
| void utl::copy | ( | T * | dest, |
| const T * | src, | ||
| size_t | len | ||
| ) |
Copy one array of objects to another.
| dest | destination sequence |
| src | source sequence |
| len | source sequence length |
Definition at line 306 of file util_inl.h.
Referenced by utl::SpanAllocator< T, D >::copy(), utl::VectorMD< T >::copy(), utl::Number< T >::copy(), and utl::Vector< T >::copy().
|
inline |
Round the given value v up to the nearest multiple of m.
| v | value to round up |
| m | rounding factor |
Definition at line 327 of file util_inl.h.
| T utl::roundDown | ( | const T & | v, |
| const T & | m | ||
| ) |
Round the given value v down to the nearest multiple of m.
| v | value to round down |
| m | rounding factor |
Definition at line 346 of file util_inl.h.
| void utl::serialize | ( | T * | array, |
| size_t | len, | ||
| Stream & | stream, | ||
| uint_t | io, | ||
| uint_t | mode = ser_default |
||
| ) |
Serialize an array.
| 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 362 of file util_inl.h.
References utl::getSerializeMode(), utl::ser_default, and utl::serialize().
| void utl::serialize | ( | T *& | object, |
| Stream & | stream, | ||
| uint_t | io, | ||
| uint_t | mode | ||
| ) |
Serialize an object (boxed serialization).
| object | object to serialize |
| stream | stream to serialize to/from |
| io | see io_t |
| mode | see serialize_t |
Definition at line 389 of file util_inl.h.
References utl::serializeBoxed().
|
inline |
Compare two objects.
If an Ordering is given it will be used, otherwise Object::compare() will perform the comparison.
| lhs | left-hand-side object |
| rhs | right-hand-side object |
| ordering | (optional) ordering |
Definition at line 462 of file util_inl.h.
References ASSERTD, and utl::Object::compare().
|
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().
| lhs | left-hand-side object |
| rhs | right-hand-side object |
| ordering | (optional) ordering to use |
Definition at line 489 of file util_inl.h.
References utl::Object::compare().
Referenced by utl::ComparisonPredicate::cmp(), utl::TRandIt< T >::compare(), utl::TFwdIt< T >::compare(), and utl::TBidIt< T >::compare().
| void utl::swap | ( | T * | array, |
| size_t | lhsIdx, | ||
| size_t | rhsIdx | ||
| ) |
Swap two elements of the given array.
| array | given array |
| lhsIdx | index of lhs element |
| rhsIdx | index of rhs element |
Definition at line 516 of file util_inl.h.
Referenced by utl::multiKeyQuickSort().
| void utl::swap | ( | T * | array, |
| size_t | lhsIdx, | ||
| size_t | rhsIdx, | ||
| size_t | size | ||
| ) |
Swap two sections of the given array.
| array | given array |
| lhsIdx | index of lhs segment |
| rhsIdx | index of rhs segment |
| size | size of segments to be swapped |
Definition at line 535 of file util_inl.h.