From 7b01ea510b1c53b05ebcb4326b9e61d7ceead7c6 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 10 May 2019 23:20:50 +0200 Subject: [PATCH] Some improvements to library initialization code. --- docs/d2/dad/_hash_8h_source.html | 2 +- docs/d2/df4/namespace_m_utils_1_1_o_s.html | 12 +++++------ docs/d3/dc1/_o_s_support_8h.html | 12 +++++------ docs/d3/dc1/_o_s_support_8h_source.html | 2 +- docs/d4/d85/_job_object_8h_source.html | 2 +- docs/d5/d3b/_global_8h_source.html | 4 ++-- include/MUtils/Global.h | 23 ++++++++++++++++------ src/Global.cpp | 17 ++++++++-------- 8 files changed, 43 insertions(+), 31 deletions(-) diff --git a/docs/d2/dad/_hash_8h_source.html b/docs/d2/dad/_hash_8h_source.html index c766025..e2b95ce 100644 --- a/docs/d2/dad/_hash_8h_source.html +++ b/docs/d2/dad/_hash_8h_source.html @@ -73,7 +73,7 @@ $(function() {
static const quint16 HASH_BLAKE2_512
Hash algorithm identifier.
Definition: Hash.h:42
static const quint16 HASH_KECCAK_384
Hash algorithm identifier.
Definition: Hash.h:45
Global MUtils namespace.
Definition: CPUFeatures.h:37
-
#define MUTILS_NO_COPY(CLASS)
Disables copy constructor and assignment operator in the specified class. This macro should be used i...
Definition: Global.h:405
+
#define MUTILS_NO_COPY(CLASS)
Disables copy constructor and assignment operator in the specified class. This macro should be used i...
Definition: Global.h:416
MUTILS_API Hash * create(const quint16 &hashId, const char *const key=NULL)
Create instance of a hash function.
This abstract class specifies the generic interface for all support hash algorithms.
Definition: Hash.h:57
static const quint16 HASH_KECCAK_256
Hash algorithm identifier.
Definition: Hash.h:44
diff --git a/docs/d2/df4/namespace_m_utils_1_1_o_s.html b/docs/d2/df4/namespace_m_utils_1_1_o_s.html index 53ff670..b70822d 100644 --- a/docs/d2/df4/namespace_m_utils_1_1_o_s.html +++ b/docs/d2/df4/namespace_m_utils_1_1_o_s.html @@ -249,12 +249,12 @@ MUTILS_API void shell_chan MUTILS_API QString get_file_path (const int &fd)   - -MUTILS_API bool wow64fsredir_disable (void *oldValue) -  - -MUTILS_API bool wow64fsredir_revert (void *oldValue) -  + +MUTILS_API bool wow64fsredir_disable (uintptr_t &oldValue) +  + +MUTILS_API bool wow64fsredir_revert (const uintptr_t oldValue) +  MUTILS_API QString get_envvar (const QString &name)   diff --git a/docs/d3/dc1/_o_s_support_8h.html b/docs/d3/dc1/_o_s_support_8h.html index cc75f9b..11e9f18 100644 --- a/docs/d3/dc1/_o_s_support_8h.html +++ b/docs/d3/dc1/_o_s_support_8h.html @@ -279,12 +279,12 @@ MUTILS_API void MUtils::OS MUTILS_API QString MUtils::OS::get_file_path (const int &fd)   - -MUTILS_API bool MUtils::OS::wow64fsredir_disable (void *oldValue) -  - -MUTILS_API bool MUtils::OS::wow64fsredir_revert (void *oldValue) -  + +MUTILS_API bool MUtils::OS::wow64fsredir_disable (uintptr_t &oldValue) +  + +MUTILS_API bool MUtils::OS::wow64fsredir_revert (const uintptr_t oldValue) +  MUTILS_API QString MUtils::OS::get_envvar (const QString &name)   diff --git a/docs/d3/dc1/_o_s_support_8h_source.html b/docs/d3/dc1/_o_s_support_8h_source.html index ad12ac0..1f91198 100644 --- a/docs/d3/dc1/_o_s_support_8h_source.html +++ b/docs/d3/dc1/_o_s_support_8h_source.html @@ -67,7 +67,7 @@ $(function() {
OSSupport.h
-Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2019 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 //MUtils
30 #include <MUtils/Global.h>
31 
32 //Qt
33 #include <QString>
34 #include <QMap>
35 #include <QDate>
36 #include <QWidget>
37 
38 //Forward declaration
39 class QFile;
40 
42 
46 namespace MUtils
47 {
51  namespace OS
52  {
56  namespace Version
57  {
61  typedef enum
62  {
63  OS_UNKNOWN = 0,
65  }
66  os_type_t;
67 
71  typedef struct _os_version_t
72  {
73  unsigned int type;
74  unsigned int versionMajor;
75  unsigned int versionMinor;
76  unsigned int versionBuild;
77  unsigned int versionSPack;
78  bool overrideFlag;
79 
80  MUTILS_API bool operator== (const _os_version_t &rhs) const;
81  MUTILS_API bool operator!= (const _os_version_t &rhs) const;
82  MUTILS_API bool operator> (const _os_version_t &rhs) const;
83  MUTILS_API bool operator>= (const _os_version_t &rhs) const;
84  MUTILS_API bool operator< (const _os_version_t &rhs) const;
85  MUTILS_API bool operator<= (const _os_version_t &rhs) const;
86  }
88 
89  //Known Windows NT versions
90  MUTILS_API extern const os_version_t WINDOWS_WIN2K;
91  MUTILS_API extern const os_version_t WINDOWS_WINXP;
92  MUTILS_API extern const os_version_t WINDOWS_XPX64;
93  MUTILS_API extern const os_version_t WINDOWS_VISTA;
94  MUTILS_API extern const os_version_t WINDOWS_WIN70;
95  MUTILS_API extern const os_version_t WINDOWS_WIN80;
96  MUTILS_API extern const os_version_t WINDOWS_WIN81;
97  MUTILS_API extern const os_version_t WINDOWS_WN100;
98 
99  //Unknown OS
100  MUTILS_API extern const os_version_t UNKNOWN_OPSYS;
101  }
102 
106  typedef enum
107  {
114  }
116 
120  typedef enum
121  {
125  }
127 
131  typedef enum
132  {
139  }
140  drive_type_t;
141 
142  //System message
143  MUTILS_API void system_message_nfo(const wchar_t *const title, const wchar_t *const text);
144  MUTILS_API void system_message_wrn(const wchar_t *const title, const wchar_t *const text);
145  MUTILS_API void system_message_err(const wchar_t *const title, const wchar_t *const text);
146 
147  //CLI Arguments
148  typedef QMap<QString,QString> ArgumentMap;
149  MUTILS_API const QStringList crack_command_line(const QString &command_line = QString());
150  MUTILS_API const ArgumentMap &arguments(void);
151 
152  //Copy file
153  typedef bool (*progress_callback_t)(const double &progress, void *const userData);
154  MUTILS_API bool copy_file(const QString &sourcePath, const QString &outputPath, const bool &overwrite = true, const progress_callback_t callback = NULL, void *const userData = NULL);
155 
156  //Get file version
157  MUTILS_API bool get_file_version(const QString fileName, quint16 *const major = NULL, quint16 *const minor = NULL, quint16 *const patch = NULL, quint16 *const build = NULL);
158 
159  //Get the OS version
160  MUTILS_API const Version::os_version_t &os_version(void);
161  MUTILS_API const char *os_friendly_name(const MUtils::OS::Version::os_version_t &os_version);
162  MUTILS_API const bool &running_on_wine(void);
163 
164  //Get known Folder
165  MUTILS_API const QString &known_folder(known_folder_t folder_id);
166 
167  //Current Date & Time
168  MUTILS_API QDate current_date(void);
169  MUTILS_API quint64 current_file_time(void);
170 
171  //Check for process elevation
172  MUTILS_API bool is_elevated(bool *bIsUacEnabled = NULL);
173  MUTILS_API bool user_is_admin(void);
174 
182  MUTILS_API int network_status(void);
183 
184  //Message handler
185  MUTILS_API bool handle_os_message(const void *const message, long *result);
186 
196  MUTILS_API void sleep_ms(const size_t &duration);
197 
198  //Is executable/library file?
199  MUTILS_API bool is_executable_file(const QString &path);
200  MUTILS_API bool is_library_file(const QString &path);
201 
202  //Shutdown & Hibernation
203  MUTILS_API bool is_hibernation_supported(void);
204  MUTILS_API bool shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown, const bool hibernate);
205 
206  //Free diskspace
207  MUTILS_API bool free_diskspace(const QString &path, quint64 &freeSpace);
208 
220  MUTILS_API drive_type_t get_drive_type(const QString &path, bool *fast_seeking = NULL);
221 
222  //Shell open
223  MUTILS_API bool shell_open(const QWidget *parent, const QString &url, const bool explore = false);
224  MUTILS_API bool shell_open(const QWidget *parent, const QString &url, const QString &parameters, const QString &directory, const bool explore = false);
225 
226  //Open media file
227  MUTILS_API bool open_media_file(const QString &mediaFilePath);
228 
229  //Process priority
230  MUTILS_API bool change_process_priority(const int priority);
231  MUTILS_API bool change_process_priority(const QProcess *proc, const int priority);
232 
233  //Process ID
234  MUTILS_API quint32 process_id(void);
235  MUTILS_API quint32 process_id(const QProcess *const proc);
236 
237  //Thread ID
238  MUTILS_API quint32 thread_id(void);
239  MUTILS_API quint32 thread_id(const QProcess *const proc);
240 
241  //Suspend or resume processv
242  MUTILS_API bool suspend_process(const QProcess *proc, const bool suspend);
243 
244  //System timer resolution
245  MUTILS_API bool setup_timer_resolution(const quint32 &interval = 1);
246  MUTILS_API bool reset_timer_resolution(const quint32 &interval = 1);
247 
248  //Set file time
249  MUTILS_API bool set_file_time(const QFile &file, const QDateTime &created = QDateTime(), const QDateTime &modified = QDateTime(), const QDateTime &accessed = QDateTime());
250  MUTILS_API bool set_file_time(const QString &path, const QDateTime &created = QDateTime(), const QDateTime &modified = QDateTime(), const QDateTime &accessed = QDateTime());
251 
252  //Keyboard support
253  MUTILS_API bool check_key_state_esc(void);
254 
255  //Shell notification
256  MUTILS_API void shell_change_notification(void);
257 
258  //Get file path from descriptor
259  MUTILS_API QString get_file_path(const int &fd);
260 
261  //WOW64 redirection
262  MUTILS_API bool wow64fsredir_disable(void *oldValue);
263  MUTILS_API bool wow64fsredir_revert (void *oldValue);
264 
265  //Environment variables
266  MUTILS_API QString get_envvar(const QString &name);
267  MUTILS_API bool set_envvar(const QString &name, const QString &value);
268 
269  //NULL device
270  MUTILS_API const QLatin1String &null_device(void);
271 
272  //Check if debugger is present
273  MUTILS_API void check_debugger(void);
274 
275  //Error handling
276  MUTILS_API void fatal_exit(const wchar_t* const errorMessage);
277  }
278 }
279 
MUTILS_API int network_status(void)
Check the network status.
+Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2019 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 //MUtils
30 #include <MUtils/Global.h>
31 
32 //Qt
33 #include <QString>
34 #include <QMap>
35 #include <QDate>
36 #include <QWidget>
37 
38 //Forward declaration
39 class QFile;
40 
42 
46 namespace MUtils
47 {
51  namespace OS
52  {
56  namespace Version
57  {
61  typedef enum
62  {
63  OS_UNKNOWN = 0,
65  }
66  os_type_t;
67 
71  typedef struct _os_version_t
72  {
73  unsigned int type;
74  unsigned int versionMajor;
75  unsigned int versionMinor;
76  unsigned int versionBuild;
77  unsigned int versionSPack;
78  bool overrideFlag;
79 
80  MUTILS_API bool operator== (const _os_version_t &rhs) const;
81  MUTILS_API bool operator!= (const _os_version_t &rhs) const;
82  MUTILS_API bool operator> (const _os_version_t &rhs) const;
83  MUTILS_API bool operator>= (const _os_version_t &rhs) const;
84  MUTILS_API bool operator< (const _os_version_t &rhs) const;
85  MUTILS_API bool operator<= (const _os_version_t &rhs) const;
86  }
88 
89  //Known Windows NT versions
90  MUTILS_API extern const os_version_t WINDOWS_WIN2K;
91  MUTILS_API extern const os_version_t WINDOWS_WINXP;
92  MUTILS_API extern const os_version_t WINDOWS_XPX64;
93  MUTILS_API extern const os_version_t WINDOWS_VISTA;
94  MUTILS_API extern const os_version_t WINDOWS_WIN70;
95  MUTILS_API extern const os_version_t WINDOWS_WIN80;
96  MUTILS_API extern const os_version_t WINDOWS_WIN81;
97  MUTILS_API extern const os_version_t WINDOWS_WN100;
98 
99  //Unknown OS
100  MUTILS_API extern const os_version_t UNKNOWN_OPSYS;
101  }
102 
106  typedef enum
107  {
114  }
116 
120  typedef enum
121  {
125  }
127 
131  typedef enum
132  {
139  }
140  drive_type_t;
141 
142  //System message
143  MUTILS_API void system_message_nfo(const wchar_t *const title, const wchar_t *const text);
144  MUTILS_API void system_message_wrn(const wchar_t *const title, const wchar_t *const text);
145  MUTILS_API void system_message_err(const wchar_t *const title, const wchar_t *const text);
146 
147  //CLI Arguments
148  typedef QMap<QString,QString> ArgumentMap;
149  MUTILS_API const QStringList crack_command_line(const QString &command_line = QString());
150  MUTILS_API const ArgumentMap &arguments(void);
151 
152  //Copy file
153  typedef bool (*progress_callback_t)(const double &progress, void *const userData);
154  MUTILS_API bool copy_file(const QString &sourcePath, const QString &outputPath, const bool &overwrite = true, const progress_callback_t callback = NULL, void *const userData = NULL);
155 
156  //Get file version
157  MUTILS_API bool get_file_version(const QString fileName, quint16 *const major = NULL, quint16 *const minor = NULL, quint16 *const patch = NULL, quint16 *const build = NULL);
158 
159  //Get the OS version
160  MUTILS_API const Version::os_version_t &os_version(void);
161  MUTILS_API const char *os_friendly_name(const MUtils::OS::Version::os_version_t &os_version);
162  MUTILS_API const bool &running_on_wine(void);
163 
164  //Get known Folder
165  MUTILS_API const QString &known_folder(known_folder_t folder_id);
166 
167  //Current Date & Time
168  MUTILS_API QDate current_date(void);
169  MUTILS_API quint64 current_file_time(void);
170 
171  //Check for process elevation
172  MUTILS_API bool is_elevated(bool *bIsUacEnabled = NULL);
173  MUTILS_API bool user_is_admin(void);
174 
182  MUTILS_API int network_status(void);
183 
184  //Message handler
185  MUTILS_API bool handle_os_message(const void *const message, long *result);
186 
196  MUTILS_API void sleep_ms(const size_t &duration);
197 
198  //Is executable/library file?
199  MUTILS_API bool is_executable_file(const QString &path);
200  MUTILS_API bool is_library_file(const QString &path);
201 
202  //Shutdown & Hibernation
203  MUTILS_API bool is_hibernation_supported(void);
204  MUTILS_API bool shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown, const bool hibernate);
205 
206  //Free diskspace
207  MUTILS_API bool free_diskspace(const QString &path, quint64 &freeSpace);
208 
220  MUTILS_API drive_type_t get_drive_type(const QString &path, bool *fast_seeking = NULL);
221 
222  //Shell open
223  MUTILS_API bool shell_open(const QWidget *parent, const QString &url, const bool explore = false);
224  MUTILS_API bool shell_open(const QWidget *parent, const QString &url, const QString &parameters, const QString &directory, const bool explore = false);
225 
226  //Open media file
227  MUTILS_API bool open_media_file(const QString &mediaFilePath);
228 
229  //Process priority
230  MUTILS_API bool change_process_priority(const int priority);
231  MUTILS_API bool change_process_priority(const QProcess *proc, const int priority);
232 
233  //Process ID
234  MUTILS_API quint32 process_id(void);
235  MUTILS_API quint32 process_id(const QProcess *const proc);
236 
237  //Thread ID
238  MUTILS_API quint32 thread_id(void);
239  MUTILS_API quint32 thread_id(const QProcess *const proc);
240 
241  //Suspend or resume processv
242  MUTILS_API bool suspend_process(const QProcess *proc, const bool suspend);
243 
244  //System timer resolution
245  MUTILS_API bool setup_timer_resolution(const quint32 &interval = 1);
246  MUTILS_API bool reset_timer_resolution(const quint32 &interval = 1);
247 
248  //Set file time
249  MUTILS_API bool set_file_time(const QFile &file, const QDateTime &created = QDateTime(), const QDateTime &modified = QDateTime(), const QDateTime &accessed = QDateTime());
250  MUTILS_API bool set_file_time(const QString &path, const QDateTime &created = QDateTime(), const QDateTime &modified = QDateTime(), const QDateTime &accessed = QDateTime());
251 
252  //Keyboard support
253  MUTILS_API bool check_key_state_esc(void);
254 
255  //Shell notification
256  MUTILS_API void shell_change_notification(void);
257 
258  //Get file path from descriptor
259  MUTILS_API QString get_file_path(const int &fd);
260 
261  //WOW64 redirection
262  MUTILS_API bool wow64fsredir_disable(uintptr_t &oldValue);
263  MUTILS_API bool wow64fsredir_revert (const uintptr_t oldValue);
264 
265  //Environment variables
266  MUTILS_API QString get_envvar(const QString &name);
267  MUTILS_API bool set_envvar(const QString &name, const QString &value);
268 
269  //NULL device
270  MUTILS_API const QLatin1String &null_device(void);
271 
272  //Check if debugger is present
273  MUTILS_API void check_debugger(void);
274 
275  //Error handling
276  MUTILS_API void fatal_exit(const wchar_t* const errorMessage);
277  }
278 }
279 
MUTILS_API int network_status(void)
Check the network status.
MUTILS_API const os_version_t UNKNOWN_OPSYS
Operating system version constant.
Local application data (non-roaming)
Definition: OSSupport.h:109
unsigned int versionMinor
The minor version of the underlaying operating system.
Definition: OSSupport.h:75
diff --git a/docs/d4/d85/_job_object_8h_source.html b/docs/d4/d85/_job_object_8h_source.html index a299102..ea186dc 100644 --- a/docs/d4/d85/_job_object_8h_source.html +++ b/docs/d4/d85/_job_object_8h_source.html @@ -70,7 +70,7 @@ $(function() { Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2019 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 
31 #pragma once
32 
33 #include <MUtils/Global.h>
34 
35 class QProcess;
36 
37 namespace MUtils
38 {
46  class MUTILS_API JobObject
47  {
48  public:
54  JobObject(void);
55 
61  ~JobObject(void);
62 
70  bool isObjectCreated(void);
71 
81  bool addProcessToJob(const QProcess *const process);
82 
92  bool terminateJob(const quint32 &exitCode);
93 
94  private:
95  uintptr_t m_jobPtr;
97  };
98 }
This file contains miscellaneous functions that are generally useful for Qt-based applications...
This class represents a job object.
Definition: JobObject.h:46
Global MUtils namespace.
Definition: CPUFeatures.h:37
-
#define MUTILS_NO_COPY(CLASS)
Disables copy constructor and assignment operator in the specified class. This macro should be used i...
Definition: Global.h:405
+
#define MUTILS_NO_COPY(CLASS)
Disables copy constructor and assignment operator in the specified class. This macro should be used i...
Definition: Global.h:416
-Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2019 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 class QDir;
34 template<typename K, typename V> class QHash;
35 
37 
41 //MUtils API
42 #ifdef _MSC_VER
43 # ifdef MUTILS_DLL_EXPORT
44 # define MUTILS_API __declspec(dllexport)
45 # else
46 # ifndef MUTILS_STATIC_LIB
47 # define MUTILS_API __declspec(dllimport)
48 # else
49 # define MUTILS_API /*static lib*/
50 # endif
51 # endif
52 #else
53 # define MUTILS_API
54 #endif
55 
56 #define MUTILS_MAKE_STRING_HELPER(X) #X
57 #define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
58 #define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
59 
60 //Check Debug Flags
61 #if defined(_DEBUG) || defined(DEBUG) || (!defined(NDEBUG))
62 # define MUTILS_DEBUG (1)
63 # if defined(NDEBUG) || defined(QT_NO_DEBUG) || (!defined(QT_DEBUG))
64 # error Inconsistent DEBUG flags have been detected!
65 # endif
66 #else
67 # define MUTILS_DEBUG (0)
68 # if (!defined(NDEBUG)) || (!defined(QT_NO_DEBUG)) || defined(QT_DEBUG)
69 # error Inconsistent DEBUG flags have been detected!
70 # endif
71 #endif
72 
73 //Check CPU options
74 #if defined(_MSC_VER) && (!defined(__INTELLISENSE__)) && (!defined(_M_X64)) && defined(_M_IX86_FP)
75  #if (_M_IX86_FP != 0)
76  #error We should not enabled SSE or SSE2 in release builds!
77  #endif
78 #endif
79 
83 
88 namespace MUtils
89 {
93  typedef struct _fp_parts_t { double parts[2]; } fp_parts_t;
94 
102  MUTILS_API const QString& temp_folder(void);
103 
117  MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true, const QStringList *const extraPaths = NULL, const QHash<QString, QString> *const extraEnv = NULL);
118 
126  MUTILS_API quint32 next_rand_u32(void);
127  MUTILS_API quint32 next_rand_u32(const quint32 max);
128 
136  MUTILS_API quint64 next_rand_u64(void);
137 
147  MUTILS_API QString next_rand_str(const bool &bLong = false);
148 
162  MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
163  MUTILS_API QString make_temp_file(const QDir &basePath, const QString &extension, const bool placeholder = false);
164 
180  MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy = false, const bool placeholder = false);
181  MUTILS_API QString make_unique_file(const QDir &basePath, const QString &baseName, const QString &extension, const bool fancy = false, const bool placeholder = false);
182 
190  MUTILS_API bool parity(quint32 value);
191 
201  MUTILS_API bool remove_file(const QString &fileName);
202 
214  MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive);
215 
225  MUTILS_API QString& trim_right(QString &str);
226 
236  MUTILS_API QString& trim_left(QString &str);
237 
247  MUTILS_API QString trim_right(const QString &str);
248 
258  MUTILS_API QString trim_left(const QString &str);
259 
269  MUTILS_API void natural_string_sort(QStringList &list, const bool bIgnoreCase);
270 
282  MUTILS_API QString clean_file_name(const QString &name, const bool &pretty);
283 
295  MUTILS_API QString clean_file_path(const QString &path, const bool &pretty);
296 
308  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value);
309  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 &value);
310  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value, const size_t &offset);
311  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 &value, const size_t &offset);
312 
326  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count);
327  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 *values, const size_t &count);
328  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &offset, const size_t &count);
329  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 *values, const size_t &offset, const size_t &count);
330 
340  MUTILS_API QStringList available_codepages(const bool &noAliases = true);
341 
351  MUTILS_API fp_parts_t break_fp(const double value);
352 
353  //Internal
354  namespace Internal
355  {
356  MUTILS_API int selfTest(const char *const buildKey, const bool debug);
357  static const int s_selfTest = selfTest(__DATE__ "@" __TIME__, MUTILS_DEBUG);
358  }
359 }
360 
362 
365 #define MUTILS_DELETE(PTR) do { if((PTR)) { delete (PTR); (PTR) = NULL; } } while(0)
366 
369 #define MUTILS_DELETE_ARRAY(PTR) do { if((PTR)) { delete [] (PTR); (PTR) = NULL; } } while(0)
370 
373 #define MUTILS_ZERO_MEMORY(PTR) memset(&(PTR), 0, sizeof((PTR)))
374 
377 #define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
378 
381 #define MUTILS_UTF8(STR) ((STR).toUtf8().constData())
382 
385 #define MUTILS_L1STR(STR) ((STR).toLatin1().constData())
386 
389 #define MUTILS_QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
390 
393 #define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")
394 
397 #define MUTILS_BOOLIFY(X) (!(!(X)))
398 
401 #define MUTILS_ARR2LEN(X) (sizeof((X)) / sizeof((X)[0]))
402 
405 #define MUTILS_NO_COPY(CLASS) \
406  CLASS(const CLASS &) { throw "Copy constructor is disabled!"; } \
407  CLASS &operator=(const CLASS &) { throw "Assignment operator is disabled!"; }
MUTILS_API QStringList available_codepages(const bool &noAliases=true)
Retrieve a list of all available codepages.
+Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2019 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 class QDir;
34 template<typename K, typename V> class QHash;
35 
37 
41  //Interface version
42 #define MUTILS_INTERFACE 2
43 
44 //Build key
45 #define MUTILS_BUILD_KEY_HELPER(X,Y) X##" "##Y
46 #define MUTILS_BUILD_KEY MUTILS_BUILD_KEY_HELPER(__DATE__, __TIME__)
47 
48 //MUtils API
49 #ifdef _MSC_VER
50 # ifdef MUTILS_DLL_EXPORT
51 # define MUTILS_API __declspec(dllexport)
52 # else
53 # ifndef MUTILS_STATIC_LIB
54 # define MUTILS_API __declspec(dllimport)
55 # else
56 # define MUTILS_API /*static lib*/
57 # endif
58 # endif
59 #else
60 # define MUTILS_API
61 #endif
62 
63 //Check Debug Flags
64 #if defined(_DEBUG) || defined(DEBUG) || (!defined(NDEBUG))
65 # define MUTILS_DEBUG (1)
66 # if defined(NDEBUG) || defined(QT_NO_DEBUG) || (!defined(QT_DEBUG))
67 # error Inconsistent DEBUG flags have been detected!
68 # endif
69 #else
70 # define MUTILS_DEBUG (0)
71 # if (!defined(NDEBUG)) || (!defined(QT_NO_DEBUG)) || defined(QT_DEBUG)
72 # error Inconsistent DEBUG flags have been detected!
73 # endif
74 #endif
75 
76 //Check CPU options
77 #if defined(_MSC_VER) && (!defined(__INTELLISENSE__)) && (!defined(_M_X64)) && defined(_M_IX86_FP)
78  #if (_M_IX86_FP != 0)
79  #error We should not enabled SSE or SSE2 in release builds!
80  #endif
81 #endif
82 
83 #define MUTILS_MAKE_STRING_HELPER(X) #X
84 #define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X)
85 #define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT))
86 
87 #define MUTILS_INIT_GLUE_HELPER(X,Y) X##Y
88 #define MUTILS_INIT_GLUE(X,Y) MUTILS_INIT_GLUE_HELPER(X,Y)
89 #define MUTILS_INITIALIZER MUTILS_INIT_GLUE(initialize_, MUTILS_INTERFACE)
90 
94 
99 namespace MUtils
100 {
104  typedef struct _fp_parts_t { double parts[2]; } fp_parts_t;
105 
113  MUTILS_API const QString& temp_folder(void);
114 
128  MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true, const QStringList *const extraPaths = NULL, const QHash<QString, QString> *const extraEnv = NULL);
129 
137  MUTILS_API quint32 next_rand_u32(void);
138  MUTILS_API quint32 next_rand_u32(const quint32 max);
139 
147  MUTILS_API quint64 next_rand_u64(void);
148 
158  MUTILS_API QString next_rand_str(const bool &bLong = false);
159 
173  MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
174  MUTILS_API QString make_temp_file(const QDir &basePath, const QString &extension, const bool placeholder = false);
175 
191  MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy = false, const bool placeholder = false);
192  MUTILS_API QString make_unique_file(const QDir &basePath, const QString &baseName, const QString &extension, const bool fancy = false, const bool placeholder = false);
193 
201  MUTILS_API bool parity(quint32 value);
202 
212  MUTILS_API bool remove_file(const QString &fileName);
213 
225  MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive);
226 
236  MUTILS_API QString& trim_right(QString &str);
237 
247  MUTILS_API QString& trim_left(QString &str);
248 
258  MUTILS_API QString trim_right(const QString &str);
259 
269  MUTILS_API QString trim_left(const QString &str);
270 
280  MUTILS_API void natural_string_sort(QStringList &list, const bool bIgnoreCase);
281 
293  MUTILS_API QString clean_file_name(const QString &name, const bool &pretty);
294 
306  MUTILS_API QString clean_file_path(const QString &path, const bool &pretty);
307 
319  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value);
320  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 &value);
321  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 &value, const size_t &offset);
322  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 &value, const size_t &offset);
323 
337  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &count);
338  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 *values, const size_t &count);
339  MUTILS_API bool regexp_parse_uint32(const QRegExp &regexp, quint32 *values, const size_t &offset, const size_t &count);
340  MUTILS_API bool regexp_parse_int32(const QRegExp &regexp, qint32 *values, const size_t &offset, const size_t &count);
341 
351  MUTILS_API QStringList available_codepages(const bool &noAliases = true);
352 
362  MUTILS_API fp_parts_t break_fp(const double value);
363 
364  //Internal
365  namespace Internal
366  {
367  MUTILS_API int MUTILS_INITIALIZER(const char *const buildKey, const bool debug);
368  static const int s_initializedFlag = MUTILS_INITIALIZER(MUTILS_BUILD_KEY, MUTILS_DEBUG);
369  }
370 }
371 
373 
376 #define MUTILS_DELETE(PTR) do { if((PTR)) { delete (PTR); (PTR) = NULL; } } while(0)
377 
380 #define MUTILS_DELETE_ARRAY(PTR) do { if((PTR)) { delete [] (PTR); (PTR) = NULL; } } while(0)
381 
384 #define MUTILS_ZERO_MEMORY(PTR) memset(&(PTR), 0, sizeof((PTR)))
385 
388 #define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
389 
392 #define MUTILS_UTF8(STR) ((STR).toUtf8().constData())
393 
396 #define MUTILS_L1STR(STR) ((STR).toLatin1().constData())
397 
400 #define MUTILS_QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
401 
404 #define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")
405 
408 #define MUTILS_BOOLIFY(X) (!(!(X)))
409 
412 #define MUTILS_ARR2LEN(X) (sizeof((X)) / sizeof((X)[0]))
413 
416 #define MUTILS_NO_COPY(CLASS) \
417  CLASS(const CLASS &) { throw "Copy constructor is disabled!"; } \
418  CLASS &operator=(const CLASS &) { throw "Assignment operator is disabled!"; }
MUTILS_API QStringList available_codepages(const bool &noAliases=true)
Retrieve a list of all available codepages.
struct MUtils::_fp_parts_t fp_parts_t
This struct containes the parts (integral and fractional part) of a floating-point number...
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 QString clean_file_path(const QString &path, const bool &pretty)
Clean up a file path string.
-
This struct containes the parts (integral and fractional part) of a floating-point number...
Definition: Global.h:93
+
This struct containes the parts (integral and fractional part) of a floating-point number...
Definition: Global.h:104
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 bool parity(quint32 value)
Computes the parity of the given unsigned 32-Bit value.
diff --git a/include/MUtils/Global.h b/include/MUtils/Global.h index 48ea302..c56d8f1 100644 --- a/include/MUtils/Global.h +++ b/include/MUtils/Global.h @@ -38,6 +38,13 @@ template class QHash; /** \cond INTERNAL */ + //Interface version +#define MUTILS_INTERFACE 2 + +//Build key +#define MUTILS_BUILD_KEY_HELPER(X,Y) X##" "##Y +#define MUTILS_BUILD_KEY MUTILS_BUILD_KEY_HELPER(__DATE__, __TIME__) + //MUtils API #ifdef _MSC_VER # ifdef MUTILS_DLL_EXPORT @@ -53,10 +60,6 @@ template class QHash; # define MUTILS_API #endif -#define MUTILS_MAKE_STRING_HELPER(X) #X -#define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X) -#define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT)) - //Check Debug Flags #if defined(_DEBUG) || defined(DEBUG) || (!defined(NDEBUG)) # define MUTILS_DEBUG (1) @@ -77,6 +80,14 @@ template class QHash; #endif #endif +#define MUTILS_MAKE_STRING_HELPER(X) #X +#define MUTILS_MAKE_STRING(X) MUTILS_MAKE_STRING_HELPER(X) +#define MUTILS_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" MUTILS_MAKE_STRING(__LINE__) ") : warning: " TXT)) + +#define MUTILS_INIT_GLUE_HELPER(X,Y) X##Y +#define MUTILS_INIT_GLUE(X,Y) MUTILS_INIT_GLUE_HELPER(X,Y) +#define MUTILS_INITIALIZER MUTILS_INIT_GLUE(initialize_, MUTILS_INTERFACE) + /** \endcond INTERNAL */ @@ -353,8 +364,8 @@ namespace MUtils //Internal namespace Internal { - MUTILS_API int selfTest(const char *const buildKey, const bool debug); - static const int s_selfTest = selfTest(__DATE__ "@" __TIME__, MUTILS_DEBUG); + MUTILS_API int MUTILS_INITIALIZER(const char *const buildKey, const bool debug); + static const int s_initializedFlag = MUTILS_INITIALIZER(MUTILS_BUILD_KEY, MUTILS_DEBUG); } } diff --git a/src/Global.cpp b/src/Global.cpp index 056d213..da1dc7d 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -902,19 +902,20 @@ MUtils::fp_parts_t MUtils::break_fp(const double value) } /////////////////////////////////////////////////////////////////////////////// -// SELF-TEST +// INITIALIZER /////////////////////////////////////////////////////////////////////////////// -int MUtils::Internal::selfTest(const char *const buildKey, const bool debug) +int MUtils::Internal::MUTILS_INITIALIZER(const char *const buildKey, const bool debug) { - static const bool MY_DEBUG_FLAG = MUTILS_DEBUG; - static const char *const MY_BUILD_KEY = __DATE__ "@" __TIME__; + static const bool INTERNAL_DEBUG_FLAG = MUTILS_DEBUG; + static const char *const INTERNAL_BUILD_KEY = MUTILS_BUILD_KEY; - if(strncmp(buildKey, MY_BUILD_KEY, 13) || (MY_DEBUG_FLAG != debug)) + if((debug != INTERNAL_DEBUG_FLAG) || strncmp(buildKey, INTERNAL_BUILD_KEY, 11)) { - MUtils::OS::system_message_err(L"MUtils", L"FATAL ERROR: MUtils library version mismatch detected!"); - MUtils::OS::system_message_wrn(L"MUtils", L"Perform a clean(!) re-install of the application to fix the problem!"); + MUtils::OS::system_message_err(L"MUtils", L"FATAL ERROR: MUtils library initialization has failed"); abort(); } - return 0; + + volatile int _result = MUTILS_INTERFACE; + return _result; }