PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
pge_file_lib_globs.h
Go to the documentation of this file.
1 
8 #ifndef _PGE_FILE_LIB_GLOBS_H
9 #define _PGE_FILE_LIB_GLOBS_H
10 
49 #ifdef PGE_FILES_QT
50 #include <QString>
51 #include <QStringList>
52 #include <QFile>
53 #include <QTextStream>
54 #include <QTextCodec>
55 #include <QVector>
56 #include <QPair>
57 #include <QMap>
58 #include <QObject>
59 #include <tgmath.h>
60 #if defined(PGE_ENGINE)||defined(PGE_EDITOR)
61 #include <QSize>
62 #endif
63 #define PGE_FILES_INHERED public QObject
64 #define PGESTRING QString
65 #define PGESTRINGisEmpty() isEmpty()
66 #define PGESTR_Simpl(str) str.simplified()
67 #define PGEGetChar(chr) chr.toLatin1()
68 #define PGEChar QChar
69 #define PGESTRINGList QStringList
70 #define PGEVECTOR QVector
71 #define PGELIST QList
72 #define PGEPAIR QPair
73 #define PGEMAP QMap
74 #define PGEFILE QFile
75 #define PGE_SPLITSTR(dst, src, sep) dst=src.split(sep);
76 #define PGE_ReplSTR(src, from, to) src.replace(from, to)
77 #define PGE_RemSSTR(src, substr) src.remove(substr)
78 #define PGE_RemSRng(pos, len) remove(pos, len)
79 inline bool IsNULL(PGESTRING str) { return str.isNull(); }
80 inline int toInt(PGESTRING str){ return str.toInt(); }
81 inline float toFloat(PGESTRING str){ return str.toFloat(); }
82 inline double toDouble(PGESTRING str){ return str.toDouble(); }
83 inline PGESTRING removeSpaces(PGESTRING src) { return src.remove(' '); }
84 template<typename T>
85 PGESTRING fromNum(T num) { return QString::number(num); }
86 #else
87 #include <string>
88 #include <vector>
89 #include <utility>
90 #include <iostream>
91 #include <fstream>
92 #include <sstream>
93 #include <cstring>
94 #include <algorithm>
95 #include <map>
96 #define PGE_FILES_INGERED
97 #define PGESTRING std::string
98 #define PGESTRINGisEmpty() empty()
99 inline PGESTRING PGESTR_Simpl(PGESTRING str)
100  { str.erase( std::remove_if( str.begin(), str.end(), ::isspace ), str.end() );
101  return str;}
102 #define PGEGetChar(chr) chr
103 #define PGEChar char
104 #define PGESTRINGList std::vector<std::string >
105 #define PGEVECTOR std::vector
106 #define PGELIST std::vector
107 #define PGEPAIR std::pair
108 #define PGEMAP std::map
109 #define PGEFILE std::fstream
110 namespace PGE_FileFormats_misc
111 {
112  void split(std::vector<std::string>& dest, const std::string& str, std::string separator);
113  void replaceAll(std::string& str, const std::string& from, const std::string& to);
114  void RemoveSub(std::string& sInput, const std::string& sub);
115  bool hasEnding (std::string const &fullString, std::string const &ending);
116 }
117 #define PGE_SPLITSTR(dst, src, sep) dst.clear(); PGE_FileFormats_misc::split(dst, src, sep);
118 inline PGESTRING PGE_ReplSTR(PGESTRING src, PGESTRING from, PGESTRING to) {
119  PGE_FileFormats_misc::replaceAll(src, from, to);
120  return src;
121 }
122 
123 inline PGESTRING PGE_RemSSTR(PGESTRING src, PGESTRING substr) { PGE_FileFormats_misc::RemoveSub(src, substr); return src; }
124 #define PGE_RemSRng(pos, len) erase(pos, len)
125 inline bool IsNULL(PGESTRING str) { return (str.empty()!=0); }
126 inline int toInt(PGESTRING str){ return std::atoi(str.c_str()); }
127 inline float toFloat(PGESTRING str){ return std::atof(str.c_str()); }
128 inline double toDouble(PGESTRING str){ return std::atof(str.c_str()); }
129 inline PGESTRING removeSpaces(PGESTRING src) { return PGE_RemSSTR(src, " "); }
130 template<typename T>
131 PGESTRING fromNum(T num) { std::ostringstream n; n<<num; return n.str(); }
132 #endif
133 
137 namespace PGE_FileFormats_misc
138 {
142  class FileInfo
143  {
144  public:
148  FileInfo();
153  FileInfo(PGESTRING filepath);
158  void setFile(PGESTRING filepath);
163  PGESTRING suffix();
183  PGESTRING dirpath();
184  private:
188  void rebuildData();
192  PGESTRING filePath;
196  PGESTRING _filename;
200  PGESTRING _suffix;
204  PGESTRING _basename;
208  PGESTRING _dirpath;
209  };
210 
215  {
216  public:
220  enum positions{
227  };
233  static bool exists(PGESTRING filePath);
237  TextFileInput();
243  TextFileInput(PGESTRING filePath, bool utf8=false);
247  ~TextFileInput();
253  bool open(PGESTRING filePath, bool utf8=false);
257  void close();
263  PGESTRING read(long len);
273  PGESTRING readAll();
278  bool eof();
283  long long tell();
289  void seek(long long pos, positions relativeTo);
290  private:
291  #ifdef PGE_FILES_QT
292  QFile file;
295  QTextStream stream;
296  #else
297  std::fstream stream;
299  #endif
300  };
301 
302 }
303 
304 #endif // _PGE_FILE_LIB_GLOBS_H
305 
Relative to end of file.
Definition: pge_file_lib_globs.h:226
bool eof()
Is carriage position at end of file.
Definition: pge_file_lib_globs.cpp:169
Provides cross-platform text file reading interface.
Definition: pge_file_lib_globs.h:214
TextFileInput()
Constructor.
Definition: pge_file_lib_globs.cpp:71
#define PGESTRING
A macro which equal to std::string if PGE File Library built in the STL mode and equal to QString if ...
Definition: pge_file_lib_globs.h:97
bool open(PGESTRING filePath, bool utf8=false)
Opening of the file.
Definition: pge_file_lib_globs.cpp:89
PGESTRING filename()
Returns full filename without path.
Definition: pge_file_lib_globs.cpp:224
void seek(long long pos, positions relativeTo)
Changes position of carriage to specific file position.
Definition: pge_file_lib_globs.cpp:187
PGESTRING read(long len)
Reads requested number of characters from a file.
Definition: pge_file_lib_globs.cpp:121
PGESTRING readLine()
Reads whole line before line feed character.
Definition: pge_file_lib_globs.cpp:134
~TextFileInput()
Destructor.
Definition: pge_file_lib_globs.cpp:79
PGESTRING basename()
Returns base name part (first part of file name before first dot)
Definition: pge_file_lib_globs.cpp:234
PGESTRING dirpath()
Returns full directory path where actual file is located.
Definition: pge_file_lib_globs.cpp:239
Relative to current position.
Definition: pge_file_lib_globs.h:222
PGESTRING readAll()
Reads all data from a file at current position of carriage.
Definition: pge_file_lib_globs.cpp:150
void setFile(PGESTRING filepath)
Sets file which will be used to calculate file information.
Definition: pge_file_lib_globs.cpp:213
Provides cross-platform file path calculation for a file names or paths.
Definition: pge_file_lib_globs.h:142
void close()
Close currently opened file.
Definition: pge_file_lib_globs.cpp:112
positions
Relative positions of carriage.
Definition: pge_file_lib_globs.h:220
PGESTRING suffix()
Returns file extension (last part of filename after last dot)
Definition: pge_file_lib_globs.cpp:219
long long tell()
Returns current position of carriage relative to begin of file.
Definition: pge_file_lib_globs.cpp:178
Relative to begin of file.
Definition: pge_file_lib_globs.h:224
static bool exists(PGESTRING filePath)
Checks is requested file exist.
Definition: pge_file_lib_globs.cpp:57
PGESTRING fullPath()
Returns absolute path to file.
Definition: pge_file_lib_globs.cpp:229
FileInfo()
Constructor.
Definition: pge_file_lib_globs.cpp:205