gloox  1.0.9
Classes | Functions
gloox::util Namespace Reference

Classes

class  AtomicRefCount
 A simple implementation of a thread safe 32-bit reference count. Native functions are used where possible. When not available, a mutex is used for locking and unlocking. More...
class  Mutex
 A simple implementation of mutex as a wrapper around a pthread mutex or a win32 critical section. More...
class  MutexGuard
 A simple implementation of a mutex guard. More...

Functions

int internalLog2 (unsigned int n)
unsigned _lookup (const std::string &str, const char *values[], unsigned size, int def)
const std::string _lookup (unsigned code, const char *values[], unsigned size, const std::string &def)
unsigned _lookup2 (const std::string &str, const char *values[], unsigned size, int def)
const std::string _lookup2 (unsigned code, const char *values[], unsigned size, const std::string &def)
std::string hex (const std::string &input)
const std::string escape (std::string what)
void appendEscaped (std::string &target, const std::string &data)
bool checkValidXMLChars (const std::string &data)
void replaceAll (std::string &target, const std::string &find, const std::string &replace)
template<typename T , typename F >
void ForEach (T &t, F f)
template<typename T , typename F , typename D >
void ForEach (T &t, F f, D &d)
template<typename T , typename F , typename D1 , typename D2 >
void ForEach (T &t, F f, D1 &d1, D2 &d2)
template<typename T , typename F , typename D1 , typename D2 , typename D3 >
void ForEach (T &t, F f, D1 &d1, D2 &d2, D3 &d3)
template<typename T >
void clearList (std::list< T * > &L)
template<typename Key , typename T >
void clearMap (std::map< Key, T * > &M)
template<typename Key , typename T >
void clearMap (std::map< const Key, T * > &M)

Detailed Description

A namespace holding a couple utility functions.

Function Documentation

GLOOX_API unsigned _lookup ( const std::string &  str,
const char *  values[],
unsigned  size,
int  def = -1 
)

Finds the enumerated value associated with a string value.

Parameters
strString to search for.
valuesArray of String/Code pairs to look into.
sizeThe array's size.
defDefault value returned in case the lookup failed.
Returns
The associated enum code.

Definition at line 35 of file util.cpp.

GLOOX_API const std::string _lookup ( unsigned  code,
const char *  values[],
unsigned  size,
const std::string &  def = EmptyString 
)

Finds the string associated with an enumerated type.

Parameters
codeCode of the string to search for.
valuesArray of String/Code pairs to look into.
sizeThe array's size.
defDefault value returned in case the lookup failed.
Returns
The associated string (empty in case there's no match).

Definition at line 43 of file util.cpp.

GLOOX_API unsigned _lookup2 ( const std::string &  str,
const char *  values[],
unsigned  size,
int  def = -1 
)

Finds the ORable enumerated value associated with a string value.

Parameters
strString to search for.
valuesArray of String/Code pairs to look into.
sizeThe array's size.
defThe default value to return if the lookup failed.
Returns
The associated enum code.

Definition at line 48 of file util.cpp.

GLOOX_API const std::string _lookup2 ( unsigned  code,
const char *  values[],
unsigned  size,
const std::string &  def = EmptyString 
)

Finds the string associated with an ORable enumerated type.

Parameters
codeCode of the string to search for.
valuesArray of String/Code pairs to look into.
sizeThe array's size.
defThe default value to return if the lookup failed.
Returns
The associated string (empty in case there's no match).

Definition at line 54 of file util.cpp.

GLOOX_API void appendEscaped ( std::string &  target,
const std::string &  data 
)

Append the data to the target, doing any necessary escaping along the way (& –> &amp;, etc). This method is faster than calling "escape" and appending the return value, especially for source strings that don't need any escaping.

Parameters
targetThe string to append the data to.
dataThe string to append that might need escaping.

Definition at line 95 of file util.cpp.

GLOOX_API bool checkValidXMLChars ( const std::string &  data)

Checks whether the given input is valid UTF-8.

Parameters
dataThe data to check for validity.
Returns
@b True if the input is valid UTF-8, false otherwise.

Definition at line 141 of file util.cpp.

void gloox::util::clearList ( std::list< T * > &  L)
inline

Delete all elements from a list of pointers.

Parameters
LList of pointers to delete.

Definition at line 152 of file util.h.

void gloox::util::clearMap ( std::map< Key, T * > &  M)
inline

Delete all associated values from a map (not the key elements).

Parameters
MMap of pointer values to delete.

Definition at line 169 of file util.h.

void gloox::util::clearMap ( std::map< const Key, T * > &  M)
inline

Delete all associated values from a map (not the key elements). Const key type version.

Parameters
MMap of pointer values to delete.

Definition at line 187 of file util.h.

GLOOX_API const std::string escape ( std::string  what)

Does some fancy escaping. (& –> &amp;, etc).

Note
If you intend to append the result of escape to another string, use the faster appendEscaped.
Parameters
whatA string to escape.
Returns
The escaped string.

Definition at line 77 of file util.cpp.

void gloox::util::ForEach ( T &  t,
f 
)
inline

A convenience function that executes the given function on each object in a given list.

Parameters
tThe object to execute the function on.
fThe function to execute.

Definition at line 96 of file util.h.

void gloox::util::ForEach ( T &  t,
f,
D &  d 
)
inline

A convenience function that executes the given function on each object in a given list, passing the given argument.

Parameters
tThe object to execute the function on.
fThe function to execute.
dAn argument to pass to the function.

Definition at line 110 of file util.h.

void gloox::util::ForEach ( T &  t,
f,
D1 &  d1,
D2 &  d2 
)
inline

A convenience function that executes the given function on each object in a given list, passing the given arguments.

Parameters
tThe object to execute the function on.
fThe function to execute.
d1An argument to pass to the function.
d2An argument to pass to the function.

Definition at line 125 of file util.h.

void gloox::util::ForEach ( T &  t,
f,
D1 &  d1,
D2 &  d2,
D3 &  d3 
)
inline

A convenience function that executes the given function on each object in a given list, passing the given arguments.

Parameters
tThe object to execute the function on.
fThe function to execute.
d1An argument to pass to the function.
d2An argument to pass to the function.
d3An argument to pass to the function.

Definition at line 141 of file util.h.

std::string hex ( const std::string &  input)

Returns the input string in hex notation.

Parameters
inputThe (binary) input string.
Returns
The input string in hex notation.

Definition at line 60 of file util.cpp.

GLOOX_API int internalLog2 ( unsigned int  n)

Custom log2() implementation.

Parameters
nFigure to take the logarithm from.
Returns
The logarithm to the basis of 2.

Definition at line 24 of file util.cpp.

GLOOX_API void replaceAll ( std::string &  target,
const std::string &  find,
const std::string &  replace 
)

Replace all instances of one substring of arbitrary length with another substring of arbitrary length. Replacement happens in place (so make a copy first if you don't want the original modified).

Parameters
targetThe string to process. Changes are made "in place".
findThe sub-string to find within the target string
replaceThe sub-string to substitute for the find string.
Todo:
Look into merging with util::escape() and Parser::decode().

Definition at line 177 of file util.cpp.