Classes | Modules | Functions

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 (IN int fd) throw ()
 smart_fd::~smart_fd (void) throw ()
void smart_fd::clear (void) throw ()
bool smart_fd::open (IN const char *path, IN int flags)
 smart_fd::operator int (void) const throw ()
 smart_fd::operator bool (void) const throw ()
bool smart_fd::operator! (void) const throw ()
 smart_dir::~smart_dir (void) throw ()
void smart_dir::clear (void) throw ()
 smart_dir::operator bool (void) const throw ()
void smart_dir::open (IN const char *path)
void smart_dir::close (void) throw ()
bool smart_dir::getNextEntry (OUT struct dirent &entry)
 AdvisoryLock::AdvisoryLock (void) throw ()
 AdvisoryLock::~AdvisoryLock (void) throw ()
bool AdvisoryLock::attemptLock (IN const char *filename, IN int operation) throw ()
void AdvisoryLock::unlock (void) throw ()



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



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



const char * GetExtension (IN const char *filename) throw ()
bool hasExtension (IN const char *filename, IN const char *extension) throw ()
 returns true if the given filename ends with the specified string (NOT case-sensitive)
void GetFileRoot (IN const char *filename, OUT std::string &file_root)
void GetParentDirectory (IN const char *filename, OUT std::string &directory) throw ()
const char * getTopDirectory (IN const char *filename, OUT std::string &topDir)
 retrieves the highest known folder for the given file.
std::string getPathRelativeTo (IN const char *startFilename, IN const char *relFilename)
 given a starting filename, and then a path relative to that, return the full path of the file.
void appendPath (IN const char *parentDirectory, IN const char *nextPath, OUT std::string &path)
 given a starting path (directory), append another piece of the path
const char * GetFilename (IN const char *path) throw ()
void getTempfile (IN const char *path, OUT std::string &tempfile) throw ()
void getUserHomePath (OUT std::string &path)
bool ContainsWhitespace (IN const char *test) throw ()
bool doesPathExist (IN const char *path) throw ()
void createEmptyFileIfDoesNotExist (IN const char *path) throw ()
void walkDirectoryTree (IN const char *rootDirectory, IN const char *matchExtension, OUT 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 (IO std::istream &stream, OUT std::string &token, IN bool respect_quotes=true, IN bool *eof=NULL)
void expectToken (IO std::istream &stream, IN const char *expected)
float readFloat (IN std::istream &stream, IO std::string &token)
int readInteger (IN std::istream &stream, IO std::string &token)
short readShort (IN std::istream &stream, IO std::string &token)
long readLong (IN std::istream &stream, IO 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 176 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 ( IN const char *  month  )  throw ()

Definition at line 216 of file date.cpp.

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

Definition at line 60 of file file.cpp.

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

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

Definition at line 91 of file file.cpp.

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

Definition at line 111 of file file.cpp.

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

Definition at line 154 of file file.cpp.

const char* getTopDirectory ( IN const char *  filename,
OUT 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 198 of file file.cpp.

std::string getPathRelativeTo ( IN const char *  startFilename,
IN 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 533 of file file.cpp.

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

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

Definition at line 557 of file file.cpp.

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

Definition at line 226 of file file.cpp.

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

Definition at line 258 of file file.cpp.

void getUserHomePath ( OUT std::string &  path  ) 

Definition at line 296 of file file.cpp.

bool ContainsWhitespace ( IN const char *  test  )  throw ()

Definition at line 321 of file file.cpp.

bool doesPathExist ( IN const char *  path  )  throw ()

Definition at line 377 of file file.cpp.

void createEmptyFileIfDoesNotExist ( IN const char *  path  )  throw ()

Definition at line 399 of file file.cpp.

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

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

Parameters:
matchExtension can be null

Definition at line 447 of file file.cpp.

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

Definition at line 196 of file file.h.

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

Definition at line 197 of file file.h.

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

Definition at line 200 of file file.h.

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

Definition at line 213 of file file.h.

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

Definition at line 223 of file file.h.

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

Definition at line 225 of file file.h.

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

Definition at line 226 of file file.h.

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

Definition at line 246 of file file.h.

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

Definition at line 249 of file file.h.

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

Definition at line 256 of file file.h.

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

Definition at line 258 of file file.h.

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

Definition at line 267 of file file.h.

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

Definition at line 269 of file file.h.

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

Definition at line 293 of file file.h.

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

Definition at line 294 of file file.h.

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

Definition at line 298 of file file.h.

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

Definition at line 332 of file file.h.

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

Definition at line 65 of file token_stream.cpp.

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

Definition at line 236 of file date.cpp.

const char* getDateString ( IN long  timestamp  ) 

Definition at line 261 of file date.cpp.

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

Definition at line 282 of file date.cpp.

long getNetTimeFromDateString ( IN const char *  date  )  throw ()

Definition at line 369 of file date.cpp.

int getWeekdayFromNetTime ( IN long  time  )  throw ()

Definition at line 430 of file date.cpp.

const char* GetWeekday ( IN int  weekday_index  )  throw ()

Definition at line 446 of file date.cpp.

const char* GetMonth ( IN int  month_index  )  throw ()

Definition at line 461 of file date.cpp.

long getDayBucket ( IN long  timestamp  )  throw ()

Definition at line 477 of file date.cpp.

long getWeekBucket ( IN long  timestamp  )  throw ()

Definition at line 491 of file date.cpp.

long getMonthBucket ( IN long  timestamp  )  throw ()

Definition at line 505 of file date.cpp.

long getYearBucket ( IN long  timestamp  )  throw ()

Definition at line 521 of file date.cpp.

std::string getDayBucketName ( IN long  day_bucket  ) 

Definition at line 537 of file date.cpp.

std::string getWeekBucketName ( IN long  week_bucket  ) 

Definition at line 548 of file date.cpp.

std::string getMonthBucketName ( IN long  month_bucket  ) 

Definition at line 558 of file date.cpp.

std::string getYearBucketName ( IN long  year_bucket  ) 

Definition at line 570 of file date.cpp.

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

Definition at line 157 of file token_stream.cpp.

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

Definition at line 182 of file token_stream.cpp.

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

Definition at line 196 of file token_stream.cpp.

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

Definition at line 224 of file token_stream.cpp.

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

Definition at line 210 of file token_stream.cpp.

const char* generateUUID ( OUT 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 76 of file uuid.cpp.