Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArUtil Class Reference

This class has utility functions. More...

#include <ariaUtil.h>

List of all members.

Public Types

enum  BITS {
  BIT0 = 0x1, BIT1 = 0x2, BIT2 = 0x4, BIT3 = 0x8,
  BIT4 = 0x10, BIT5 = 0x20, BIT6 = 0x40, BIT7 = 0x80,
  BIT8 = 0x100, BIT9 = 0x200, BIT10 = 0x400, BIT11 = 0x800,
  BIT12 = 0x1000, BIT13 = 0x2000, BIT14 = 0x4000, BIT15 = 0x8000
}
 Values for the bits from 0 to 16. More...
enum  REGKEY {
  REGKEY_CLASSES_ROOT, REGKEY_CURRENT_CONFIG, REGKEY_CURRENT_USER, REGKEY_LOCAL_MACHINE,
  REGKEY_USERS
}

Static Public Member Functions

static void addDirectories (char *dest, size_t destLength, const char *baseDir, const char *insideDir)
 Adds two directories, taking care of all slash issues.
static void appendSlash (char *path, size_t pathLength)
 Appends a slash to a path if there is not one there already.
static double atof (const char *nptr)
 Does an atof but if its inf or -inf deals with it fine.
static const char * convertBool (int val)
 Converts an integer value into a string for true or false.
template<class T>
static void deleteSet (T begin, T end)
 Delete all members of a set. Does NOT empty the set.
template<class T>
static void deleteSetPairs (T begin, T end)
 Delete all members of a set. Does NOT empty the set.
static void escapeSpaces (char *dest, const char *src, size_t maxLen)
 Puts a \ before spaces in src, puts it into dest.
static bool findFile (const char *fileName)
 OS-independent way of checking to see if a file exists and is readable.
static bool findFirstStringInRegistry (const char *key, const char *value, char *str, int len)
 Returns a string from the Windows registry, searching each of the following registry root paths in order: REGKEY_CURRENT_USER, REGKEY_LOCAL_MACHINE.
static double findMax (double first, double second)
 Returns the maximum of the two values.
static int findMax (int first, int second)
 Returns the maximum of the two values.
static double findMin (double first, double second)
 Returns the minimum of the two values.
static int findMin (int first, int second)
 Returns the minimum of the two values.
static void fixSlashes (char *path, size_t pathLength)
 Fix the slash orientation in file path string for windows or linux.
static void fixSlashesBackward (char *path, size_t pathLength)
 Fix the slash orientation in file path string to be all backward.
static void fixSlashesForward (char *path, size_t pathLength)
 Fix the slash orientation in file path string to be all forward.
static void functorPrintf (ArFunctor1< const char * > *functor, char *str,...)
 Function for doing a printf style call to a functor.
static bool getStringFromFile (const char *fileName, char *str, size_t strLen)
 Gets a string contained in an arbitrary file.
static bool getStringFromRegistry (REGKEY root, const char *key, const char *value, char *str, int len)
 Returns a string from the Windows registry.
static unsigned int getTime (void)
 Get the time in milliseconds.
static bool isOnlyAlphaNumeric (const char *str)
 Returns true if this string is only alphanumeric, false otherwise.
static void lower (char *dest, const char *src, size_t maxLen)
 Lowers a string from src into dest, make sure there's enough space.
static long sizeFile (std::string fileName)
 OS-independent way of finding the size of a file.
static long sizeFile (const char *fileName)
 OS-independent way of finding the size of a file.
static void sleep (unsigned int ms)
 Sleep for the given number of milliseconds.
static int strcasecmp (const char *str, const char *str2)
 Finds out if two strings are equal (ignoring case).
static int strcasecmp (const char *str, std::string str2)
 Finds out if two strings are equal (ignoring case).
static int strcasecmp (std::string str, const char *str2)
 Finds out if two strings are equal (ignoring case).
static int strcasecmp (std::string str, std::string str2)
 Finds out if two strings are equal (ignoring case).
