Isis 3.0 Developer's Reference (API) |
Home |
00001 #ifndef IString_h 00002 #define IString_h 00003 00025 #include <string> 00026 #include <vector> 00027 00028 #include <QString> 00029 #include <QStringList> 00030 00031 #include "Constants.h" 00032 00033 namespace Isis { 00034 class IString; 00035 00036 bool toBool(const QString &); 00037 int toInt(const QString &); 00038 BigInt toBigInt(const QString &); 00039 double toDouble(const QString &); 00040 00041 QString toString(bool); 00042 QString toString(char); 00043 QString toString(const int &); 00044 QString toString(const unsigned int &); 00045 QString toString(const BigInt &); 00046 QString toString(double, int precision = 14); 00047 00179 class IString : public std::string { 00180 public: 00181 IString(); 00182 00183 IString(const std::string &str); 00184 IString(const IString &str); 00185 IString(const char *str); 00186 IString(const int &num); 00187 IString(const double &num, const int piPrecision = 14); 00188 IString(const BigInt &num); 00189 IString(const QString &str); 00190 00191 ~IString(); 00192 00193 IString Trim(const std::string &chars); 00194 static std::string Trim(const std::string &chars, const std::string &str); 00195 00196 IString TrimHead(const std::string &chars); 00197 static std::string TrimHead(const std::string &chars, const std::string &str); 00198 00199 IString TrimTail(const std::string &chars); 00200 static std::string TrimTail(const std::string &chars, const std::string &str); 00201 00202 IString UpCase(); 00203 static std::string UpCase(const std::string &str); 00204 00205 IString DownCase(); 00206 static std::string DownCase(const std::string &str); 00207 00208 int ToInteger() const; 00209 static int ToInteger(const std::string &str); 00210 00211 BigInt ToBigInteger() const; 00212 static BigInt ToBigInteger(const std::string &str); 00213 00214 double ToDouble() const; 00215 static double ToDouble(const std::string &str); 00216 00217 QString ToQt() const; 00218 static QString ToQt(const std::string &str); 00219 00220 IString Token(const IString &separator); 00221 static int Split(const char separator, const std::string &instr, 00222 std::vector<std::string> &tokens, 00223 bool allowEmptyEntries = true); 00224 00225 IString Compress(bool force = false); 00226 static std::string Compress(const std::string &str, bool force = false); 00227 00228 IString Replace(const std::string &from, const std::string &to, 00229 int maxReplaceCount = 20); 00230 static std::string Replace(const std::string &str, 00231 const std::string &from, 00232 const std::string &to, 00233 int maxReplacementCount = 20); 00234 00235 IString Replace(const std::string &from, const std::string &to , bool honorquotes); 00236 static IString Replace(const std::string &str, const std::string &from, 00237 const std::string &to , bool honorquotes); 00238 00239 IString Convert(const std::string &listofchars, const char &to); 00240 static std::string Convert(const std::string &str, 00241 const std::string &listofchars, 00242 const char &to); 00243 00244 IString ConvertWhiteSpace(); 00245 static std::string ConvertWhiteSpace(const std::string &str); 00246 00247 IString Remove(const std::string &del); 00248 static std::string Remove(const std::string &del, const std::string &str); 00249 00255 operator int() const { 00256 return ToInteger(); 00257 }; 00258 00265 operator BigInt() const { 00266 return ToBigInteger(); 00267 }; 00268 00274 operator double() const { 00275 return ToDouble(); 00276 }; 00277 00283 operator IString() const { 00284 return ToQt(); 00285 }; 00286 00287 IString &operator= (const int &value); 00288 00289 IString &operator= (const BigInt &value); 00290 00298 IString &operator= (const double &value) { 00299 SetDouble(value); 00300 return *this; 00301 } 00302 00303 bool Equal(const std::string &str) const; 00304 static bool Equal(const std::string &str1, const std::string &str2); 00305 00306 static std::string ToStd(const QString &str); 00307 00308 static QStringList ToQt(const std::vector<std::string> &sl); 00309 static std::vector<std::string> ToStd(const QStringList &sl); 00310 00311 private: 00312 void SetDouble(const double &value, const int piPrecision = 14); 00313 }; 00314 00315 std::ostream &operator<<(std::ostream &os, const QString &string); 00316 std::ostream &operator<<(std::ostream &os, const QStringRef &string); 00317 } 00318 00319 #endif