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

facilities::Util Class Reference

#include <Util.h>

List of all members.

Static Public Member Functions

int atoi (const std::string &InStr)
 converts an std::string to an integer
int atoi (const std::string &InStr)
 converts an std::string to an integer
int atoi (const std::string &InStr)
 converts an std::string to an integer
int atoi (const std::string &InStr)
 converts an std::string to an integer
std::string basename (const std::string &path)
std::string basename (const std::string &path)
std::string basename (const std::string &path)
std::string basename (const std::string &path)
int catchOptionVal (std::string *toCatch, const int ops=0, const std::string &openDel=std::string("#("), const std::string &closeDel=std::string(")"))
int catchOptionVal (std::string *toCatch, const int ops=0, const std::string &openDel=std::string("#("), const std::string &closeDel=std::string(")"))
int expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
int expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
int expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
int expandEnvVar (std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
const char * itoa (int val, std::string &outStr)
const char * itoa (int val, std::string &outStr)
const char * itoa (int val, std::string &outStr)
const char * itoa (int val, std::string &outStr)
void keyValueTokenize (std::string input, const std::string &delimiters, std::map< std::string, std::string > &tokenMap, const std::string &pairDelimiter=std::string("="), bool clear=true)
void keyValueTokenize (std::string input, const std::string &delimiters, std::map< std::string, std::string > &tokenMap, const std::string &pairDelimiter=std::string("="), bool clear=true)
double stringToDouble (const std::string &InStr)
double stringToDouble (const std::string &InStr)
double stringToDouble (const std::string &InStr)
double stringToDouble (const std::string &InStr)
int stringToInt (const std::string &InStr)
int stringToInt (const std::string &InStr)
int stringToInt (const std::string &InStr)
int stringToInt (const std::string &InStr)
void stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true)
void stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true)
void stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true)
void stringTokenize (std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true)
unsigned trimTrailing (std::string *toTrim)
unsigned trimTrailing (std::string *toTrim)


Member Function Documentation

int facilities::Util::atoi const std::string &  InStr  )  [static]
 

converts an std::string to an integer

int facilities::Util::atoi const std::string &  InStr  )  [static]
 

converts an std::string to an integer

int facilities::Util::atoi const std::string &  InStr  )  [static]
 

converts an std::string to an integer

int facilities::Util::atoi const std::string &  InStr  )  [static]
 

converts an std::string to an integer

00081                                        {
00082     // Purpose and Method:  Provide a standard routine to convert std::strings
00083     //    into integers.  The method used depends upon the availability of
00084     //    the stringstream classes.  The stringstream classes are the
00085     //    standard, but some compilers do yet support them.
00086     //    The method used is determined by the DEFECT_NO_STRINGSTREAM
00087     //    macro, defined in the facilities requirements file.
00088     // Output: returns an integer
00089     //    if string cannot be converted to an integer, returns zero
00090 
00091     int val;
00092 
00093 #ifdef DEFECT_NO_STRINGSTREAM
00094     std::istrstream locStream(inStr.c_str());
00095 #else
00096     std::istringstream locStream(inStr);
00097 #endif
00098     locStream >> val;
00099     if (!locStream) {return 0;}
00100     return val;
00101   }  

std::string facilities::Util::basename const std::string &  path  )  [static]
 

return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.

See also:
{ Util::expandEnvVar }
Parameters:
path string assumed to be a file identifier.

std::string facilities::Util::basename const std::string &  path  )  [static]
 

return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.

See also:
{ Util::expandEnvVar }
Parameters:
path string assumed to be a file identifier.

std::string facilities::Util::basename const std::string &  path  )  [static]
 

return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.

See also:
{ Util::expandEnvVar }
Parameters:
path string assumed to be a file identifier.

std::string facilities::Util::basename const std::string &  path  )  [static]
 

return the "non-directory" part of a (supposed) file identifier, path. Environment variable translation should be done before calling basename.

See also:
{ Util::expandEnvVar }
Parameters:
path string assumed to be a file identifier.
00160                                                 {
00161      std::vector<std::string> names;
00162      stringTokenize(path, "\\/", names);
00163      return *(names.end() - 1);
00164   }

