Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

parseutil.h

Go to the documentation of this file.
00001 #ifndef PARSEUTIL_H 00002 #define PARSEUTIL_H 00003 00004 #include <string> 00005 #include <exception> 00006 #include <vector> 00007 00008 #include "common.h" 00009 00010 BOREALIS_NAMESPACE_BEGIN; 00011 00012 // Returns a vector of the constituent strings that make up 'src'. 00013 // 'src' is interpreted to be a sequence of constituent strings, separated 00014 // by any of the characters appearing in 'delimiters'. 00015 // 00016 // The returned vector's elements have the same ordering as the constituent 00017 // strings in 'src'. The delimiter characters don't appear as elements in the 00018 // output vector, or as part of the constituent strings that are in the output 00019 // vector. 00020 // 00021 // Consecutive delimiters are taken to delimit an empty string, which will 00022 // appear in the output vector. 00023 vector<string> unpackString(const string & src, const string & delimiters); 00024 00025 00026 // The following functions attempt to parse the specified string to a particular 00027 // data type. The functions throws an exception if the parse is unsuccessful. 00028 bool stringToBool(const string & s) 00029 throw (exception); 00030 00031 size_t stringToSize_t(const string & s) 00032 throw (exception); 00033 00034 int stringToInt(const string & s) 00035 throw (exception); 00036 00037 unsigned int stringToUInt(const string & s) 00038 throw (exception); 00039 00040 long stringToLong(const string & s) 00041 throw (exception); 00042 00043 unsigned long stringToULong(const string & s) 00044 throw (exception); 00045 00046 unsigned long long stringToULongLong(const string & s) 00047 throw (exception); 00048 00049 double stringToDouble(const string & s) 00050 throw (exception); 00051 00052 00053 // Finds the index info argv of the command-line argument with the specified 00054 // value. Throws an exception if it can't be found, or if it apperas more than 00055 // once. 00056 // 00057 // Doesn't check argv[0], as that's the name of the program, not an argument. 00058 // 00059 // If argname is the very last element in argv, and (! canBeLast), an exception 00060 // is thrown. This is to benefit arguments that indicate that the next argument 00061 // is the value to some certain parameter. 00062 size_t getArgUniqueIndex(string argname, bool canBeLast, int argc, 00063 const char * argv[]) 00064 throw (exception); 00065 00066 00067 // The following functions find and parse a command-line argument of the form 00068 // "argname". 00069 // They throw an exception if it can't be found, or if the following cmd-line 00070 // argument can't be parsed as a the data type indicated by the function's name. 00071 // 00072 // "argname" must appear only once in the parameters. 00073 // 00074 // For the functions that have range parameters, if the valid value range is 00075 // violated, an exception is thrown. 00076 double getUniqueDoubleArg(string argname, 00077 int argc, const char * argv[], 00078 double minValue, double maxValue) 00079 throw (exception); 00080 00081 00082 int getUniqueIntArg(string argname, 00083 int argc, const char * argv[], 00084 int minValue, int maxValue) 00085 throw (exception); 00086 00087 00088 string getUniqueStringArg(string argname, 00089 int argc, 00090 const char * argv[]) 00091 throw (exception); 00092 00093 00094 // Simply returns whether or not the specified token appears in the cmd-line 00095 // arguments. 00096 // 00097 // Doesn't check argv[0], as that's the name of the program, not an argument. 00098 bool argInCmdLine(string argumentName, 00099 int argc, const char * argv[]); 00100 00101 BOREALIS_NAMESPACE_END; 00102 00103 #endif

Generated on Fri Nov 12 15:15:21 2004 for Borealis by doxygen 1.3.8