Classes | Modules | Functions | Variables

Utility Library
[General Utility Libraries]

Very low-level utility APIs and objects. More...

Collaboration diagram for Utility Library:

Classes

class  circular_buffer_t< T >
 Simple circular buffer. More...
class  distribution_t< T >
 Basic distribution template. More...
class  smart_fd
 smart file descriptor -- only use this for low-level objects! You probably want to use nstream or iostreams instead. More...
class  smart_dir
 smart directory handle. More...
class  AdvisoryLock
 advisory locking object WARNING: has no effect in Windows More...
class  FixedBuffer< Sizer, Validator >
 Template that supports strings of a fixed buffer size. More...
class  free_list_t< T >
 Simple free list manager. More...
struct  utf8_char_t
 a UTF-8 character. More...
class  stack_array< T, N >
class  StringBuffer

Modules

 Comma Separated Values
 

Wrapper for comma-separated-value (csv) files.


Functions

 smart_fd::smart_fd (int fd) throw ()
 smart_fd::~smart_fd (void) throw ()
void smart_fd::clear (void) throw ()
bool smart_fd::open (const char *path, int flags)
 smart_fd::operator int (void) const throw ()
 smart_fd::operator bool (void) const throw ()
bool smart_fd::operator! (void) const throw ()
 smart_fd::smart_fd (const smart_fd &)
 smart_dir::~smart_dir (void) throw ()
void smart_dir::clear (void) throw ()
 smart_dir::operator bool (void) const throw ()
void smart_dir::open (const char *path)
void smart_dir::close (void) throw ()
bool smart_dir::getNextEntry (struct dirent &entry)
 smart_dir::smart_dir (const smart_dir &)
 AdvisoryLock::AdvisoryLock (void) throw ()
 AdvisoryLock::~AdvisoryLock (void) throw ()
bool AdvisoryLock::attemptLock (const char *filename, int operation) throw ()
void AdvisoryLock::unlock (void) throw ()

Variables

int smart_fd::m_fd
DIR * smart_dir::m_dir
int AdvisoryLock::m_fd



enum  eUUIDConstants {
  eUUID_Length = 40,
  eUUID_Invalid = 0
}
const char * generateUUID (char *buffer)
 helper method to create a UUID.



int GetMonthFromString (const char *month) throw ()
void getDisplayableDateFromNetTime (long time, std::string &display)
const char * getDateString (long timestamp)
void getDateStringFromNetTime (long time, std::string &display)
long getNetTimeFromDateString (const char *date) throw ()
int getWeekdayFromNetTime (long time) throw ()
const char * GetWeekday (int weekday_index) throw ()
const char * GetMonth (int month_index) throw ()
long getDayBucket (long timestamp) throw ()
long getWeekBucket (long timestamp) throw ()
long getMonthBucket (long timestamp) throw ()
long getYearBucket (long timestamp) throw ()
std::string getDayBucketName (long day_bucket)
std::string getWeekBucketName (long week_bucket)
std::string getMonthBucketName (long month_bucket)
std::string getYearBucketName (long year_bucket)



const char * GetExtension (const char *filename) throw ()
bool hasExtension (const char *filename, const char *extension) throw ()
 returns true if the given filename ends with the specified string (NOT case-sensitive)
void GetFileRoot (const char *filename, std::string &file_root)
void GetParentDirectory (const char *filename, std::string &directory) throw ()
const char * getTopDirectory (const char *filename, std::string &topDir)
 retrieves the highest known folder for the given file.
std::string getPathRelativeTo (const char *startFilename, const char *relFilename)
 given a starting filename, and then a path relative to that, return the full path of the file.
void appendPath (const char *parentDirectory, const char *nextPath, std::string &path)
 given a starting path (directory), append another piece of the path
const char * GetFilename (const char *path) throw ()
void getTempfile (const char *path, std::string &tempfile) throw ()
void getUserHomePath (std::string &path)
bool ContainsWhitespace (const char *test) throw ()
bool doesPathExist (const char *path) throw ()
void createEmptyFileIfDoesNotExist (const char *path) throw ()
void walkDirectoryTree (const char *rootDirectory, const char *matchExtension, VecString &paths)
 does a recursive directory walk, and returns all paths relative to root
#define THROW_ERROR(error, args)
 throws a (hopefully) descriptive error based on errno passed in



