OSDN Git Service

Added support for Visual Studio 2019.2 (v16.2).
[mutilities/MUtilities.git] / include / MUtils / Global.h
index bcf660f..ca7fe75 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // MuldeR's Utilities for Qt
-// Copyright (C) 2004-2017 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
  */
 
@@ -86,6 +101,11 @@ class QProcess;
 namespace MUtils
 {
        /**
+       * \brief This struct containes the parts (integral and fractional part) of a floating-point number
+       */
+       typedef struct _fp_parts_t { double parts[2]; } fp_parts_t;
+
+       /**
        * \brief Rerieves the full path of the application's *Temp* folder.
        *
        * The application's *Temp* folder is a unique application-specific folder, intended to store any temporary files that the application may need. It will be created when this function is called for the first time (lazy initialization); subsequent calls are guaranteed to return the same path. Usually the application's *Temp* folder will be created as a sub-folder of the system's global *Temp* folder, as indicated by the `TMP` or `TEMP` environment variables. However, it may be created at a different place (e.g. in the users *Profile* directory), if those environment variables don't point to a usable directory. In any case, this function makes sure that the application's *Temp* folder exists for the whole lifetime of the application and that it is writable. When the application terminates normally, the application's *Temp* folder and all files or sub-directories thereof will be *removed* automatically!
@@ -107,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.
@@ -117,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.
        *
@@ -152,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.
@@ -168,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
@@ -329,11 +352,22 @@ namespace MUtils
        */
        MUTILS_API QStringList available_codepages(const bool &noAliases = true);
 
-       //Internal
+       /**
+       * \brief Break floating-point number into fractional and integral parts
+       *
+       * The function returns a struct containing the fractional and the integral part of a given floating-point values as two separate values. This is a convenience warapper for the `modf()` function.
+       *
+       * \param value The original floating-point value
+       *
+       * \return Returns a struct containing the fractional and integral parts.
+       */
+       MUTILS_API fp_parts_t break_fp(const double value);
+
+       //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);
        }
 }