libUTL++
Utility

Various general-purpose functions. More...

Classes

struct  utl::PointerLikeTraits< PtrT >
 Pointer-like traits. More...
 
class  utl::PointerIntPairBase
 Non-template base class for PointerIntPair. More...
 
class  utl::PointerIntPair< PtrT, IntBits, IntT, PtrTraits >
 (Pointer,Int) pair. More...
 
class  utl::BoolToggle
 Toggle a boolean value RAII-style. More...
 
struct  utl::comparisonFunctor< T >
 Object comparison evaluator. More...
 
struct  utl::equals< T >
 Object comparison predicate evaluator that returns the value of (lhs == rhs). More...
 
struct  utl::lessThan< T >
 Object comparison predicate evaluator that returns the value of (lhs < rhs). 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::find_t { utl::find_any = 0, utl::find_first = 1, utl::find_last = 2, utl::find_ip = 3 }
 Find strategy. More...
 
enum  utl::io_t { utl::io_null = 0, utl::io_rd = 1, utl::io_wr = 2, utl::io_rdwr = 3 }
 I/O flags. 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...
 

Functions

void utl::init ()
 Initialize UTL++. More...
 
void utl::deInit ()
 De-initialize UTL++. More...
 
void utl::abort (const char *filename, int lineNo, const char *text=nullptr)
 Abort the process. More...
 
void utl::abort (const char *text)
 Abort the process. More...
 
int utl::compare (bool lhs, bool rhs)
 Compare two boolean values. More...
 
void utl::die (const char *filename, int lineNo, const char *text=nullptr, int exitCode=1)
 Exit the process with an error code. More...
 
void utl::die (const char *text, int exitCode=1)
 Exit the process with an error code. More...
 
uint_t utl::getSerializeMode ()
 Get the default serialization mode (see utl::serialize_t). More...
 
void utl::setSerializeMode (uint_t mode)
 Set the default serialization mode (see utl::serialize_t). More...
 
void * utl::realloc (void *ptr, size_t size, size_t newSize)
 Re-allocate the given block. More...
 
char * utl::strdup (const char *str)
 Duplicate the given string. More...
 
SSL_CTX * utl::sslContext ()
 Get a pointer to the global SSL context. More...
 
bool utl::sslVerifyLocations (const char *caFile, const char *caPath)
 Set default locations for trusted CA certificates. More...
 
