OSDN Git Service

Various improvements to known_folder() function, again.
[mutilities/MUtilities.git] / include / MUtils / Global.h
index ce3f60c..ca7fe75 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // MuldeR's Utilities for Qt
-// Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 
 //Forward Declarations
 class QProcess;
+class QDir;
+template<typename K, typename V> class QHash;
 
 ///////////////////////////////////////////////////////////////////////////////
 
 /** \cond INTERNAL
  */
 
+ //Interface version
+#define MUTILS_INTERFACE 3
+
 //MUtils API
 #ifdef _MSC_VER
 #      ifdef MUTILS_DLL_EXPORT
@@ -51,10 +56,6 @@ class QProcess;
 #      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)
@@ -75,6 +76,20 @@ class QProcess;
        #endif
 #endif
 
+//Library initializer
+#define MUTILS_GLUE_NAME_HELPER(X,Y) X##Y
+#define MUTILS_GLUE_NAME(X,Y) MUTILS_GLUE_NAME_HELPER(X,Y)
+#if MUTILS_DEBUG
+#define MUTILS_INITIALIZER MUTILS_GLUE_NAME(initialize_d, MUTILS_INTERFACE)
+#else
+#define MUTILS_INITIALIZER MUTILS_GLUE_NAME(initialize_r, MUTILS_INTERFACE)
+#endif
+
+//Compiler warnings
+#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))
+
 /** \endcond INTERNAL
  */
 
@@ -112,7 +127,7 @@ namespace MUtils
        *
        * \param extraPaths A read-only pointer to a QStringList object containing additional paths that will be added (prepended) to the sub-process' `PATH` environment variable. This parameter can be `NULL`, in which case *no* additional paths are added.
        */
-       MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true, const QStringList *const extraPaths = NULL);
+       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);
 
        /**
        * \brief Generates a *random* unsigned 32-Bit value.
@@ -122,7 +137,8 @@ namespace MUtils
        * \return The function returns a *random* unsigned 32-Bit value.
        */
        MUTILS_API quint32 next_rand_u32(void);
-       
+       MUTILS_API quint32 next_rand_u32(const quint32 max);
+
        /**
        * \brief Generates a *random* unsigned 64-Bit value.
        *
@@ -157,6 +173,7 @@ namespace MUtils
        * \return If the function succeeds, it returns a QString holding the full path of the temporary file; otherwise it returns a default-constructed QString.
        */
        MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
+       MUTILS_API QString make_temp_file(const QDir    &basePath, const QString &extension, const bool placeholder = false);
 
        /**
        * \brief Generates a unique file name.
@@ -173,7 +190,8 @@ namespace MUtils
        *
        * \return If the function succeeds, it returns a QString holding the full path of the unique file; otherwise it returns a default-constructed QString.
        */
-       MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy = false);
+       MUTILS_API QString make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy = false, const bool placeholder = false);
+       MUTILS_API QString make_unique_file(const QDir    &basePath, const QString &baseName, const QString &extension, const bool fancy = false, const bool placeholder = false);
 
        /**
        * \brief Computes the *parity* of the given unsigned 32-Bit value
@@ -345,11 +363,11 @@ namespace MUtils
        */
        MUTILS_API fp_parts_t break_fp(const double value);
 
-       //Internal
+       //Internal (do *not* call directly!)
        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 unsigned int MUTILS_INITIALIZER(const unsigned int interfaceId);
+               static const unsigned int init_flag = MUTILS_INITIALIZER(MUTILS_INTERFACE);
        }
 }