1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
26 //Forward Declarations
29 ///////////////////////////////////////////////////////////////////////////////
33 # ifdef MUTILS_DLL_EXPORT
34 # define MUTILS_API __declspec(dllexport)
36 # ifndef MUTILS_STATIC_LIB
37 # define MUTILS_API __declspec(dllimport)
39 # define MUTILS_API /*static lib*/
47 #define MUTILS_MAKE_STRING_HELPER(X) #X
48 #define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
49 #define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
52 #if defined(_DEBUG) || defined(DEBUG) || (!defined(NDEBUG))
53 # define MUTILS_DEBUG (1)
54 # if defined(NDEBUG) || defined(QT_NO_DEBUG) || (!defined(QT_DEBUG))
55 # error Inconsistent DEBUG flags have been detected!
58 # define MUTILS_DEBUG (0)
59 # if (!defined(NDEBUG)) || (!defined(QT_NO_DEBUG)) || defined(QT_DEBUG)
60 # error Inconsistent DEBUG flags have been detected!
65 #if defined(_MSC_VER) && (!defined(__INTELLISENSE__)) && (!defined(_M_X64)) && defined(_M_IX86_FP)
67 #error We should not enabled SSE or SSE2 in release builds!
71 ///////////////////////////////////////////////////////////////////////////////
76 MUTILS_API
const QString
& temp_folder(void);
79 MUTILS_API
void init_process(QProcess
&process
, const QString
&wokringDir
, const bool bReplaceTempDir
= true, const QStringList
*const extraPaths
= NULL
);
82 MUTILS_API
void seed_rand(void);
83 MUTILS_API QString
next_rand_str(const bool &bLong
= false);
84 MUTILS_API quint32
next_rand_u32(void);
85 MUTILS_API quint64
next_rand_u64(void);
88 MUTILS_API QString
make_temp_file(const QString
&basePath
, const QString
&extension
, const bool placeholder
= false);
89 MUTILS_API QString
make_unique_file(const QString
&basePath
, const QString
&baseName
, const QString
&extension
, const bool fancy
= false);
92 MUTILS_API
bool parity(quint32 value
);
95 MUTILS_API
bool remove_file(const QString
&fileName
);
96 MUTILS_API
bool remove_directory(const QString
&folderPath
, const bool &recursive
);
99 MUTILS_API QString
& trim_right(QString
&str
);
100 MUTILS_API QString
& trim_left(QString
&str
);
101 MUTILS_API QString
trim_right(const QString
&str
);
102 MUTILS_API QString
trim_left(const QString
&str
);
105 MUTILS_API
void natural_string_sort(QStringList
&list
, const bool bIgnoreCase
);
108 MUTILS_API QString
clean_file_name(const QString
&name
);
109 MUTILS_API QString
clean_file_path(const QString
&path
);
111 //Regular expressions
112 MUTILS_API
bool regexp_parse_uint32(const QRegExp
®exp
, quint32
&value
);
113 MUTILS_API
bool regexp_parse_uint32(const QRegExp
®exp
, quint32
*values
, const size_t &count
);
115 //Internationalization
116 MUTILS_API QStringList
available_codepages(const bool &noAliases
= true);
121 MUTILS_API
int selfTest(const char *const buildKey
, const bool debug
);
122 static const int s_selfTest
= selfTest(__DATE__
"@" __TIME__
, MUTILS_DEBUG
);
126 ///////////////////////////////////////////////////////////////////////////////
129 #define MUTILS_DELETE(PTR) do { if((PTR)) { delete (PTR); (PTR) = NULL; } } while(0)
130 #define MUTILS_DELETE_ARRAY(PTR) do { if((PTR)) { delete [] (PTR); (PTR) = NULL; } } while(0)
133 #define MUTILS_ZERO_MEMORY(PTR) memset(&(PTR), 0, sizeof((PTR)))
135 //String conversion macros
136 #define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
137 #define MUTILS_UTF8(STR) ((STR).toUtf8().constData())
138 #define MUTILS_QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
141 #define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")