xorp

policy_utils Namespace Reference

Some generic utility functions used by different policy components. More...

Classes

class  PolicyUtilsErr
 Generic exception for errors. More...

Functions

void str_to_list (const string &in, list< string > &out)
 Converts a string in the form "1,2,...,n" to a list of strings.
void str_to_set (const string &in, set< string > &out)
 Converts a string in the form "1,2,...,n" to a set of strings.
void read_file (const string &fname, string &out)
 Reads a file into a string.
unsigned count_nl (const char *x)
 Count the occurences of newlines in the c-style string.
bool regex (const string &str, const string &reg)
 Match a regex.
template<class T >
void delete_vector (vector< T * > *v)
 Deletes a vector by deleting objects and deleting the vector itself.
template<class T >
void clear_container (T &l)
 Deletes objects in container.
template<class A , class T >
void clear_map (map< A, T * > &m)
 Delets objects of a map and clears the map at the end.
template<class T >
void clear_map_container (T &m)
 Delets objects of a map-like container and clears the map at the end.
template<class T >
string to_str (T x)
 Converts an object to a string via an ostringstream.

Detailed Description

Some generic utility functions used by different policy components.


Function Documentation

template<class T >
void policy_utils::clear_container ( T &  l)

Deletes objects in container.

Checks if objects are null and skips them if so.

The container is cleared at the end.

Parameters:
lcontainer to be deleted and cleared.
template<class A , class T >
void policy_utils::clear_map ( map< A, T * > &  m)

Delets objects of a map and clears the map at the end.

Checks for null objects.

Parameters:
mmap to be deleted and cleared.
template<class T >
void policy_utils::clear_map_container ( T &  m)

Delets objects of a map-like container and clears the map at the end.

Checks for null objects.

Parameters:
mmap-like container to be deleted and cleared.
unsigned policy_utils::count_nl ( const char *  x)

Count the occurences of newlines in the c-style string.

Returns:
the number of new lines in the string.
Parameters:
xthe 0 terminated c-style string to count new lines in.
template<class T >
void policy_utils::delete_vector ( vector< T * > *  v)

Deletes a vector by deleting objects and deleting the vector itself.

It checks if objects are null and skips them if so. Also checks if vector itself is null.

Parameters:
vvector to delete
void policy_utils::read_file ( const string &  fname,
string &  out 
)

Reads a file into a string.

An exception is thrown on error.

Parameters:
fnamefilename to read.
outoutput string which will be filled with file content.
bool policy_utils::regex ( const string &  str,
const string &  reg 
)

Match a regex.

Parameters:
strinput string to check.
regregular expression used for matching.
Returns:
true if string matches regular expression
void policy_utils::str_to_list ( const string &  in,
list< string > &  out 
)

Converts a string in the form "1,2,...,n" to a list of strings.

Parameters:
ininput string.
outoutput list.
void policy_utils::str_to_set ( const string &  in,
set< string > &  out 
)

Converts a string in the form "1,2,...,n" to a set of strings.

Parameters:
ininput string.
outoutput set.
template<class T >
string policy_utils::to_str ( x)

Converts an object to a string via an ostringstream.

Returns:
string representation of object.
Parameters:
xobject to convert to string.
 All Classes Namespaces Functions Variables Typedefs Enumerations