Rev 1011 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1011 | Rev 1024 | ||
|---|---|---|---|
| 1 | /*************************************************************************** |
1 | /*************************************************************************** |
| 2 | * Copyright (C) 2003 by Mattias Runge * |
2 | * Copyright (C) 2003 by Mattias Runge * |
| 3 | * mattias@mrunge.se * |
3 | * mattias@mrunge.se * |
| 4 | * * |
4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
8 | * (at your option) any later version. * |
| 9 | * * |
9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
| 14 | * * |
14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
19 | ***************************************************************************/ |
| 20 | #ifndef _TOOLS_H |
20 | #ifndef _TOOLS_H |
| 21 | #define _TOOLS_H |
21 | #define _TOOLS_H |
| 22 | 22 | ||
| 23 | #include <string> |
23 | #include <string> |
| 24 | #include <vector> |
24 | #include <vector> |
| 25 | #include <fstream> |
25 | #include <fstream> |
| 26 | #include <sstream> |
26 | #include <sstream> |
| 27 | #include <stdexcept> |
27 | #include <stdexcept> |
| 28 | #include <iostream> |
28 | #include <iostream> |
| 29 | 29 | ||
| 30 | using namespace std; |
30 | using namespace std; |
| 31 | 31 | ||
| 32 | #include <cmath> |
32 | #include <cmath> |
| 33 | #include <sys/types.h> |
33 | #include <sys/types.h> |
| 34 | #include <dirent.h> |
34 | #include <dirent.h> |
| 35 | 35 | ||
| 36 | string niceTime(); |
36 | string niceTime(); |
| 37 | - | ||
| 38 | unsigned int hex2uint(string hex); |
37 | unsigned int hex2uint(string hex); |
| 39 | - | ||
| 40 | string hex2bin(string hex); |
38 | string hex2bin(string hex); |
| 41 | string bin2hex(string bin); |
39 | string bin2hex(string bin); |
| 42 | - | ||
| 43 | float bin2float(string bin); |
40 | float bin2float(string bin); |
| 44 | string float2bin(float num, int length); |
41 | string float2bin(float num, int length); |
| 45 | - | ||
| 46 | unsigned int bin2uint(string bin); |
42 | unsigned int bin2uint(string bin); |
| 47 | string uint2bin(unsigned int num, int length); |
43 | string uint2bin(unsigned int num, int length); |
| 48 | - | ||
| 49 | string uint2hex(unsigned int num, int length); |
44 | string uint2hex(unsigned int num, int length); |
| 50 | - | ||
| 51 | vector<string> explode(string delimiter, string str); |
45 | vector<string> explode(string delimiter, string str); |
| 52 | string strtoupper(string s); |
46 | string strtoupper(string s); |
| 53 | string strtolower(string s); |
47 | string strtolower(string s); |
| 54 | string trim(string s); |
48 | string trim(string s); |
| 55 | string trim(const string s, char c); |
49 | string trim(const string s, char c); |
| 56 | int stoi(const string s); |
50 | int stoi(const string s); |
| 57 | string itos(int i); |
51 | string itos(int i); |
| 58 | string utos(unsigned int i); |
52 | string utos(unsigned int i); |
| 59 | unsigned int stou(const string s); |
53 | unsigned int stou(const string s); |
| 60 | float stof(const string s); |
54 | float stof(const string s); |
| 61 | string ftos(float f); |
55 | string ftos(float f); |
| 62 | string str_replace(string search, string replace, string str); |
56 | string str_replace(string search, string replace, string str); |
| 63 | string file_get_contents(string filename); |
57 | string file_get_contents(string filename); |
| 64 | bool file_exists(string filename); |
58 | bool file_exists(string filename); |
| 65 | string escape(string in); |
59 | string escape(string in); |
| 66 | string rpad(string in, int length, char c); |
60 | string rpad(string in, int length, char c); |
| 67 | string lpad(string in, int length, char c); |
61 | string lpad(string in, int length, char c); |
| 68 | - | ||
| 69 | class FileTools |
- | |
| 70 | { |
- | |
| 71 | public: |
- | |
| 72 | static vector<string> GetDirList(string path); |
- | |
| 73 | static string GetUniqeFilename(string path, string prefix, string postfix); |
- | |
| 74 | static string GetUniqeFilename(string path) { return GetUniqeFilename(path, "", ""); } |
- | |
| 75 | static bool SaveFile(string filepath, string data); |
- | |
| 76 | static string Get(string src); |
- | |
| 77 | static bool Copy(string src, string dest); |
- | |
| 78 | static bool Exist(string filename); |
- | |
| 79 | - | ||
| 80 | }; |
- | |
| 81 | 62 | ||
| 82 | #endif // _TOOLS_H |
63 | #endif // _TOOLS_H |
| 83 | 64 | ||