00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PUTILITIES_H
00021 #define PUTILITIES_H
00022
00023 #include "PLibraries.h"
00024
00025 #define isNAN(x) !((x) <= 0 || (x) > 0)
00026 #define ends_with(str, x) (string(str).find(string(x)) != string::npos && \
00027 string(str).find(string(x)) == string(str).length() - \
00028 string(x).length())
00029
00040 class PUtilities {
00041 public:
00042
00043
00044
00045
00051 static void copyFile(const string &newFileName, const string &fileToCopy);
00052
00058 static void makeDirectory(const string &dirName);
00059
00060
00061
00067 static void trimSpaces(string &str);
00068
00075 template <typename T>
00076 static string toStr(const T &x)
00077 {
00078 stringstream ss;
00079 ss << x;
00080 return ss.str();
00081 }
00082
00088 static string padLeft(const string &s, unsigned int len, char padChar = ' ');
00089
00095 static string padRight(const string &s, unsigned int len, char padChar = ' ');
00096
00109 static vector<string> getLinesStarting(const vector<string> &lines,
00110 const string &prefix,
00111 const string &chainId = "",
00112 bool trimPrefix = false,
00113 const string &terminationCode = "");
00114
00120 static vector<string> getTokens(const string &curLine);
00121
00122
00123
00136 static vector<string> getLinesStarting(const string &fileName,
00137 const string &prefix,
00138 const string &chainId="",
00139 bool trimPrefix = false,
00140 const string &terminationCode = "");
00141
00147 static vector<string> getLines(const string &fileName, const string &chainId="");
00148
00153 static void appendToFile(const string &fileName, const string &line);
00154
00155
00156
00162 static void AbortProgram(const string &message);
00163
00169 static const void *PointerThatIsNot(const void *p1, const void *p2, const void *have);
00170
00176 template <typename T>
00177 static T** New2DArray(unsigned size) {
00178 T** table = new T*[size];
00179
00180 for(unsigned i = 0; i < size; i++) {
00181 table[i] = new T[size];
00182 }
00183
00184 return table;
00185 }
00186
00192 template <typename T>
00193 static void Delete2DArray(T **table, unsigned size) {
00194 for(unsigned i = 0; i < size; i++) {
00195 delete[] table[i];
00196 }
00197
00198 delete[] table;
00199 }
00200
00201 };
00202
00203 #endif