00001
00002 #ifndef FACILITIES_UTIL_H
00003 #define FACILITIES_UTIL_H
00004
00005 #include <string>
00006 #include <vector>
00007 #include <map>
00008
00016 namespace facilities {
00019
00021 class Untranslatable {
00022 public:
00023 Untranslatable(const std::string& toTrans) : m_badVar(toTrans) {}
00024 std::string m_badVar;
00025 };
00026
00028
00029 class WrongType {
00030 public:
00031 WrongType(const std::string& toConvert, const std::string& typeName) :
00032 m_toConvert(toConvert), m_typeName(typeName) {}
00033 std::string getMsg() {
00034 std::string msg =
00035 "facilities::WrongType. Cannot convert '" + m_toConvert + "' to type "
00036 + m_typeName;
00037 return msg;
00038 }
00039 private:
00040 std::string m_toConvert;
00041 std::string m_typeName;
00042 };
00043
00044 class Util {
00045 public:
00060 static int expandEnvVar(std::string* toExpand,
00061 const std::string& openDel = std::string("$("),
00062 const std::string& closeDel = std::string(")"));
00063
00073 static const char* itoa(int val, std::string &outStr);
00074
00076 static int atoi(const std::string& InStr);
00077
00078
00081 static double stringToDouble(const std::string& InStr);
00082
00085 static int stringToInt(const std::string& InStr);
00086
00087
00088
00097 static void stringTokenize(std::string input, const std::string &delimiters,
00098 std::vector<std::string> &tokens,
00099 bool clear = true);
00100
00117 static void keyValueTokenize(std::string input,
00118 const std::string &delimiters,
00119 std::map<std::string,std::string> &tokenMap,
00120 const std::string& pairDelimiter =
00121 std::string("="),
00122 bool clear = true);
00123
00130 static std::string basename(const std::string &path);
00131
00137 static unsigned trimTrailing(std::string* toTrim);
00138 };
00139 }
00140
00141 #endif