00001
00002 #ifndef FACILITIES_UTIL_H
00003 #define FACILITIES_UTIL_H
00004
00005 #include <string>
00006 #include <vector>
00007
00015 namespace facilities {
00018
00020 class Untranslatable {
00021 public:
00022 Untranslatable(const std::string& toTrans) : m_badVar(toTrans) {}
00023 std::string m_badVar;
00024 };
00025
00027
00028 class WrongType {
00029 public:
00030 WrongType(const std::string& toConvert, const std::string& typeName) :
00031 m_toConvert(toConvert), m_typeName(typeName) {}
00032 std::string getMsg() {
00033 std::string msg =
00034 "facilities::WrongType. Cannot convert '" + m_toConvert + "' to type "
00035 + m_typeName;
00036 return msg;
00037 }
00038 private:
00039 std::string m_toConvert;
00040 std::string m_typeName;
00041 };
00042
00043 class Util {
00044 public:
00059 static int expandEnvVar(std::string* toExpand,
00060 const std::string& openDel = std::string("$("),
00061 const std::string& closeDel = std::string(")"));
00062
00072 static int catchOptionVal(std::string* toCatch,
00073 const int ops = 0,
00074 const std::string& openDel = std::string("#("),
00075 const std::string& closeDel = std::string(")"));
00076
00086 static const char* itoa(int val, std::string &outStr);
00087
00089 static int atoi(const std::string& InStr);
00090
00091
00094 static double stringToDouble(const std::string& InStr);
00095
00098 static int stringToInt(const std::string& InStr);
00099
00100
00101
00110 static void stringTokenize(std::string input, const std::string &delimiters,
00111 std::vector<std::string> &tokens,
00112 bool clear = true);
00113
00119 static std::string basename(const std::string &path);
00120 };
00121 }
00122
00123 #endif