| 1 /* |
|
| 2 * LDForge: LDraw parts authoring CAD |
|
| 3 * Copyright (C) 2013 Santeri Piippo |
|
| 4 * |
|
| 5 * This program is free software: you can redistribute it and/or modify |
|
| 6 * it under the terms of the GNU General Public License as published by |
|
| 7 * the Free Software Foundation, either version 3 of the License, or |
|
| 8 * (at your option) any later version. |
|
| 9 * |
|
| 10 * This program 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 |
|
| 13 * GNU General Public License for more details. |
|
| 14 * |
|
| 15 * You should have received a copy of the GNU General Public License |
|
| 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 */ |
|
| 18 |
|
| 19 // ============================================================================= |
|
| 20 // This file is included one way or another in every source file of LDForge. |
|
| 21 // Stuff defined and included here is universally included. |
|
| 22 |
|
| 23 #ifndef LDFORGE_COMMON_H |
|
| 24 #define LDFORGE_COMMON_H |
|
| 25 |
|
| 26 #include <stdio.h> |
|
| 27 #include <stdlib.h> |
|
| 28 #include <stdint.h> |
|
| 29 #include <stdarg.h> |
|
| 30 #include <QString> |
|
| 31 #include <QMutex> |
|
| 32 |
|
| 33 #include "config.h" |
|
| 34 |
|
| 35 #define APPNAME "LDForge" |
|
| 36 #define VERSION_MAJOR 0 |
|
| 37 #define VERSION_MINOR 2 |
|
| 38 #define VERSION_PATCH 999 |
|
| 39 #define BUILD_ID BUILD_INTERNAL |
|
| 40 |
|
| 41 #define BUILD_INTERNAL 0 |
|
| 42 #define BUILD_ALPHA 1 |
|
| 43 #define BUILD_BETA 2 |
|
| 44 #define BUILD_RC 3 |
|
| 45 #define BUILD_RELEASE 4 |
|
| 46 |
|
| 47 // RC Number for BUILD_RC |
|
| 48 #define RC_NUMBER 0 |
|
| 49 |
|
| 50 // ============================================= |
|
| 51 #ifdef DEBUG |
|
| 52 # undef RELEASE |
|
| 53 #endif // DEBUG |
|
| 54 |
|
| 55 #ifdef RELEASE |
|
| 56 # undef DEBUG |
|
| 57 #endif // RELEASE |
|
| 58 |
|
| 59 // ============================================= |
|
| 60 #define alias auto& |
|
| 61 #define elif(A) else if (A) |
|
| 62 |
|
| 63 // Null pointer |
|
| 64 static const std::nullptr_t null = nullptr; |
|
| 65 |
|
| 66 #ifdef WIN32 |
|
| 67 # define DIRSLASH "\\" |
|
| 68 # define DIRSLASH_CHAR '\\' |
|
| 69 #else // WIN32 |
|
| 70 # define DIRSLASH "/" |
|
| 71 # define DIRSLASH_CHAR '/' |
|
| 72 #endif // WIN32 |
|
| 73 |
|
| 74 #define PROP_NAME(GET) m_##GET |
|
| 75 |
|
| 76 #define READ_ACCESSOR(T, GET) \ |
|
| 77 T const& GET() const |
|
| 78 |
|
| 79 #define SET_ACCESSOR(T, SET) \ |
|
| 80 void SET (T val) |
|
| 81 |
|
| 82 // Read-only, private property with a get accessor |
|
| 83 #define DECLARE_READ_PROPERTY(T, GET, SET) \ |
|
| 84 private: \ |
|
| 85 T PROP_NAME (GET); \ |
|
| 86 SET_ACCESSOR (T, SET); \ |
|
| 87 public: \ |
|
| 88 READ_ACCESSOR (T, GET); |
|
| 89 |
|
| 90 // Read/write private property with get and set accessors |
|
| 91 #define DECLARE_PROPERTY(T, GET, SET) \ |
|
| 92 private: \ |
|
| 93 T PROP_NAME (GET); \ |
|
| 94 public: \ |
|
| 95 READ_ACCESSOR (T, GET); \ |
|
| 96 SET_ACCESSOR (T, SET); |
|
| 97 |
|
| 98 #define DEFINE_PROPERTY(T, CLASS, GET, SET) \ |
|
| 99 READ_ACCESSOR (T, CLASS::GET) { return PROP_NAME (GET); } \ |
|
| 100 SET_ACCESSOR (T, CLASS::SET) { PROP_NAME (GET) = val; } |
|
| 101 |
|
| 102 // Shortcuts |
|
| 103 #define PROPERTY(T, GET, SET) \ |
|
| 104 private: \ |
|
| 105 T PROP_NAME (GET); \ |
|
| 106 public: \ |
|
| 107 READ_ACCESSOR (T, GET) { return PROP_NAME (GET); } \ |
|
| 108 SET_ACCESSOR (T, SET) { PROP_NAME (GET) = val; } |
|
| 109 |
|
| 110 #define READ_PROPERTY(T, GET, SET) \ |
|
| 111 private: \ |
|
| 112 T PROP_NAME (GET); \ |
|
| 113 SET_ACCESSOR (T, SET) { PROP_NAME (GET) = val; } \ |
|
| 114 public: \ |
|
| 115 READ_ACCESSOR (T, GET) { return PROP_NAME (GET); } |
|
| 116 |
|
| 117 // Property whose set accessor is a public slot |
|
| 118 // TODO: make this replace PROPERTY |
|
| 119 #define SLOT_PROPERTY (T, GET, SET) \ |
|
| 120 private: \ |
|
| 121 T PROP_NAME (GET); \ |
|
| 122 public: \ |
|
| 123 READ_ACCESSOR (T, GET) { return PROP_NAME (GET); } \ |
|
| 124 public slots: \ |
|
| 125 SET_ACCESSOR (T, SET) { PROP_NAME (GET) = val; } |
|
| 126 |
|
| 127 #ifdef null |
|
| 128 #undef null |
|
| 129 #endif // null |
|
| 130 |
|
| 131 #ifdef __GNUC__ |
|
| 132 #define FUNCNAME __PRETTY_FUNCTION__ |
|
| 133 #else |
|
| 134 #define FUNCNAME __func__ |
|
| 135 #endif // __GNUC__ |
|
| 136 |
|
| 137 // Replace assert with a version that shows a GUI dialog if possible. |
|
| 138 // On Windows I just can't get the actual error messages otherwise. |
|
| 139 void assertionFailure (const char* file, int line, const char* funcname, const char* expr); |
|
| 140 |
|
| 141 #ifdef assert |
|
| 142 # undef assert |
|
| 143 #endif // assert |
|
| 144 |
|
| 145 #ifdef DEBUG |
|
| 146 # define assert(N) { ((N) ? (void) 0 : assertionFailure (__FILE__, __LINE__, FUNCNAME, #N)); } |
|
| 147 #else |
|
| 148 # define assert(N) {} |
|
| 149 #endif // DEBUG |
|
| 150 |
|
| 151 // Version string identifier |
|
| 152 QString versionString(); |
|
| 153 QString versionMoniker(); |
|
| 154 QString fullVersionString(); |
|
| 155 |
|
| 156 // ----------------------------------------------------------------------------- |
|
| 157 #ifdef IN_IDE_PARSER // KDevelop workarounds: |
|
| 158 # error IN_IDE_PARSER is defined (this code is only for KDevelop workarounds) |
|
| 159 |
|
| 160 # ifndef va_start |
|
| 161 # define va_start(va, arg) |
|
| 162 # endif // va_start |
|
| 163 |
|
| 164 # ifndef va_end |
|
| 165 # define va_end(va) |
|
| 166 # endif // va_end |
|
| 167 |
|
| 168 static const char* __func__ = ""; // Current function name |
|
| 169 typedef void FILE; // :| |
|
| 170 #endif // IN_IDE_PARSER |
|
| 171 |
|
| 172 #endif // LDFORGE_COMMON_H |
|