MuldeR's Utilities for Qt
MUtilities
Global.h
Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
27 #pragma once
28 
29 #include <QString>
30 
31 //Forward Declarations
32 class QProcess;
33 
35 
39 //MUtils API
40 #ifdef _MSC_VER
41 # ifdef MUTILS_DLL_EXPORT
42 # define MUTILS_API __declspec(dllexport)
43 # else
44 # ifndef MUTILS_STATIC_LIB
45 # define MUTILS_API __declspec(dllimport)
46 # else
47 # define MUTILS_API /*static lib*/
48 # endif
49 # endif
50 #else
51 # define MUTILS_API
52 #endif
53 
54 #define MUTILS_MAKE_STRING_HELPER(X) #X
55 #define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
56 #define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
57 
58 //Check Debug Flags
59 #if defined(_DEBUG) || defined(DEBUG) || (!defined(NDEBUG))
60 # define MUTILS_DEBUG (1)
61 # if defined(NDEBUG) || defined(QT_NO_DEBUG) || (!defined(QT_DEBUG))
62 # error Inconsistent DEBUG flags have been detected!
63 # endif
64 #else
65 # define MUTILS_DEBUG (0)
66 # if (!defined(NDEBUG)) || (!defined(QT_NO_DEBUG)) || defined(QT_DEBUG)
67 # error Inconsistent DEBUG flags have been detected!
68 # endif
69 #endif
70 
71 //Check CPU options
72 #if defined(_MSC_VER) && (!defined(__INTELLISENSE__)) && (!defined(_M_X64)) && defined(_M_IX86_FP)
73  #if (_M_IX86_FP != 0)
74  #error We should not enabled SSE or SSE2 in release builds!
75  #endif
76 #endif
77 
81 
83 namespace MUtils
84 {
92  MUTILS_API const QString& temp_folder(void);
93 
107  MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true, const QStringList *const extraPaths = NULL);
108 
116  MUTILS_API quint32 next_rand_u32(void);
117 
125  MUTILS_API quint64 next_rand_u64(void);
126 
136  MUTILS_API QString next_rand_str(const bool &bLong = false);
137 
151  MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
152 
168  MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy = false);
169 
177  MUTILS_API bool parity(quint32 value);
178 
188  MUTILS_API bool remove_file(const QString &fileName);
189 
201  MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive);
202 
212  MUTILS_API QString& trim_right(QString &str);
213 
223  MUTILS_API QString& trim_left(QString &str);
224 
234  MUTILS_API QString trim_right(const QString &str);
235 
245  MUTILS_API QString trim_left(const QString &str);
246 
256  MUTILS_API void natural_string_sort(QStringList &list, const bool bIgnoreCase);
257 
267  MUTILS_API QString clean_file_name(const QString &name);
268 
278  MUTILS_API QString clean_file_path(const QString &path);
279 
291  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value);
292 
306  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count);
307 
317  MUTILS_API QStringList available_codepages(const bool &noAliases = true);
318 
319  //Internal
320  namespace Internal
321  {
322  MUTILS_API int selfTest(const char *const buildKey, const bool debug);
323  static const int s_selfTest = selfTest(__DATE__ "@" __TIME__, MUTILS_DEBUG);
324  }
325 }
326 
328 
331 #define MUTILS_DELETE(PTR) do { if((PTR)) { delete (PTR); (PTR) = NULL; } } while(0)
332 
335 #define MUTILS_DELETE_ARRAY(PTR) do { if((PTR)) { delete [] (PTR); (PTR) = NULL; } } while(0)
336 
339 #define MUTILS_ZERO_MEMORY(PTR) memset(&(PTR), 0, sizeof((PTR)))
340 
343 #define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
344 
347 #define MUTILS_UTF8(STR) ((STR).toUtf8().constData())
348 
351 #define MUTILS_QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
352 
355 #define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")
MUTILS_API QStringList available_codepages(const bool &noAliases=true)
Retrieve a list of all available codepages.
MUTILS_API QString next_rand_str(const bool &bLong=false)
Generates a random string.
MUTILS_API bool remove_file(const QString &fileName)
Deletes the specified file.
MUTILS_API void natural_string_sort(QStringList &list, const bool bIgnoreCase)
Sort a list of strings using "natural ordering" algorithm.
MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value)
Parse regular expression results.
MUTILS_API QString clean_file_name(const QString &name)
Clean up a file name string.
MUTILS_API bool parity(quint32 value)
Computes the parity of the given unsigned 32-Bit value.
MUTILS_API quint64 next_rand_u64(void)
Generates a random unsigned 64-Bit value.
MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir=true, const QStringList *const extraPaths=NULL)
Initialize a given QProcess object.
MUTILS_API QString & trim_right(QString &str)
Remove trailing white-space characters.
MUTILS_API const QString & temp_folder(void)
Rerieves the full path of the application&#39;s Temp folder.
Definition: CPUFeatures.h:30
MUTILS_API quint32 next_rand_u32(void)
Generates a random unsigned 32-Bit value.
MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy=false)
Generates a unique file name.
MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive)
Recursively deletes the specified directory.
MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder=false)
Generates a temporary file name.
MUTILS_API QString & trim_left(QString &str)
Remove leading white-space characters.
MUTILS_API QString clean_file_path(const QString &path)
Clean up a file path string.