static int strcmp (const char *str, const char *str2)
 Finds out if two strings are equal.
static int strcmp (const char *str, std::string str2)
 Finds out if two strings are equal.
static int strcmp (std::string str, const char *str2)
 Finds out if two strings are equal.
static int strcmp (std::string str, std::string str2)
 Finds out if two strings are equal.
static bool stripQuotes (char *dest, const char *src, size_t destLen)
 Strips out the quotes in the src buffer into the dest buffer.
static void writeToFile (const char *str, FILE *file)
 Function for doing a fprintf to a file (here to make a functor for).

Static Public Attributes

static const char * COM1 = "/dev/ttyS0"
 First serial port device name (value depends on compilation platform).
static const char * COM2 = "/dev/ttyS1"
 Second serial port device name (value depends on compilation platform).
static const char * COM3 = "/dev/ttyS2"
 Third serial port device name (value depends on compilation platform).
static const char * COM4 = "/dev/ttyS3"
 Fourth serial port device name (value depends on compilation platform).
static const char * FALSESTRING = "false"
 "false"
static const char * TRUESTRING = "true"
 "true"


Detailed Description

This class has utility functions.

Definition at line 56 of file ariaUtil.h.


Member Enumeration Documentation

enum ArUtil::BITS
 

Values for the bits from 0 to 16.

Enumeration values:
BIT0  value of BIT0
BIT1  value of BIT1
BIT2  value of BIT2
BIT3  value of BIT3
BIT4  value of BIT4
BIT5  value of BIT5
BIT6  value of BIT6
BIT7  value of BIT7
BIT8  value of BIT8
BIT9  value of BIT9
BIT10  value of BIT10
BIT11  value of BIT11
BIT12  value of BIT12
BIT13  value of BIT13
BIT14  value of BIT14
BIT15  value of BIT15

Definition at line 60 of file ariaUtil.h.

enum ArUtil::REGKEY
 

These are for passing into getStringFromRegistry

Enumeration values:
REGKEY_CLASSES_ROOT  use HKEY_CLASSES_ROOT
REGKEY_CURRENT_CONFIG  use HKEY_CURRENT_CONFIG
REGKEY_CURRENT_USER  use HKEY_CURRENT_USER
REGKEY_LOCAL_MACHINE  use HKEY_LOCAL_MACHIE
REGKEY_USERS  use HKEY_USERS

Definition at line 217 of file ariaUtil.h.


Member Function Documentation

void ArUtil::addDirectories char *  dest,
size_t  destLength,
const char *  baseDir,
const char *  insideDir
[static]
 

Adds two directories, taking care of all slash issues.

This function will take the 'baseDir' and put the 'insideDir' after it so that it winds up with 'baseDir/insideDir/'. It will take care of slashes, making sure there is one between them and one at the end, and the slashes will match what the operating system expects.

Parameters:
dest the place to put the result
destLength the length of the place to put the results
baseDir the directory to start with
insideDir the directory to place after the baseDir

Definition at line 387 of file ariaUtil.cpp.

References appendSlash(), and fixSlashes().

void ArUtil::appendSlash char *  path,
size_t  pathLength
[static]
 

Appends a slash to a path if there is not one there already.