int facilities::Util::catchOptionVal std::string *  toCatch,
const int  ops = 0,
const std::string &  openDel = std::string("#("), const std::string &closeDel=std::string(")")
[static]
 

Given input string toCatch catch val from string opt, by default of the form #(opt) and remove "#(opt)" from the original string.

Parameters:
toCatch string for which expansion is to be done
openDel opening delimiter (defaults to "#(")
closeDel closing delimiter (defaults to ")")
Returns:
-1 if attempt at expansion failed, else atoi(opt). TODO: Perhaps add optional arguments to specify alternate delimiters.

int facilities::Util::catchOptionVal std::string *  toCatch,
const int  ops = 0,
const std::string &  openDel = std::string("#("), const std::string &closeDel=std::string(")")
[static]
 

Given input string toCatch catch val from string opt, by default of the form #(opt) and remove "#(opt)" from the original string.

Parameters:
toCatch string for which expansion is to be done
openDel opening delimiter (defaults to "#(")
closeDel closing delimiter (defaults to ")")
Returns:
-1 if attempt at expansion failed, else atoi(opt). TODO: Perhaps add optional arguments to specify alternate delimiters.

int facilities::Util::expandEnvVar std::string *  toExpand,
const std::string &  openDel = std::string("$("), const std::string &closeDel=std::string(")")
[static]
 

Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified

Parameters:
toExpand string for which expansion is to be done
openDel opening delimiter (defaults to "$(")
closeDel closing delimiter (defaults to ")")
Returns:
-1 if attempt at expansion failed at least once, else number of successful expansions.
TODO: Perhaps add optional arguments to specify alternate delimiters.

int facilities::Util::expandEnvVar std::string *  toExpand,
const std::string &  openDel = std::string("$("), const std::string &closeDel=std::string(")")
[static]
 

Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified

Parameters:
toExpand string for which expansion is to be done
openDel opening delimiter (defaults to "$(")
closeDel closing delimiter (defaults to ")")
Returns:
-1 if attempt at expansion failed at least once, else number of successful expansions.
TODO: Perhaps add optional arguments to specify alternate delimiters.

int facilities::Util::expandEnvVar std::string *  toExpand,
const std::string &  openDel = std::string("$("), const std::string &closeDel=std::string(")")
[static]
 

Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified

Parameters:
toExpand string for which expansion is to be done
openDel opening delimiter (defaults to "$(")
closeDel closing delimiter (defaults to ")")
Returns:
-1 if attempt at expansion failed at least once, else number of successful expansions.
TODO: Perhaps add optional arguments to specify alternate delimiters.

int facilities::Util::expandEnvVar std::string *  toExpand,
const std::string &  openDel = std::string("$("), const std::string &closeDel=std::string(")")
[static]
 

Given input string toExpand expand references to environment variables, by default of the form and put the expanded version back into the original string. Alternate delimiters for the varname may optionally be specified

Parameters:
toExpand string for which expansion is to be done
openDel opening delimiter (defaults to "$(")
closeDel closing delimiter (defaults to ")")
Returns:
-1 if attempt at expansion failed at least once, else number of successful expansions.
TODO: Perhaps add optional arguments to specify alternate delimiters.

const char* facilities::Util::itoa int  val,
std::string &  outStr
[static]
 

Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.

Parameters:
val 
outStr will be modified by this method
Returns:
const char* based on the contents of outStr.c_str()

const char* facilities::Util::itoa int  val,
std::string &  outStr
[static]
 

Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.

Parameters:
val 
outStr will be modified by this method
Returns:
const char* based on the contents of outStr.c_str()

const char* facilities::Util::itoa int  val,
std::string &  outStr
[static]
 

Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.

Parameters:
val 
outStr will be modified by this method
Returns:
const char* based on the contents of outStr.c_str()

const char * facilities::Util::itoa int  val,
std::string &  outStr
[static]
 

Given an input integer val to convert and an output string outStr converts val into a std::string. This method duplicates the stdlib.h method itoa, except that it returns std::string rather than char*.

