OSDN Git Service

c235b88cc6cc89651ef06c90b33bbea63b62d33f
[mutilities/MUtilities.git] / include / MUtils / Global.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2014 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
20 //////////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 #include <QString>
25
26 //Forward Declarations
27 class QProcess;
28
29 ///////////////////////////////////////////////////////////////////////////////
30
31 //MUtils API
32 #ifdef _MSC_VER
33 #       ifdef MUTILS_DLL_EXPORT
34 #               define MUTILS_API __declspec(dllexport)
35 #       else
36 #               ifndef MUTILS_STATIC_LIB
37 #                       define MUTILS_API __declspec(dllimport)
38 #               else
39 #                       define MUTILS_API /*static lib*/
40 #               endif
41 #       endif
42 #else
43 #       define MUTILS_API
44 #endif
45
46 //Helper Macros
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))
50
51 //Check Debug Flags
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!
56 #       endif
57 #else
58 #       define MUTILS_DEBUG (0)
59 #       if (!defined(NDEBUG)) || (!defined(QT_NO_DEBUG)) || defined(QT_DEBUG)
60 #               error Inconsistent DEBUG flags have been detected!
61 #       endif
62 #endif
63
64 //Check CPU options
65 #if defined(_MSC_VER) && (!defined(_M_X64)) && defined(_M_IX86_FP)
66         #if (_M_IX86_FP != 0)
67                 #error We should not enabled SSE or SSE2 in release builds!
68         #endif
69 #endif
70
71 ///////////////////////////////////////////////////////////////////////////////
72
73 namespace MUtils
74 {
75         //Temp Folder
76         MUTILS_API const QString& temp_folder(void);
77
78         //Process Utils
79         MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true);
80
81         //Random
82         MUTILS_API void seed_rand(void);
83         MUTILS_API QString rand_str(const bool &bLong = false);
84         MUTILS_API quint32 next_rand32(void);
85         MUTILS_API quint64 next_rand64(void);
86
87         //Remove File/Dir
88         MUTILS_API bool remove_file(const QString &fileName);
89         MUTILS_API bool remove_directory(const QString &folderPath);
90
91         //Version
92         MUTILS_API const char* mutils_build_date(void);
93         MUTILS_API const char* mutils_build_time(void);
94
95         //Internal
96         namespace Internal
97         {
98                 MUTILS_API int selfTest(const char *const date, const bool debug);
99                 static const int g_selfTestRet = selfTest(__DATE__, MUTILS_DEBUG);
100         }
101 }
102
103 ///////////////////////////////////////////////////////////////////////////////
104
105 #define MUTILS_DELETE(PTR) do \
106 { \
107         if((PTR)) \
108         { \
109                 delete (PTR); \
110                 (PTR) = NULL; \
111         } \
112 } \
113 while(0)
114
115 #define MUTILS_DELETE_ARRAY(PTR) do \
116 { \
117         if((PTR)) \
118         { \
119                 delete [] (PTR); \
120                 (PTR) = NULL; \
121         } \
122 } \
123 while(0)
124
125 //String conversion macros
126 #define MUTILS_WCHR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
127 #define MUTILS_UTF8(STR) ((STR).toUtf8().constData())
128 #define MUTILS_QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
129
130 //Boolean helper
131 #define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")