gloox  1.0
Classes | Functions
gloox::util Namespace Reference

Classes

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)
const std::string escape (std::string what)
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 33 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 41 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 46 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 52 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 82 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 144 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 161 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 179 of file util.h.

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

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

Parameters
whatA string to escape.
Returns
The escaped string.

Definition at line 64 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 88 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 102 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 117 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 133 of file util.h.

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 22 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 101 of file util.cpp.