void getNextToken (std::istream &stream, std::string &token, bool respect_quotes=true, bool *eof=NULL)
void expectToken (std::istream &stream, const char *expected)
float readFloat (std::istream &stream, std::string &token)
int readInteger (std::istream &stream, std::string &token)
short readShort (std::istream &stream, std::string &token)
long readLong (std::istream &stream, std::string &token)

Detailed Description

Very low-level utility APIs and objects.

More or less a grab bag of parsing, file, and date-based helper methods.


Define Documentation

#define THROW_ERROR (   error,
  args 
)
Value:
{                                                               \
                if (error) {                                            \
                        char buffer[512];                               \
                        strerror_r(error, buffer, sizeof(buffer));      \
                        WAVE_EX(wex);                                   \
                        wex << "Encountered an error (" << error;       \
                        wex << "): " << buffer;                         \
                        wex << "\n" << args ;                           \
                }                                                       \
        }

throws a (hopefully) descriptive error based on errno passed in

Definition at line 151 of file file.h.


Enumeration Type Documentation

constants specific to Universally Unique Identifiers

Enumerator:
eUUID_Length 

safe length for UUIDs (incl null)

eUUID_Invalid 

Definition at line 45 of file uuid.h.


Function Documentation

int GetMonthFromString ( const char *  month  )  throw ()

Definition at line 215 of file date.cpp.

const char* GetExtension ( const char *  filename  )  throw ()

Definition at line 61 of file file.cpp.

bool hasExtension ( const char *  filename,
const char *  extension 
) throw ()

returns true if the given filename ends with the specified string (NOT case-sensitive)

Definition at line 92 of file file.cpp.

void GetFileRoot ( const char *  filename,
std::string &  file_root 
)

Definition at line 112 of file file.cpp.

void GetParentDirectory ( const char *  filename,
std::string &  directory 
) throw ()

Definition at line 155 of file file.cpp.

const char* getTopDirectory ( const char *  filename,
std::string &  topDir 
)

retrieves the highest known folder for the given file.

returns a pointer to the beginning of the filename now relative to the top directory

Definition at line 199 of file file.cpp.

std::string getPathRelativeTo ( const char *  startFilename,
const char *  relFilename 
)

given a starting filename, and then a path relative to that, return the full path of the file.

Examples:

  • getPathRelativeTo("foo/bar.txt", "hi.txt") --> "foo/hi.txt"
  • getPathRelativeTo("foo/bar.txt", "x/hi.txt") --> "foo/x/hi.txt"
  • getPathRelativeTo("foo/bar.txt", "../hi.txt") --> "hi.txt"
  • getPathRelativeTo("foo/models/x.model", "../textures/y.texture") --> "foo/textures/y.texture"

Definition at line 529 of file file.cpp.

void appendPath ( const char *  parentDirectory,
const char *  nextPath,
std::string &  path 
)

given a starting path (directory), append another piece of the path

Definition at line 553 of file file.cpp.

const char* GetFilename ( const char *  path  )  throw ()

Definition at line 227 of file file.cpp.

void getTempfile ( const char *  path,
std::string &  tempfile 
) throw ()

Definition at line 259 of file file.cpp.

void getUserHomePath ( std::string &  path  ) 

Definition at line 292 of file file.cpp.

bool ContainsWhitespace ( const char *  test  )  throw ()

Definition at line 317 of file file.cpp.

bool doesPathExist ( const char *  path  )  throw ()

Definition at line 373 of file file.cpp.

void createEmptyFileIfDoesNotExist ( const char *  path  )  throw ()

Definition at line 395 of file file.cpp.

void walkDirectoryTree ( const char *  rootDirectory,
const char *  matchExtension,
VecString paths 
)

does a recursive directory walk, and returns all paths relative to root

Parameters:
matchExtension can be null

Definition at line 443 of file file.cpp.

smart_fd::smart_fd ( int  fd  )  throw () [inline, inherited]

Definition at line 171 of file file.h.

smart_fd::~smart_fd ( void   )  throw () [inline, inherited]

Definition at line 172 of file file.h.

void smart_fd::clear ( void   )  throw () [inline, inherited]

Definition at line 175 of file file.h.

bool smart_fd::open ( const char *  path,
int  flags 
) [inline, inherited]

Definition at line 184 of file file.h.

smart_fd::operator int ( void   )  const throw () [inline, inherited]

Definition at line 190 of file file.h.

smart_fd::operator bool ( void   )  const throw () [inline, inherited]