void utl::serialize (bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boolean. More...
 
void utl::serialize (int8_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an 8-bit integer. More...
 
void utl::serialize (char &c, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a character. More...
 
void utl::serialize (uint8_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an 8-bit unsigned character. More...
 
void utl::serialize (int16_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a 16-bit integer. More...
 
void utl::serialize (uint16_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an unsigned 16-bit integer. More...
 
void utl::serialize (int32_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a 32-bit integer. More...
 
void utl::serialize (uint32_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an unsigned 32-bit integer. More...
 
void utl::serialize (long &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a long integer. More...
 
void utl::serialize (ulong_t &i, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an unsigned long integer. More...
 
void utl::serialize (double &n, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a double-precision floating point number. More...
 
void utl::serialize (Object &object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an object. More...
 
template<typename T , typename... R>
const T & utl::min (const T &a, const T &b, const R &... args)
 Return the smallest value among two or more provided values of the same type. More...
 
template<typename T , typename... R>
const T & utl::max (const T &a, const T &b, const R &... args)
 Return the largest value among two or more provided values of the same type. More...
 
size_t utl::allocatedSize (const Object *object)
 Compute the allocated size of an object. More...
 
template<typename T >
void utl::arrayGrow (T *&array, size_t &arraySize, size_t minSize=size_t_max, size_t growthIncrement=size_t_max, const T *defVal=nullptr)
 Grow an array. More...
 
template<typename T >
void utl::arrayGrow (T *&array, T *&arrayPtr, T *&arrayLim, size_t minSize=size_t_max, size_t growthIncrement=size_t_max)
 Grow an array. More...
 
template<typename T >
const T & utl::cast (const utl::Object &object)
 Safely cast an object to the desired type. More...
 
template<typename T >
T & utl::cast (utl::Object &object)
 Safely cast an object to the desired type. More...
 
template<typename T >
const T * utl::cast (const utl::Object *object)
 Safely cast an object pointer to the desired type. More...
 
template<typename T >
T * utl::cast (utl::Object *object)
 Safely cast an object pointer to the desired type. More...
 
template<typename T >
T & utl::cast_const (const utl::Object &object)
 Safely cast an object reference to the desired type (remove const-qualifier). More...
 
template<typename T >
T * utl::cast_const (const utl::Object *object)
 Safely cast an object pointer to the desired type (remove const-qualifier). More...
 
template<typename T >
T * utl::clone (const T *object)
 Create a clone of the given object. More...
 
template<typename T >
int utl::compare (const T &lhs, const T &rhs)
 Compare two objects of the same type. More...
 
int utl::compare (const Object *lhs, const Object *rhs, const Ordering *ordering=nullptr)
 Compare two objects. More...
 
int utl::compareNullable (const Object *lhs, const Object *rhs, const Ordering *ordering=nullptr)
 Compare two objects. More...
 
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. More...
 
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. More...
 
template<typename InputCont1 , typename InputCont2 >
int utl::compare (typename InputCont1::const_iterator lhsBegin, typename InputCont1::const_iterator lhsEnd, typename InputCont2::const_iterator rhsBegin, typename InputCont2::const_iterator rhsEnd, std::function< int(typename InputCont1::value_type, typename InputCont2::value_type)> comp)
 Compare two sequences. More...
 
bool utl::comparisonResultMatchesOp (int cmpRes, uint_t cmpOp)
 Determine whether the given comparison result is consistent with the given comparison operator. More...
 
template<typename T >
void utl::copy (T *dest, const T *src, size_t len)
 Copy one array of objects to another. More...
 
template<typename T >
utl::roundUp (const T &v, const T &m)
 Round the given value v up to the nearest multiple of m. More...
 
template<typename T >
utl::roundDown (const T &v, const T &m)
 Round the given value v down to the nearest multiple of m. More...
 
template<typename T >
void utl::serialize (T *array, size_t len, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an array. More...
 
template<typename T >
void utl::serialize (T *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an object (boxed). More...
 
template<typename T >
void utl::serialize (T &object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize an object (non-boxed). More...
 
template<typename T >
void utl::serializeNullable (T *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a nullable object. More...
 
template<typename T >
void utl::serializeBoxed (T *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boxed object. More...
 
uint16_t utl::reverseBytes (uint16_t n)
 Reverse the byte ordering of a 16-bit unsigned integer. More...
 
uint32_t utl::reverseBytes (uint32_t n)
 Reverse the byte ordering of a 32-bit unsigned integer. More...
 
uint64_t utl::reverseBytes (uint64_t n)
 Reverse the byte ordering of a 64-bit unsigned integer. More...
 
template<typename T >
void utl::swap (T *array, size_t lhsIdx, size_t rhsIdx)
 Swap two elements of the given array. More...
 
template<typename T >
void utl::swap (T *array, size_t lhsIdx, size_t rhsIdx, size_t size)
 Swap two sections of the given array. More...
 
void utl::clobber ()
 Fake read/write access to all memory. More...
 
void utl::escape (void *ptr)
 Fake read/write access to all memory, and require the object at address ptr to exist. More...
 
constexpr size_t utl::KB (size_t n)
 Convert size in kilobytes to size in bytes. More...
 
constexpr size_t utl::MB (size_t n)
 Convert size in megabytes to size in bytes. More...
 
constexpr size_t utl::GB (size_t n)
 Convert size in gigabytes to size in bytes. More...
 

Detailed Description

Various general-purpose functions.

Enumeration Type Documentation

◆ cmp_t

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 util.h.

◆ find_t

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 41 of file util.h.

◆ io_t

enum utl::io_t

I/O flags.

Enumerator
io_null 

null value

io_rd 

read

io_wr 

write

io_rdwr 

read/write

Definition at line 55 of file util.h.

◆ serialize_t

Specifies a serialization mode.

See also
Object::serialize
Enumerator
ser_readable 

human-readable and portable representation

ser_compact 

space-efficient and portable representation

ser_nonportable 

nonportable space- and time-efficient representation

ser_default 

default representation (via getSerializeMode())

Definition at line 70 of file util.h.

Function Documentation

◆ init()

void utl::init ( )

Initialize UTL++.

This function is called by utl::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::Stream::_indentIfBOL(), utl::SpanAllocator< T, D >::alloc(), utl::AutoPtr< T >::AutoPtr(), utl::Base64decode::Base64decode(), utl::Base64encode::Base64encode(), utl::Base64encoder::Base64encoder(), utl::BinaryData::BinaryData(), utl::BinTreeBfsIt::BinTreeBfsIt(), utl::BinTreeNode::BinTreeNode(), utl::BitArray::BitArray(), utl::FDstream::blockingIO(), utl::HttpResponse::body(), utl::BoyerMooreSearch< T >::BoyerMooreSearch(), utl::BufferedStream::BufferedStream(), utl::BWTencoder::BWTencoder(), utl::Thread::cancel(), utl::DBconnection::clearResult(), utl::CmdLineArgs::CmdLineArgs(), utl::StringVars::container(), utl::DBresultIterator::DBresultIterator(), utl::Directory::Directory(), utl::StringTranslator::dump(), utl::DBresult::errorMsg(), utl::IsA::eval(), utl::ExtArray::ExtArray(), utl::ServerSocket::fd(), utl::FileSpec::FileSpec(), utl::Decimal::floor(), utl::FSobject::FSobject(), utl::CRC32::get(), utl::HeapIt::getIdx(), utl::CachedObject::getKey(), utl::Heap::getMax(), utl::HashtableIt::getNode(), utl::Hashtable::Hashtable(), utl::HttpRequest::header(), utl::Heap::Heap(), utl::HttpRequest::HttpRequest(), utl::HuffmanEncoder::HuffmanEncoder(), utl::IOmux::IOmux(), utl::MultiKeyOrdering::isDescending(), utl::ListNode::ListNode(), utl::LZencoder::LZencoder(), utl::MemStream::MemStream(), utl::NetServer::NetServer(), utl::ObjectCache::ObjectCache(), utl::ObjectRegistry::ObjectRegistry(), utl::RDparser::ok(), utl::Regex::ok(), utl::Bool::operator bool(), utl::String::operator const void *(), utl::Number< T >::operator T(), utl::AutoPtr< T >::operator T*(), utl::CmdLineArgs::operator()(), utl::Collection::operator()(), utl::Array::operator()(), utl::Vector< uint_t >::operator+(), utl::DBresultIterator::operator++(), utl::Span< Time, Duration >::operator+=(), utl::URI::operator+=(), utl::ArrayIt::operator-(), utl::TFwdIt< T >::operator=(), utl::TBidIt< T >::operator=(), utl::TRandIt< T >::operator=(), utl::ExtArray::operator[](), utl::BitArray::operator[](), utl::FwdIt::owner(), utl::Deque::pushBack(), utl::List::pushBack(), utl::LogMgr::putLine(), utl::Regex::Regex(), utl::SpanAllocator< T, D >::remove(), utl::SpanCol< T, D >::remove(), utl::RLencoder::RLencoder(), utl::Semaphore::Semaphore(), utl::BinTree::serializeFast(), utl::BoyerMooreSearch< T >::set(), utl::DequeIt::set(), utl::SlistNode::set(), utl::ListNode::set(), utl::ArithmeticEncoder::setContext(), utl::ObjectCache::setFrozen(), utl::Hashtable::setHashFunction(), utl::MemStream::setIncrement(), utl::Encoder::setLastBlock(), utl::BufferedStream::setLineBuffered(), utl::Translator::setMapping(), utl::InetHostAddress::setNil(), utl::BinTreeBfsIt::setNode(), utl::ListIt::setNode(), utl::BinTreeIt::setNode(), utl::SkipListIt::setNode(), utl::Vertex::setObject(), utl::UnaryPredicate::setObject(), utl::ComparisonPredicate::setOrdering(), utl::Base64encode::setOutputStream(), utl::Base64decode::setOutputStream(), utl::BoyerMooreSearch< T >::setOwner(), utl::BinaryPredicate::setRHS(), utl::BinTreeNode::setRight(), utl::Pair::setSecondOwner(), utl::Graph::setStart(), utl::ParseNode::setToken(), utl::DBfield::size(), utl::SkipList::SkipList(), utl::SlistNode::SlistNode(), utl::IOmux::streams(), utl::Vector< uint_t >::swap(), utl::SyslogStream::SyslogStream(), utl::Exception::takeObject(), utl::Token::Token(), utl::TCollection< Vertex >::toString(), utl::ArithContext::totFreq(), utl::RWlock::trylock(), utl::RWlockLF::trylock(), utl::SyslogStream::underflow(), utl::URI::URI(), utl::Semaphore::V(), utl::Vector< uint_t >::Vector(), and utl::Vertex::Vertex().

◆ deInit()

void utl::deInit ( )

De-initialize UTL++.

This function is called by utl::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::Stream::_indentIfBOL(), utl::Base64encoder::Base64encoder(), utl::BinaryData::BinaryData(), utl::FDstream::blockingIO(), utl::HttpResponse::body(), utl::BWTencoder::BWTencoder(), utl::Thread::cancel(), utl::DBconnection::clearResult(), utl::StringVars::container(), utl::StringTranslator::dump(), utl::DBresult::errorMsg(), utl::IsA::eval(), utl::ServerSocket::fd(), utl::FileSpec::FileSpec(), utl::Decimal::floor(), utl::CRC32::get(), utl::HeapIt::getIdx(), utl::CachedObject::getKey(), utl::Heap::getMax(), utl::HashtableIt::getNode(), utl::HttpRequest::header(), utl::HuffmanEncoder::HuffmanEncoder(), utl::MultiKeyOrdering::isDescending(), utl::LZencoder::LZencoder(), utl::NetServer::NetServer(), utl::RDparser::ok(), utl::Regex::ok(), utl::Bool::operator bool(), utl::String::operator const void *(), utl::Number< T >::operator T(), utl::AutoPtr< T >::operator T*(), utl::CmdLineArgs::operator()(), utl::Collection::operator()(), utl::Array::operator()(), utl::Vector< uint_t >::operator+(), utl::DBresultIterator::operator++(), utl::Span< Time, Duration >::operator+=(), utl::URI::operator+=(), utl::ArrayIt::operator-(), utl::TFwdIt< T >::operator=(), utl::TBidIt< T >::operator=(), utl::TRandIt< T >::operator=(), utl::ExtArray::operator[](), utl::BitArray::operator[](), utl::FwdIt::owner(), utl::Deque::pushBack(), utl::List::pushBack(), utl::LogMgr::putLine(), utl::SpanAllocator< T, D >::remove(), utl::SpanCol< T, D >::remove(), utl::RLencoder::RLencoder(), utl::BinTree::serializeFast(), utl::DequeIt::set(), utl::ArithmeticEncoder::setContext(), utl::ObjectCache::setFrozen(), utl::Hashtable::setHashFunction(), utl::MemStream::setIncrement(), utl::Encoder::setLastBlock(), utl::BufferedStream::setLineBuffered(), utl::Translator::setMapping(), utl::InetHostAddress::setNil(), utl::BinTreeBfsIt::setNode(), utl::ListIt::setNode(), utl::BinTreeIt::setNode(), utl::SkipListIt::setNode(), utl::Vertex::setObject(), utl::UnaryPredicate::setObject(), utl::ComparisonPredicate::setOrdering(), utl::Base64encode::setOutputStream(), utl::Base64decode::setOutputStream(), utl::BoyerMooreSearch< T >::setOwner(), utl::BinaryPredicate::setRHS(), utl::BinTreeNode::setRight(), utl::Pair::setSecondOwner(), utl::Graph::setStart(), utl::ParseNode::setToken(), utl::DBfield::size(), utl::SkipList::SkipList(), utl::IOmux::streams(), utl::Exception::takeObject(), utl::Token::Token(), utl::TCollection< Vertex >::toString(), utl::ArithContext::totFreq(), utl::RWlock::trylock(), utl::RWlockLF::trylock(), utl::SyslogStream::underflow(), utl::Semaphore::V(), and utl::AutoPtr< T >::~AutoPtr().

◆ abort() [1/2]

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

Abort the process.

Parameters
filenamefilename where abortion occurred
lineNoline number where abortion occurred
textmessage explaining the reason for the failure

◆ abort() [2/2]

void utl::abort ( const char *  text)

Abort the process.

Parameters
textmessage explaining the reason for the failure

◆ compare() [1/6]

◆ die() [1/2]

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

Exit the process with an error code.

Parameters
filenamefilename where failure occurred
lineNoline number where failure occurred
textmessage explaining the reason for the failure
exitCodeexit code

◆ die() [2/2]

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

Exit the process with an error code.

Parameters
textmessage explaining the reason for the failure
exitCodeexit code

◆ getSerializeMode()

uint_t utl::getSerializeMode ( )

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

See also
Object::serialize

Referenced by utl::serialize().

◆ setSerializeMode()

void utl::setSerializeMode ( uint_t  mode)

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

See also
Object::serialize

◆ realloc()

void* utl::realloc ( void *  ptr,
size_t  size,
size_t  newSize 
)

Re-allocate the given block.

Returns
address of re-allocated block
Parameters
ptraddress of block to re-allocate
sizecurrent size of block
newSizenew size of block

Referenced by utl::Vector< uint_t >::swap().

◆ strdup()

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

Duplicate the given string.

Returns
address of newly allocated block
Parameters
strstring to duplicate

◆ sslContext()

SSL_CTX* utl::sslContext ( )

Get a pointer to the global SSL context.

Returns
global SSL_CTX*

◆ sslVerifyLocations()

bool utl::sslVerifyLocations ( const char *  caFile,
const char *  caPath 
)

Set default locations for trusted CA certificates.

Returns
true iff the operation succeeded
Parameters
caFilepath to a file of CA certificates in PEM format
caPathpath to a directory containing CA certificates in PEM format

◆ serialize() [1/15]

◆ serialize() [2/15]

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

Serialize an 8-bit integer.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [3/15]

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

Serialize a character.

Parameters
ccharacter to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [4/15]

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

Serialize an 8-bit unsigned character.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [5/15]

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

Serialize a 16-bit integer.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [6/15]

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

Serialize an unsigned 16-bit integer.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [7/15]

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

Serialize a 32-bit integer.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [8/15]

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

Serialize an unsigned 32-bit integer.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [9/15]

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

Serialize a long integer.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [10/15]

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

Serialize an unsigned long integer.

Parameters
iinteger to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [11/15]

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

Serialize a double-precision floating point number.

Parameters
ndouble to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ serialize() [12/15]

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

Serialize an object.

Parameters
objectobject to serialize to/from stream
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

◆ min()

template<typename T , typename... R>
const T& utl::min ( const T &  a,
const T &  b,
const R &...  args 
)

Return the smallest value among two or more provided values of the same type.

Returns
the largest value
Parameters
afirst object
bsecond object
argsadditional objects (if any)

Definition at line 61 of file util_inl.h.

References utl::min().

Referenced by utl::Vector< uint_t >::assertOwner(), utl::Vector< uint_t >::copy(), utl::ArithmeticEncoder::decode(), utl::Time::get(), utl::Span< Time, Duration >::merge(), utl::Vector< uint_t >::move(), utl::multiKeyQuickSort(), utl::Span< Time, Duration >::overlap(), utl::BoyerMooreSearch< T >::set(), utl::Time::set(), utl::Vector< uint_t >::swap(), and utl::Time::Time().

◆ max()

template<typename T , typename... R>
const T& utl::max ( const T &  a,
const T &  b,
const R &...  args 
)

Return the largest value among two or more provided values of the same type.

Returns
the largest of the provided values
Parameters
afirst object
bsecond object
argsadditional objects (if any)

Definition at line 89 of file util_inl.h.

References utl::max().

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

◆ allocatedSize()

size_t utl::allocatedSize ( const Object object)
inline

Compute the allocated size of an object.

Returns
allocated size of object (0 if object is null)
Parameters
objectobject to invoke utl::Object::allocatedSize() on

Definition at line 191 of file util_inl.h.

Referenced by utl::Object::serializeBoxed().

◆ arrayGrow() [1/2]

template<typename T >
void utl::arrayGrow ( T *&  array,
size_t &  arraySize,
size_t  minSize = size_t_max,
size_t  growthIncrement = size_t_max,
const T *  defVal = nullptr 
)

Grow an array.

Parameters
arrayarray to grow
arraySizearray size
minSizegrow to at least this size
growthIncrement(optional) growth increment
defVal(optional) default value for new objects

Definition at line 211 of file util_inl.h.

References ASSERTD, utl::nextMultipleOfPow2(), utl::nextPow2(), and utl::size_t_max.

◆ arrayGrow() [2/2]

template<typename T >
void utl::arrayGrow ( T *&  array,
T *&  arrayPtr,
T *&  arrayLim,
size_t  minSize = size_t_max,
size_t  growthIncrement = size_t_max 
)

Grow an array.

Parameters
arrayarray to grow
arrayPtrindex into array
arrayLimend of array
minSizeminimum size
growthIncrementlimit growth

Definition at line 284 of file util_inl.h.

◆ cast() [1/4]

template<typename T >
const T& utl::cast ( const utl::Object object)
inline

Safely cast an object to the desired type.

In a DEBUG build, trigger an assertion failure if the cast cannot be done.

Definition at line 307 of file util_inl.h.

References ASSERTD, and isA.

◆ cast() [2/4]

template<typename T >
T& utl::cast ( utl::Object object)
inline

Safely cast an object to the desired type.

In a DEBUG build, trigger an assertion failure if the cast cannot be done.

Definition at line 323 of file util_inl.h.

References ASSERTD, and isA.

◆ cast() [3/4]

template<typename T >
const T* utl::cast ( const utl::Object object)
inline

Safely cast an object pointer to the desired type.

In a DEBUG build, trigger an assertion failure if the cast cannot be done.

Definition at line 339 of file util_inl.h.

References ASSERTD.

◆ cast() [4/4]

template<typename T >
T* utl::cast ( utl::Object object)
inline

Safely cast an object pointer to the desired type.

In a DEBUG build, trigger an assertion failure if the cast cannot be done.

Definition at line 355 of file util_inl.h.

References ASSERTD.

◆ cast_const() [1/2]

template<typename T >
T& utl::cast_const ( const utl::Object object)
inline

Safely cast an object reference to the desired type (remove const-qualifier).

In a DEBUG build, trigger an assertion failure if the cast cannot be done.

Definition at line 371 of file util_inl.h.

References ASSERTD, and isA.

◆ cast_const() [2/2]

template<typename T >
T* utl::cast_const ( const utl::Object object)
inline

Safely cast an object pointer to the desired type (remove const-qualifier).

In a DEBUG build, trigger an assertion failure if the cast cannot be done.

Definition at line 387 of file util_inl.h.

References ASSERTD.

◆ clone()

◆ compare() [2/6]

template<typename 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
lhsleft-hand-side object
rhsright-hand-side object

Definition at line 422 of file util_inl.h.

◆ compare() [3/6]

int utl::compare ( const Object lhs,
const Object rhs,
const Ordering ordering = nullptr 
)
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
lhsleft-hand-side object
rhsright-hand-side object
ordering(optional) ordering

Definition at line 442 of file util_inl.h.

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

◆ compareNullable()

int utl::compareNullable ( const Object lhs,
const Object rhs,
const Ordering ordering = nullptr 
)
inline

Compare two objects.

This function is just like compare(), but it can deal with one or both of the object pointers being null. If exactly one object pointer is null, the object referenced by the other pointer is considered greater. If both object pointers are null, this function returns 0. Otherwise, its behavior is identical to compare().

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

Definition at line 466 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().

◆ compare() [4/6]

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.

Returns
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters
lhsleft-hand-side sequence
rhsright-hand-side sequence
lenlhs and rhs sequence length

Definition at line 492 of file util_inl.h.

References utl::compare().

◆ compare() [5/6]

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.

Returns
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs
Parameters
lhsleft-hand-side sequence
lhsLenlhs sequence length
rhsright-hand-side sequence
rhsLenrhs sequence length

Definition at line 520 of file util_inl.h.

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

◆ compare() [6/6]

template<typename InputCont1 , typename InputCont2 >
int utl::compare ( typename InputCont1::const_iterator  lhsBegin,
typename InputCont1::const_iterator  lhsEnd,
typename InputCont2::const_iterator  rhsBegin,
typename InputCont2::const_iterator  rhsEnd,
std::function< int(typename InputCont1::value_type, typename InputCont2::value_type)>  comp 
)

Compare two sequences.

Parameters
lhsBeginbegin of lhs sequence
lhsEndend of lhs sequence
rhsBeginbegin of rhs sequence
rhsEndend of rhs sequence
compcomparison function
Returns
< 0 if lhs < rhs, 0 if lhs = rhs, > 0 if lhs > rhs

Definition at line 554 of file util_inl.h.

References ABORT.

◆ comparisonResultMatchesOp()

bool utl::comparisonResultMatchesOp ( 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
cmpRescomparison result (see compare(), cmp(), etc.)
cmpOpcomparison operator (see utl::cmp_t)

Definition at line 587 of file util_inl.h.

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

◆ copy()

◆ roundUp()

template<typename 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
vvalue to round up
mrounding factor

Definition at line 728 of file util_inl.h.

Referenced by utl::Time::setCurrent().

◆ roundDown()

template<typename 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
vvalue to round down
mrounding factor

Definition at line 747 of file util_inl.h.

Referenced by utl::Time::setCurrent().

◆ serialize() [13/15]

template<typename T >
void utl::serialize ( T *  array,
size_t  len,
Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize an array.

Parameters
arrayarray to serialize to/from stream
lenarray length
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

Definition at line 766 of file util_inl.h.

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

◆ serialize() [14/15]

template<typename T >
void utl::serialize ( T *&  object,
Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)
inline

Serialize an object (boxed).

Parameters
objectobject to serialize
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

Definition at line 789 of file util_inl.h.

References utl::serializeBoxed().

◆ serialize() [15/15]

template<typename T >
void utl::serialize ( T &  object,
Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)
inline

Serialize an object (non-boxed).

Parameters
objectobject to serialize
streamstream to serialize to/from
iosee utl::io_t
modesee utl::serialize_t

Definition at line 807 of file util_inl.h.

Referenced by utl::serialize().

◆ serializeNullable()

template<typename T >
void utl::serializeNullable ( T *&  object,
Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a nullable object.

Parameters
objectobject pointer (by reference)
streamstream to serialize to/from
ioio_rd or io_wr
mode(optional : ser_default) serialization mode

Definition at line 825 of file util_inl.h.

References utl::io_rd.

Referenced by utl::Object::serializeOut().

◆ serializeBoxed()

template<typename T >
void utl::serializeBoxed ( T *&  object,
Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize a boxed object.

Parameters
objectobject pointer (by reference)
streamstream to serialize to/from
ioio_rd or io_wr
mode(optional : ser_default) serialization mode

Definition at line 853 of file util_inl.h.

References utl::io_rd.

Referenced by utl::serialize().

◆ reverseBytes() [1/3]

uint16_t utl::reverseBytes ( uint16_t  n)
inline

Reverse the byte ordering of a 16-bit unsigned integer.

Returns
16-bit integer with bytes reversed
Parameters
nthe integer to be byte-reversed

Definition at line 878 of file util_inl.h.

◆ reverseBytes() [2/3]

uint32_t utl::reverseBytes ( uint32_t  n)
inline

Reverse the byte ordering of a 32-bit unsigned integer.

Returns
32-bit integer with bytes reversed
Parameters
nthe integer to be byte-reversed

Definition at line 893 of file util_inl.h.

◆ reverseBytes() [3/3]

uint64_t utl::reverseBytes ( uint64_t  n)
inline

Reverse the byte ordering of a 64-bit unsigned integer.

Returns
64-bit integer with bytes reversed
Parameters
nthe integer to be byte-reversed

Definition at line 910 of file util_inl.h.

◆ swap() [1/2]

template<typename T >
void utl::swap ( T *  array,
size_t  lhsIdx,
size_t  rhsIdx 
)
inline

Swap two elements of the given array.

Parameters
arraygiven array
lhsIdxindex of lhs element
rhsIdxindex of rhs element

Definition at line 930 of file util_inl.h.

Referenced by utl::BWTencoder::BWTencoder(), utl::multiKeyQuickSort(), utl::Vector< uint_t >::reverse(), utl::Vector< uint_t >::setIncrement(), and utl::Vector< uint_t >::swap().

◆ swap() [2/2]

template<typename T >
void utl::swap ( T *  array,
size_t  lhsIdx,
size_t  rhsIdx,
size_t  size 
)

Swap two sections of the given array.

Parameters
arraygiven array
lhsIdxindex of lhs segment
rhsIdxindex of rhs segment
sizesize of segments to be swapped

Definition at line 950 of file util_inl.h.

◆ clobber()

void utl::clobber ( )
inline

Fake read/write access to all memory.

You can invoke clobber() to force the compiler to assume prior writes will be observed.

Definition at line 973 of file util_inl.h.

◆ escape()

void utl::escape ( void *  ptr)
inline

Fake read/write access to all memory, and require the object at address ptr to exist.

The compiler can't optimize away *ptr (regardless of size or type) if its address will be used.

Parameters
ptrthe address of an object we want to not be optimized away

Definition at line 990 of file util_inl.h.

◆ KB()

constexpr size_t utl::KB ( size_t  n)

Convert size in kilobytes to size in bytes.

Returns
number of bytes
Parameters
nnumber of kilobytes

Definition at line 1008 of file util_inl.h.

Referenced by utl::BWTencoder::BWTencoder(), utl::Bytes::Bytes(), utl::BufferedStream::getStream(), utl::Encoder::setCRC(), utl::MemStream::setIncrement(), utl::BufferedStream::setLineBuffered(), and utl::Stream::unindent().

◆ MB()

constexpr size_t utl::MB ( size_t  n)

Convert size in megabytes to size in bytes.

Returns
number of bytes
Parameters
nnumber of kilobytes

Definition at line 1023 of file util_inl.h.

Referenced by utl::Bytes::Bytes().

◆ GB()

constexpr size_t utl::GB ( size_t  n)

Convert size in gigabytes to size in bytes.

Returns
number of bytes
Parameters
nnumber of kilobytes

Definition at line 1038 of file util_inl.h.