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, bool trimPrefix = false,
00111 const string &terminationCode = "");
00112
00118 static vector<string> getTokens(const string &curLine);
00119
00120
00121
00134 static vector<string> getLinesStarting(const string &fileName,
00135 const string &prefix, bool trimPrefix = false,
00136 const string &terminationCode = "");
00137
00143 static vector<string> getLines(const string &fileName);
00144
00149 static void appendToFile(const string &fileName, const string &line);
00150
00151
00152
00158 static void AbortProgram(const string &message);
00159
00165 static const void *PointerThatIsNot(const void *p1, const void *p2, const void *have);
00166
00172 template <typename T>
00173 static T** New2DArray(unsigned size) {
00174 T** table = new T*[size];
00175
00176 for(unsigned i = 0; i < size; i++) {
00177 table[i] = new T[size];
00178 }
00179
00180 return table;
00181 }
00182
00188 template <typename T>
00189 static void Delete2DArray(T **table, unsigned size) {
00190 for(unsigned i = 0; i < size; i++) {
00191 delete[] table[i];
00192 }
00193
00194 delete[] table;
00195 }
00196
00197 };
00198
00199 #endif