Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

utils Namespace Reference

Utility functions. More...


Functions

void clear_error (void)
void set_error (const std::string &msg)
const std::string & get_error (void)
 Returns the last error message set by a utils:: function.

std::string add_slash (const std::string &filename)
 Returns filename with an appended '/'. More...

void to_upper (std::string &str)
 Converts each character in str to upper case. More...

std::string to_upper (const std::string &str)
 Returns str with each character in str capitalized.

bool stricmp (const std::string &a, const std::string &b)
 Case insensitive string compare. More...

bool check_extension (const std::string &file, const std::string &ext)
 Checks if file ends with the extension ext. More...

std::string trim (const std::string &str)
 Returns str with all white space removed from the front of the string.

std::string rtrim (const std::string &str)
 Returns str with all white space removed from the end of the string.

template<class T> std::istream & read (std::istream &stream, T &in)
 Templated binary stream read. More...

template<class T> std::ostream & write (std::ostream &stream, const T &out)
 Templated binary stream write. More...

bool mkdir (const std::string &filename)
 Creates the directory filename. More...

bool exists (const std::string &filename)
 Checks if filename exists. More...

bool can_read (const std::string &filename)
 Checks if filename can be read. More...

bool is_dir (const std::string &filename)
 Checks if filename is a directory. More...

bool is_link (const std::string &filename)
 Checks if filename is a link. More...

bool chdir (const std::string &filename)
 Changes the current directory to filename. More...

std::string get_valid_absolute_dir (const std::string &filename)
 Returns a string describing a valid abosolute directory. More...

std::string get_absolute_dir (const std::string &filename)
 Returns a cleaned version of the directory filename. More...

std::string get_filename (const std::string &filename)
 Returns the filename (basename) of the filename. More...


Variables

std::string error


Detailed Description

Utility functions.

Some utility function may set an error message. This error message can be accessed with utils::get_error( ).


Function Documentation

std::string utils::add_slash const std::string &    filename
 

Returns filename with an appended '/'.

Returns the string filename with '/' appended to the string. If filename already ends with '/', the string is left unchanged. If filename is empty, '/' is returned.

Definition at line 16 of file utils.cpp.

bool utils::can_read const std::string &    filename
 

Checks if filename can be read.

Note:
May set utils::error on error.
Returns:
true if filename can be read.

Definition at line 39 of file posix.cpp.

bool utils::chdir const std::string &    filename
 

Changes the current directory to filename.

Note:
May set utils::error on error.
Returns:
true if the current directory was successfully changed to filename.

Definition at line 81 of file posix.cpp.

bool utils::check_extension const std::string &    file,
const std::string &    ext
 

Checks if file ends with the extension ext.

Parameters:
ext  The extension to check. Do not include a leading '.' in the extension.
Returns:
true if file ends with the extension ext.

Definition at line 58 of file utils.cpp.

bool utils::exists const std::string &    filename
 

Checks if filename exists.

Note:
May set utils::error on error.
Returns:
true if filename exists.

Definition at line 26 of file posix.cpp.

std::string utils::get_absolute_dir const std::string &    filename
 

Returns a cleaned version of the directory filename.

This function returns a "clean" absolute directory string. A "clean" directory does not contain ".", "..", or "//" anywhere in the string.

Note:
This method does not check if filename is actually a valid directory. Use utils::get_valid_absolute_dir() for this purpose.

Definition at line 186 of file posix.cpp.

std::string utils::get_filename const std::string &    filename
 

Returns the filename (basename) of the filename.

This function returns the basename of filename. For example, an input of /usr/bin/ls would return ls.

Definition at line 257 of file posix.cpp.

std::string utils::get_valid_absolute_dir const std::string &    filename
 

Returns a string describing a valid abosolute directory.

This function returns a valid absolute directory. If filename is a plain file, then the directory in which filename resides is returned. This method correctly accounts for "." and "..". "//" is treated as "/./".

See also:
utils::get_absolute_dir()

Definition at line 93 of file posix.cpp.

bool utils::is_dir const std::string &    filename
 

Checks if filename is a directory.

Note:
May set utils::error on error.
Returns:
true if filename is a valid directory.

Definition at line 51 of file posix.cpp.

bool utils::is_link const std::string &    filename
 

Checks if filename is a link.

Note:
May set utils::error on error.
Returns:
true if filename is a link.

Definition at line 66 of file posix.cpp.

bool utils::mkdir const std::string &    filename
 

Creates the directory filename.

Note:
May set utils::error on error.
Returns:
true if the directory was successfully created.

Definition at line 14 of file posix.cpp.

template<class T>
std::istream& read std::istream &    stream,
T &    in
 

Templated binary stream read.

This function will read sizeof( T ) bytes from the input stream, placing the data in in. This function is well suited for reading in structs and arrays from binary files.

Parameters:
stream  istream to read from.
in  class to read/store data in.
Returns:
The istream, which can be used to check for errors.

Definition at line 88 of file utils.h.

bool utils::stricmp const std::string &    a,
const std::string &    b
 

Case insensitive string compare.

Returns:
true if each character in a is equal to each character in b. Case is not considered.

Definition at line 50 of file utils.cpp.

void utils::to_upper std::string &    str
 

Converts each character in str to upper case.

Note:
Modifies str.

Definition at line 32 of file utils.cpp.

template<class T>
std::ostream& write std::ostream &    stream,
const T &    out
 

Templated binary stream write.

This function will write sizeof( T ) bytes to output stream, This function is well suited for writing structs and arrays to binary files.

Parameters:
stream  ostream to write to.
out  class to write to stream.
Returns:
The ostream, which can be used to check for errors.

Definition at line 107 of file utils.h.


Generated on Tue Feb 11 18:49:50 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002