Definition at line 192 of file file.h.

bool smart_fd::operator! ( void   )  const throw () [inline, inherited]

Definition at line 193 of file file.h.

smart_fd::smart_fd ( const smart_fd  )  [private, inherited]
smart_dir::~smart_dir ( void   )  throw () [inline, inherited]

Definition at line 214 of file file.h.

void smart_dir::clear ( void   )  throw () [inline, inherited]

Definition at line 217 of file file.h.

smart_dir::operator bool ( void   )  const throw () [inline, inherited]

Definition at line 224 of file file.h.

void smart_dir::open ( const char *  path  )  [inline, inherited]

Definition at line 226 of file file.h.

void smart_dir::close ( void   )  throw () [inline, inherited]

Definition at line 235 of file file.h.

bool smart_dir::getNextEntry ( struct dirent &  entry  )  [inline, inherited]

Definition at line 237 of file file.h.

smart_dir::smart_dir ( const smart_dir  )  [private, inherited]
AdvisoryLock::AdvisoryLock ( void   )  throw () [inline, inherited]

Definition at line 261 of file file.h.

AdvisoryLock::~AdvisoryLock ( void   )  throw () [inline, inherited]

Definition at line 262 of file file.h.

bool AdvisoryLock::attemptLock ( const char *  filename,
int  operation 
) throw () [inline, inherited]

Definition at line 266 of file file.h.

void AdvisoryLock::unlock ( void   )  throw () [inline, inherited]

Definition at line 300 of file file.h.

void getNextToken ( std::istream &  stream,
std::string &  token,
bool  respect_quotes = true,
bool *  eof = NULL 
)

Definition at line 65 of file token_stream.cpp.

void getDisplayableDateFromNetTime ( long  time,
std::string &  display 
)

Definition at line 235 of file date.cpp.

const char* getDateString ( long  timestamp  ) 

Definition at line 259 of file date.cpp.

void getDateStringFromNetTime ( long  time,
std::string &  display 
)

Definition at line 279 of file date.cpp.

long getNetTimeFromDateString ( const char *  date  )  throw ()

Definition at line 366 of file date.cpp.

int getWeekdayFromNetTime ( long  time  )  throw ()

Definition at line 427 of file date.cpp.

const char* GetWeekday ( int  weekday_index  )  throw ()

Definition at line 443 of file date.cpp.

const char* GetMonth ( int  month_index  )  throw ()

Definition at line 458 of file date.cpp.

long getDayBucket ( long  timestamp  )  throw ()

Definition at line 474 of file date.cpp.

long getWeekBucket ( long  timestamp  )  throw ()

Definition at line 488 of file date.cpp.

long getMonthBucket ( long  timestamp  )  throw ()

Definition at line 502 of file date.cpp.

long getYearBucket ( long  timestamp  )  throw ()

Definition at line 517 of file date.cpp.

std::string getDayBucketName ( long  day_bucket  ) 

Definition at line 532 of file date.cpp.

std::string getWeekBucketName ( long  week_bucket  ) 

Definition at line 543 of file date.cpp.

std::string getMonthBucketName ( long  month_bucket  ) 

Definition at line 553 of file date.cpp.

std::string getYearBucketName ( long  year_bucket  ) 

Definition at line 565 of file date.cpp.

void expectToken ( std::istream &  stream,
const char *  expected 
)

Definition at line 157 of file token_stream.cpp.

float readFloat ( std::istream &  stream,
std::string &  token 
)

Definition at line 182 of file token_stream.cpp.

int readInteger ( std::istream &  stream,
std::string &  token 
)

Definition at line 196 of file token_stream.cpp.

short readShort ( std::istream &  stream,
std::string &  token 
)

Definition at line 224 of file token_stream.cpp.

long readLong ( std::istream &  stream,
std::string &  token 
)

Definition at line 210 of file token_stream.cpp.

const char* generateUUID ( char *  buffer  ) 

helper method to create a UUID.

Caller must provide a pre-allocated buffer of size eUUID_Length or larger. Returns a pointer to the beginning of the buffer as a convenience.

Definition at line 74 of file uuid.cpp.


Variable Documentation

int smart_fd::m_fd [private, inherited]

Definition at line 84 of file smart_fd.h.

DIR* smart_dir::m_dir [private, inherited]

Definition at line 250 of file file.h.

int AdvisoryLock::m_fd [private, inherited]

Definition at line 311 of file file.h.