code::OS Class Reference

List of all members.

Detailed Description

A portability layer for system calls.

Author:
Lakshman

Charles Kerr

Version:
Id
code_OS.h,v 1.9 2008/02/28 16:46:34 charles Exp


Static Public Member Functions

static bool getHost (std::string *optional_hostname, std::string *optional_address)
 Attempts to get the system's host name and address.
static int getProgramSize ()
 The memory currently being used by this program, in pages.
static unsigned long getElapsedCPUTimeMSec ()
 Returns the number of milliseconds of CPU time the process has used.
static unsigned long getElapsedClockTimeSec ()
 Returns the number of seconds this program has been running.
static std::string getProcessName ()
 Returns the process name.
static bool isAbsolutePath (const std::string &path)
 Returns true if path is an absolute path.
static std::string getBaseName (const std::string &filename)
 Analogous to unix-style basename.
static std::string getDirName (const std::string &filename)
 Analogous to unix-style dirname.
static unsigned int testFile (const std::string &filename, unsigned int test_flags)
 Test a file for the properties specified in test_flags.
static std::string getCurrentDir ()
 Returns the current working directory.
static bool mkdirp (const std::string &path)
 Create all the directories necessary for the given path.
static bool rmtree (const std::string &path)
 removes a file or subdirectory and any children.
static std::string buildFilename (const char *first_element,...)
 Creates a filename from a series of elements using the correct separator for filenames.
static std::string getUniqueTemporaryFile (const std::string base="wdssii")
 Return a unique temporary name.
static std::string getUniqueTemporaryDir (const std::string base="wdssii")
 Equivalent to getUniqueTemporaryFile() + mkdirp().
static const std::string & getTempDir ()
 Returns the temporary directory to be used by wdssii.
static unsigned int sleepSec (unsigned int seconds)
 Tries to sleep for the specified number of seconds.
static void sleepMsec (unsigned long milliseconds)
 Sleep for the specified number of milliseconds.
static int getppid ()
 Equivalent to getppid() on Unix.

Static Public Attributes

static const char DIR_SEPARATOR
static const char *const DIR_SEPARATOR_STR
static const unsigned int FILE_IS_REGULAR
 Test flags that can be passed to testFile().
static const unsigned int FILE_IS_SYMLINK
static const unsigned int FILE_IS_DIRECTORY
static const unsigned int FILE_IS_EXECUTABLE
static const unsigned int FILE_EXIST


Member Function Documentation

static std::string code::OS::buildFilename ( const char *  first_element,
  ... 
) [static]

Creates a filename from a series of elements using the correct separator for filenames.

On Windows, it takes into account that either the backslash (\) or slash (/) can be used as a separator in filenames, but otherwise behaves as on Unix. When file pathname separators need to be inserted, the last one that previously occurred in the parameters (reading from left to right) is used.

static std::string code::OS::getBaseName ( const std::string &  filename  )  [static]

Analogous to unix-style basename.

We offer our own version for cross-platform support.

static std::string code::OS::getCurrentDir (  )  [static]

Returns the current working directory.

static std::string code::OS::getDirName ( const std::string &  filename  )  [static]

Analogous to unix-style dirname.

We offer our own version for cross-platform support.

static unsigned long code::OS::getElapsedClockTimeSec (  )  [static]

Returns the number of seconds this program has been running.

static unsigned long code::OS::getElapsedCPUTimeMSec (  )  [static]

Returns the number of milliseconds of CPU time the process has used.

static bool code::OS::getHost ( std::string *  optional_hostname,
std::string *  optional_address 
) [static]

Attempts to get the system's host name and address.

the equivalent of gethostname() is used to populate `optional_hostname'.

the equivalent of using the first address of gethostbyname() is used to populate `optional_address'

Returns:
true if able to populate the non-null fields.

static int code::OS::getppid (  )  [static]

Equivalent to getppid() on Unix.

Returns:
the process id of the parent process.

static std::string code::OS::getProcessName (  )  [static]

Returns the process name.

static int code::OS::getProgramSize (  )  [static]

The memory currently being used by this program, in pages.

static const std::string& code::OS::getTempDir (  )  [static]

Returns the temporary directory to be used by wdssii.

If set, the TMPDIR environmental variable is used. The fallback is "/tmp" on Unix and "c:\WINDOWS\Temp" on Windows.

static std::string code::OS::getUniqueTemporaryDir ( const std::string  base = "wdssii"  )  [inline, static]

Equivalent to getUniqueTemporaryFile() + mkdirp().

Returns:
the new temporary directory name, or an empty string if a new directory couldn't be created.

static std::string code::OS::getUniqueTemporaryFile ( const std::string  base = "wdssii"  )  [static]

Return a unique temporary name.

No one else will have this name while this executable is running. If you want to use it as a directory, use getUniqueTemporaryDir().

the 'base' string will be the lead part of the basename, and some qualifier will be added to it to ensure uniqueness; ie /tmp/base.some-unique-qualifier

static bool code::OS::isAbsolutePath ( const std::string &  path  )  [static]

Returns true if path is an absolute path.

static bool code::OS::mkdirp ( const std::string &  path  )  [static]

Create all the directories necessary for the given path.

Doesn't exist on all Unixes. One workaround, system("mkdir -p dirname"), doesn't work on Windows.

Returns:
false if the path does not already exist and could not be created new.

static bool code::OS::rmtree ( const std::string &  path  )  [static]

removes a file or subdirectory and any children.

static void code::OS::sleepMsec ( unsigned long  milliseconds  )  [static]

Sleep for the specified number of milliseconds.

static unsigned int code::OS::sleepSec ( unsigned int  seconds  )  [static]

Tries to sleep for the specified number of seconds.

Equivalent to sleep(unsigned int) on Unix.

Returns:
the number of seconds left to sleep.

static unsigned int code::OS::testFile ( const std::string &  filename,
unsigned int  test_flags 
) [static]

Test a file for the properties specified in test_flags.

test_flags can be a bitwise-or'ed set of FILE_IS_REGULAR, FILE_IS_SYMLINK, FILE_IS_DIRECTORY, FILE_IS_EXECUTABLE, and FILE_EXIST.

Returns:
the subset of test_flags which are true.


Member Data Documentation

const char code::OS::DIR_SEPARATOR [static]

const char* const code::OS::DIR_SEPARATOR_STR [static]

const unsigned int code::OS::FILE_EXIST [static]

const unsigned int code::OS::FILE_IS_DIRECTORY [static]

const unsigned int code::OS::FILE_IS_EXECUTABLE [static]

const unsigned int code::OS::FILE_IS_REGULAR [static]

Test flags that can be passed to testFile().

const unsigned int code::OS::FILE_IS_SYMLINK [static]


Generated on Fri May 4 13:40:13 2012 for WDSS-IIw2 by  doxygen 1.4.7