Append a directory seperator character to the given path string, depending on the platform. On Windows, a backslash ('\') is added. On other platforms, a forward slash ('/') is appended. If there is no more allocated space in the path string, no character will be appended.

Parameters:
path the path string to append a slash to
pathLength maximum length allocated for path string

Definition at line 316 of file ariaUtil.cpp.

Referenced by addDirectories().

template<class T>
static void ArUtil::deleteSet begin,
end
[inline, static]
 

Delete all members of a set. Does NOT empty the set.

Assumes that T is an iterator that supports the operator*, operator!= and operator++. The return is assumed to be a pointer to a class that needs to be deleted.

Definition at line 91 of file ariaUtil.h.

Referenced by ArForbiddenRangeDevice::processMap(), ArMap::setInfo(), ArMap::setMapInfo(), ArMap::setMapObjects(), ArSimpleConnector::setMaxNumLasers(), and ArRangeBuffer::~ArRangeBuffer().

template<class T>
static void ArUtil::deleteSetPairs begin,
end
[inline, static]
 

Delete all members of a set. Does NOT empty the set.

Assumes that T is an iterator that supports the operator**, operator!= and operator++. The return is assumed to be a pair. The second value of the pair is assumed to be a pointer to a class that needs to be deleted.

Definition at line 105 of file ariaUtil.h.

Referenced by ArRobot::~ArRobot(), and ArSyncTask::~ArSyncTask().

void ArUtil::escapeSpaces char *  dest,
const char *  src,
size_t  maxLen
[static]
 

Puts a \ before spaces in src, puts it into dest.

This copies src into dest but puts a \ before any spaces in src, escaping them... its mostly for use with ArArgumentBuilder... make sure you have at least maxLen spaces in the arrays that you're passing as dest... this allocates no memory

Definition at line 520 of file ariaUtil.cpp.

bool ArUtil::findFile const char *  fileName  )  [static]
 

OS-independent way of checking to see if a file exists and is readable.

Returns:
true if file is found
Parameters:
fileName name of the file to size

Definition at line 216 of file ariaUtil.cpp.

void ArUtil::fixSlashes char *  path,
size_t  pathLength
[static]
 

Fix the slash orientation in file path string for windows or linux.

Parameters:
path the path in which to fix the orientation of the slashes
pathLength the maximum length of path

Definition at line 339 of file ariaUtil.cpp.

References fixSlashesBackward(), and fixSlashesForward().

Referenced by addDirectories().

void ArUtil::fixSlashesBackward char *  path,
size_t  pathLength
[static]
 

Fix the slash orientation in file path string to be all backward.

Parameters:
path the path in which to fix the orientation of the slashes
pathLength how long that path is at max

Definition at line 352 of file ariaUtil.cpp.

Referenced by fixSlashes().

void ArUtil::fixSlashesForward char *  path,
size_t  pathLength
[static]
 

Fix the slash orientation in file path string to be all forward.

Parameters:
path the path in which to fix the orientation of the slashes
pathLength how long that path is at max

Definition at line 365 of file ariaUtil.cpp.

Referenced by fixSlashes().

bool ArUtil::getStringFromFile const char *  fileName,
char *  str,
size_t  strLen
[static]
 

Gets a string contained in an arbitrary file.

This function reads a string from a file. The file can contain spaces or tabs, but a '\r' or '\n' will be treated as the end of the string, and the string cannot have more characters than the value given by strLen. This is mostly for internal use with Linux to determine the Aria directory from a file in /etc, but will work with Linux or Windows.

Parameters:
fileName name of the file in which to look
str the string to copy the file contents into
strLen the maximum allocated length of str

Definition at line 620 of file ariaUtil.cpp.

Referenced by Aria::init().

bool ArUtil::getStringFromRegistry REGKEY  root,
const char *  key,
const char *  value,
char *  str,
int  len
[static]
 

Returns a string from the Windows registry.

Look up the given value under the given key, within the given registry root key.

Parameters:
root the root key to use, one of the REGKEY enum values
key the name of the key to find
value the value name in which to find the string
str where to put the string found, or if it could not be found, an empty (length() == 0) string
len the length of the allocated memory in str
Returns:
true if the string was found, false if it was not found or if there was a problem such as the string not being long enough

Definition at line 664 of file ariaUtil.cpp.

References ArLog::log(), REGKEY_CLASSES_ROOT, REGKEY_CURRENT_CONFIG, REGKEY_CURRENT_USER, REGKEY_LOCAL_MACHINE, REGKEY_USERS, and strcmp().

Referenced by findFirstStringInRegistry().

unsigned int ArUtil::getTime void   )  [static]
 

Get the time in milliseconds.

