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 // Hack to make KDevelop parse QString properly. Q_REQUIRED_RESULT expands into |
|
27 // an __attribute__((warn_unused_result)) KDevelop's lexer doesn't seem to |
|
28 // understand, yielding an error and leaving some methods unlexed. |
|
29 // |
|
30 // The following first includes <QChar> to get Q_REQUIRED_RESULT defined first, |
|
31 // then re-defining it as nothing. This causes Q_REQUIRED_RESULT to essentially |
|
32 // "vanish" from QString's methods when KDevelop lexes them. |
|
33 // |
|
34 // Similar reasoning for Q_DECL_HIDDEN, except with Q_OBJECT this time. |
|
35 #ifdef IN_IDE_PARSER |
|
36 # include <QChar> |
|
37 # undef Q_REQUIRED_RESULT |
|
38 # undef Q_DECL_HIDDEN |
|
39 # define Q_REQUIRED_RESULT |
|
40 # define Q_DECL_HIDDEN |
|
41 #endif |
|
42 |
|
43 #include <stdio.h> |
|
44 #include <stdlib.h> |
|
45 #include <stdint.h> |
|
46 #include <stdarg.h> |
|
47 #include <QString> |
|
48 #include <QMutex> |
|
49 |
|
50 #include "config.h" |
|
51 |
|
52 #define APPNAME "LDForge" |
|
53 #define VERSION_MAJOR 0 |
|
54 #define VERSION_MINOR 2 |
|
55 #define VERSION_PATCH 999 |
|
56 #define BUILD_ID BUILD_INTERNAL |
|
57 |
|
58 #define BUILD_INTERNAL 0 |
|
59 #define BUILD_ALPHA 1 |
|
60 #define BUILD_BETA 2 |
|
61 #define BUILD_RC 3 |
|
62 #define BUILD_RELEASE 4 |
|
63 |
|
64 // RC Number for BUILD_RC |
|
65 #define RC_NUMBER 0 |
|
66 |
|
67 // ============================================= |
|
68 #ifdef DEBUG |
|
69 # undef RELEASE |
|
70 #endif // DEBUG |
|
71 |
|
72 #ifdef RELEASE |
|
73 # undef DEBUG |
|
74 #endif // RELEASE |
|
75 |
|
76 // ============================================= |
|
77 #define alias auto& |
|
78 #define elif(A) else if (A) |
|
79 |
|
80 // Null pointer |
|
81 static const std::nullptr_t null = nullptr; |
|
82 |
|
83 #ifdef WIN32 |
|
84 # define DIRSLASH "\\" |
|
85 # define DIRSLASH_CHAR '\\' |
|
86 #else // WIN32 |
|
87 # define DIRSLASH "/" |
|
88 # define DIRSLASH_CHAR '/' |
|
89 #endif // WIN32 |
|
90 |
|
91 #define PROPERTY( ACCESS, TYPE, NAME, OPS, WRITETYPE ) \ |
|
92 private: \ |
|
93 TYPE m_##NAME; \ |
|
94 \ |
|
95 public: \ |
|
96 inline TYPE const& GET_READ_METHOD( NAME, OPS ) const \ |
|
97 { return m_##NAME; \ |
|
98 } \ |
|
99 \ |
|
100 ACCESS: \ |
|
101 DEFINE_WRITE_METHOD_##WRITETYPE( TYPE, NAME ) \ |
|
102 DEFINE_PROPERTY_##OPS( TYPE, NAME ) |
|
103 |
|
104 #define GET_READ_METHOD( NAME, OPS ) \ |
|
105 GET_READ_METHOD_##OPS( NAME ) |
|
106 |
|
107 #define GET_READ_METHOD_BOOL_OPS( NAME ) is##NAME() |
|
108 #define GET_READ_METHOD_NO_OPS( NAME ) get##NAME() |
|
109 #define GET_READ_METHOD_STR_OPS( NAME ) get##NAME() |
|
110 #define GET_READ_METHOD_NUM_OPS( NAME ) get##NAME() |
|
111 |
|
112 #define DEFINE_WRITE_METHOD_STOCK_WRITE( TYPE, NAME ) \ |
|
113 inline void set##NAME( TYPE const& NAME##_ ) \ |
|
114 { m_##NAME = NAME##_; \ |
|
115 } |
|
116 |
|
117 #define DEFINE_WRITE_METHOD_CUSTOM_WRITE( TYPE, NAME ) \ |
|
118 void set##NAME( TYPE const& NAME##_ ); \ |
|
119 |
|
120 #define DEFINE_WITH_CB( NAME ) void NAME##Changed(); |
|
121 #define DEFINE_NO_CB( NAME ) |
|
122 |
|
123 #define DEFINE_PROPERTY_NO_OPS( TYPE, NAME ) |
|
124 |
|
125 #define DEFINE_PROPERTY_STR_OPS( TYPE, NAME ) \ |
|
126 void append##NAME( TYPE a ) \ |
|
127 { TYPE tmp( m_##NAME ); \ |
|
128 tmp.append( a ); \ |
|
129 set##NAME( tmp ); \ |
|
130 } \ |
|
131 \ |
|
132 void prepend##NAME( TYPE a ) \ |
|
133 { TYPE tmp( m_##NAME ); \ |
|
134 tmp.prepend( a ); \ |
|
135 set##NAME( tmp ); \ |
|
136 } \ |
|
137 \ |
|
138 void replaceIn##NAME( TYPE a, TYPE b ) \ |
|
139 { TYPE tmp( m_##NAME ); \ |
|
140 tmp.replace( a, b ); \ |
|
141 set##NAME( tmp ); \ |
|
142 } |
|
143 |
|
144 #define DEFINE_PROPERTY_NUM_OPS( TYPE, NAME ) \ |
|
145 inline void increase##NAME( TYPE a = 1 ) \ |
|
146 { set##NAME( m_##NAME + a ); \ |
|
147 } \ |
|
148 \ |
|
149 inline void decrease##NAME( TYPE a = 1 ) \ |
|
150 { set##NAME( m_##NAME - a ); \ |
|
151 } |
|
152 |
|
153 #define DEFINE_PROPERTY_BOOL_OPS( TYPE, NAME ) \ |
|
154 inline void toggle##NAME() \ |
|
155 { set##NAME( !m_##NAME ); \ |
|
156 } |
|
157 |
|
158 #ifdef null |
|
159 #undef null |
|
160 #endif // null |
|
161 |
|
162 #ifdef __GNUC__ |
|
163 #define FUNCNAME __PRETTY_FUNCTION__ |
|
164 #else |
|
165 #define FUNCNAME __func__ |
|
166 #endif // __GNUC__ |
|
167 |
|
168 // Replace assert with a version that shows a GUI dialog if possible. |
|
169 // On Windows I just can't get the actual error messages otherwise. |
|
170 void assertionFailure (const char* file, int line, const char* funcname, const char* expr); |
|
171 |
|
172 #ifdef assert |
|
173 # undef assert |
|
174 #endif // assert |
|
175 |
|
176 #ifdef DEBUG |
|
177 # define assert(N) { ((N) ? (void) 0 : assertionFailure (__FILE__, __LINE__, FUNCNAME, #N)); } |
|
178 #else |
|
179 # define assert(N) {} |
|
180 #endif // DEBUG |
|
181 |
|
182 // Version string identifier |
|
183 QString versionString(); |
|
184 QString versionMoniker(); |
|
185 QString fullVersionString(); |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 #ifdef IN_IDE_PARSER // KDevelop workarounds: |
|
189 # error IN_IDE_PARSER is defined (this code is only for KDevelop workarounds) |
|
190 |
|
191 # ifndef va_start |
|
192 # define va_start(va, arg) |
|
193 # endif // va_start |
|
194 |
|
195 # ifndef va_end |
|
196 # define va_end(va) |
|
197 # endif // va_end |
|
198 |
|
199 static const char* __func__ = ""; // Current function name |
|
200 typedef void FILE; // :| |
|
201 #endif // IN_IDE_PARSER |
|
202 |
|
203 #endif // LDFORGE_COMMON_H |
|