Parameters:
val 
outStr will be modified by this method
Returns:
const char* based on the contents of outStr.c_str()
00054                                                    {
00055     // Purpose and Method:  Provide a standard routine to convert integers
00056     //    into std::string.  The method used depends upon the availability of
00057     //    the stringstream classes.  The stringstream classes are the
00058     //    standard, but some compilers do yet support them.
00059     //    The method used is determined by the DEFECT_NO_STRINGSTREAM
00060     //    macro, defined in the facilities requirements file.
00061 
00062     static char outCharPtr[20];
00063 
00064 #ifdef DEFECT_NO_STRINGSTREAM
00065     // Using static buffer to avoid problems with memory allocation
00066     char a[100]=""; 
00067     std::ostrstream locStream(a,100);
00068 #else
00069     std::ostringstream locStream;
00070     locStream.str("");
00071 #endif
00072     locStream << val;
00073 #ifdef DEFECT_NO_STRINGSTREAM
00074     locStream << std::ends;
00075 #endif
00076     outStr = locStream.str();
00077     strcpy(outCharPtr, outStr.c_str());
00078     return outCharPtr;
00079   }

void facilities::Util::keyValueTokenize std::string  input,
const std::string &  delimiters,
std::map< std::string, std::string > &  tokenMap,
const std::string &  pairDelimiter = std::string("="),
bool  clear = true
[static]
 

This routine breaks down a string into key/value token pairs and stores them in the user-supplied map. , based on the characters appearing in the string delimiters and the value of pairDelimiter. In a typical example, input could be "key1=val1,key2=val2,key3=val3". In this case invoke with delimiters=std::string(",") and pairDelimiter=std::string("=") (or omit pairDelimiter since it has the default value)

Parameters:
input string to be tokenized
delimiters string containing one or more delimiter characters
tokenMap map of strings to hold resulting tokens
pairDelimiter string separating key and value; defaults to "="
clear if true (default) tokens will be cleared at the start of processing

void facilities::Util::keyValueTokenize std::string  input,
const std::string &  delimiters,
std::map< std::string, std::string > &  tokenMap,
const std::string &  pairDelimiter = std::string("="),
bool  clear = true
[static]
 

This routine breaks down a string into key/value token pairs and stores them in the user-supplied map. , based on the characters appearing in the string delimiters and the value of pairDelimiter. In a typical example, input could be "key1=val1,key2=val2,key3=val3". In this case invoke with delimiters=std::string(",") and pairDelimiter=std::string("=") (or omit pairDelimiter since it has the default value)

Parameters:
input string to be tokenized
delimiters string containing one or more delimiter characters
tokenMap map of strings to hold resulting tokens
pairDelimiter string separating key and value; defaults to "="
clear if true (default) tokens will be cleared at the start of processing
00142                                           {
00143     if (clear) tokens.clear();
00144 
00145     std::vector<std::string> strvec;
00146     stringTokenize(input,delimiters,strvec,true);
00147     unsigned advance = pairDelimiter.size();
00148 
00149     std::vector<std::string>::const_iterator input_itr = strvec.begin();
00150     while(input_itr!=strvec.end())
00151       {
00152         std::string current = *input_itr++;
00153         std::string::size_type j = current.find(pairDelimiter);
00154         std::string key   = current.substr(0, j);
00155         std::string value = current.substr(j+advance);
00156         tokens[key] = value;
00157       } 
00158   }

double facilities::Util::stringToDouble const std::string &  InStr  )  [static]
 

converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType

double facilities::Util::stringToDouble const std::string &  InStr  )  [static]
 

converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType

double facilities::Util::stringToDouble const std::string &  InStr  )  [static]
 

converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType

double facilities::Util::stringToDouble const std::string &  InStr  )  [static]
 

converts a std::string to a double. If string contents are not of proper form, throws facilities::WrongType

00103                                                     {
00104     double val;
00105     char  junk[3];
00106     int nItem = sscanf(inStr.c_str(), "%lg %1s", &val, junk);
00107     if (nItem != 1) {
00108       throw WrongType(inStr, "double");
00109     }
00110     return val;
00111   }

int facilities::Util::stringToInt const std::string &  InStr  )  [static]
 

converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType

int facilities::Util::stringToInt const std::string &  InStr  )  [static]
 

converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType

int facilities::Util::stringToInt const std::string &  InStr  )  [static]
 

converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType

int facilities::Util::stringToInt const std::string &  InStr  )  [static]
 

converts a std::string to an int. If string contents are not of proper form, throws facilities::WrongType

00114                                               {
00115     int  val;
00116     char junk[3];
00117     int nItem = sscanf(inStr.c_str(), "%d %1s", &val, junk);
00118     if (nItem != 1) {
00119       throw WrongType(inStr, "int");
00120     }
00121     return val;
00122   }

void facilities::Util::stringTokenize std::string  input,
const std::string &  delimiters,
std::vector< std::string > &  tokens,
bool  clear = true
[static]
 

This routine breaksdown a string into tokens, based on the characters appearing in the string delimiters.

Parameters:
input string to be tokenized
delimiters string containing one or more delimiter characters
tokens vector of strings to hold resulting tokens
clear if true (default) tokens will be cleared at the start of processing

void facilities::Util::stringTokenize std::string  input,
const std::string &  delimiters,
std::vector< std::string > &  tokens,
bool  clear = true
[static]
 

This routine breaks down a string into tokens, based on the characters appearing in the string delimiters.

Parameters:
input string to be tokenized
delimiters string containing one or more delimiter characters
tokens vector of strings to hold resulting tokens
clear if true (default) tokens will be cleared at the start of processing

void facilities::Util::stringTokenize std::string  input,
const std::string &  delimiters,
std::vector< std::string > &  tokens,
bool  clear = true
[static]
 

This routine breaksdown a string into tokens, based on the characters appearing in the string delimiters.

Parameters:
input string to be tokenized
delimiters string containing one or more delimiter characters
tokens vector of strings to hold resulting tokens
clear if true (default) tokens will be cleared at the start of processing

void facilities::Util::stringTokenize std::string  input,
const std::string &  delimiters,
std::vector< std::string > &  tokens,
bool  clear = true
[static]
 

This routine breaks down a string into tokens, based on the characters appearing in the string delimiters.

Parameters:
input string to be tokenized
delimiters string containing one or more delimiter characters
tokens vector of strings to hold resulting tokens
clear if true (default) tokens will be cleared at the start of processing
00125                                                                       {
00126     if (clear) tokens.clear();
00127 
00128     std::string::size_type j;
00129     while ( (j = input.find_first_of(delimiters)) != std::string::npos ) {
00130       if (j != 0) tokens.push_back(input.substr(0, j));
00131       input = input.substr(j+1);
00132     }
00133     tokens.push_back(input);
00134     if (tokens.back() == "") tokens.pop_back();
00135   }

unsigned facilities::Util::trimTrailing std::string *  toTrim  )  [static]
 

Trim trailing white space characters from the supplied string. White space characters for this purpose are blank, carriage return, line feed and form feed. Return # of characters trimmed.

unsigned facilities::Util::trimTrailing std::string *  toTrim  )  [static]
 

Trim trailing white space characters from the supplied string. White space characters for this purpose are blank, carriage return, line feed and form feed. Return # of characters trimmed.

00166                                                {
00167     static const char blank=' ';
00168     static const char LF=0xA;    // new line
00169     static const char FF=0xC;    // form feed
00170     static const char CR=0xD;    // carriage return
00171 
00172     unsigned orig = toTrim->size();
00173     unsigned last = orig - 1;
00174     bool notDone = true;
00175     unsigned nTrimmed = 0;
00176 
00177 
00178     while (notDone) {
00179       char lastChar = (*toTrim)[last];
00180       switch (lastChar) {
00181       case blank:
00182       case LF:
00183       case FF:
00184       case CR:
00185         last--;
00186         nTrimmed++;
00187         break;
00188       default:
00189         notDone=false;
00190         break;
00191       }
00192     }
00193     if (nTrimmed)  toTrim->resize(orig - nTrimmed);
00194 
00195     return nTrimmed;
00196   }


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 19:21:15 2011 for BOSS6.5.5 by  doxygen 1.3.9.1