Get the time in milliseconds, counting from some arbitrary point. This time is only valid within this run of the program.

Returns:
millisecond time

Definition at line 94 of file ariaUtil.cpp.

void ArUtil::lower char *  dest,
const char *  src,
size_t  maxLen
[static]
 

Lowers a string from src into dest, make sure there's enough space.

This copies src into dest but makes it lower case make sure you have at least maxLen arrays that you're passing as dest... this allocates no memory

Definition at line 545 of file ariaUtil.cpp.

Referenced by ArFileParser::parseLine().

long ArUtil::sizeFile const char *  fileName  )  [static]
 

OS-independent way of finding the size of a file.

Returns:
size in bytes. -1 on error.
Parameters:
fileName name of the file to size

Definition at line 194 of file ariaUtil.cpp.

void ArUtil::sleep unsigned int  ms  )  [static]
 

Sleep for the given number of milliseconds.

This sleeps for the given number of milliseconds... Note in linux it tries to sleep for 10 ms less than the amount given, which should wind up close to correct... Linux is broken in this regard and sleeps for too long... it sleeps for the ceiling of the current 10 ms range, then for an additional 10 ms... so: 11 to 20 ms sleeps for 30 ms... 21 to 30 ms sleeps for 40 ms... 31 to 40 ms sleeps for 50 ms... this continues on up to the values we care about of.. 81 to 90 ms sleeps for 100 ms... 91 to 100 ms sleeps for 110 ms... so we'll sleep for 10 ms less than we want to, which should put us about right... guh

Parameters:
ms the number of milliseconds to sleep for

Definition at line 76 of file ariaUtil.cpp.

Referenced by ArRobot::asyncConnectHandler(), ArSick::blockingConnect(), ArRobot::blockingConnect(), ArP2Arm::checkArm(), ArSick::disconnect(), ArRobot::disconnect(), ArP2Arm::init(), ArSick::internalConnectHandler(), ArP2Arm::powerOn(), ArSoundsQueue::runThread(), and ArSick::runThread().

int ArUtil::strcasecmp const char *  str,
const char *  str2
[static]
 

Finds out if two strings are equal (ignoring case).

This compares two strings ignoring case, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 509 of file ariaUtil.cpp.

int ArUtil::strcasecmp const char *  str,
std::string  str2
[static]
 

Finds out if two strings are equal (ignoring case).

This compares two strings ignoring case, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 496 of file ariaUtil.cpp.

int ArUtil::strcasecmp std::string  str,
const char *  str2
[static]
 

Finds out if two strings are equal (ignoring case).

This compares two strings ignoring case, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 483 of file ariaUtil.cpp.

int ArUtil::strcasecmp std::string  str,
std::string  str2
[static]
 

Finds out if two strings are equal (ignoring case).

This compares two strings ignoring case, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 470 of file ariaUtil.cpp.

Referenced by atof(), ArConfig::parseArgument(), and ArConfig::parseArgumentParser().

int ArUtil::strcmp const char *  str,
const char *  str2
[static]
 

Finds out if two strings are equal.

This compares two strings, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 456 of file ariaUtil.cpp.

int ArUtil::strcmp const char *  str,
std::string  str2
[static]
 

Finds out if two strings are equal.

This compares two strings, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 442 of file ariaUtil.cpp.

int ArUtil::strcmp std::string  str,
const char *  str2
[static]
 

Finds out if two strings are equal.

This compares two strings, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 428 of file ariaUtil.cpp.

int ArUtil::strcmp std::string  str,
std::string  str2
[static]
 

Finds out if two strings are equal.

This compares two strings, it returns an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Parameters:
str the string to compare
str2 the second string to compare
Returns:
an integer less than, equal to, or greater than zero if str is found, respectively, to be less than, to match, or be greater than str2.

Definition at line 414 of file ariaUtil.cpp.

Referenced by getStringFromRegistry().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:56 2005 for Aria by  doxygen 1.4.0