global.h
1 //-----------------------------------------------------------------------------
2 // global.h
3 //-----------------------------------------------------------------------------
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301 USA
18 //-----------------------------------------------------------------------------
19 // Copyright (C) 2009 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
20 //-----------------------------------------------------------------------------
21 #ifndef __GLOBAL_H__
22 #define __GLOBAL_H__
23 
24 #include <QtGlobal>
25 #include <QThread>
26 
27 static inline quint32 READINT32(const char *pointer)
28 {
29  return (quint32((quint8)(*pointer))) | (quint32(quint8(*(pointer + 1))) << 8) | (quint32(quint8(*(pointer + 2))) << 16) | (quint32(quint8(*(pointer + 3))) << 24);
30 }
31 static inline quint16 READINT16(const char *pointer)
32 {
33  return (quint16((quint8)(*pointer))) | (quint16(quint8(*(pointer + 1))) << 8);
34 }
35 static inline quint16 READBIGINT16(const char *pointer)
36 {
37  return (quint16((quint8)(*pointer)) << 8) | (quint16(quint8(*(pointer + 1))));
38 }
39 static inline quint8 READINT8(const char *pointer)
40 {
41  return quint8(*pointer);
42 }
43 
44 #define WRITEINT8_DIRECT(type, integer) (type)(quint8)((integer) & 0xFF)
45 #define WRITEINT16_DIRECT(type, integer) WRITEINT8_DIRECT(type, integer), WRITEINT8_DIRECT(type, integer >> 8)
46 #define WRITEINT32_DIRECT(type, integer) WRITEINT8_DIRECT(type, integer), WRITEINT8_DIRECT(type, integer >> 8), WRITEINT8_DIRECT(type, integer >> 16), WRITEINT8_DIRECT(type, integer >> 24)
47 
48 static inline void WRITEINT32(char *pointer, const quint32 integer)
49 {
50  *pointer = (quint8)(integer & 0xFF);
51  *(pointer + 1) = (quint8)((integer >> 8) & 0xFF);
52  *(pointer + 2) = (quint8)((integer >> 16) & 0xFF);
53  *(pointer + 3) = (quint8)((integer >> 24) & 0xFF);
54 }
55 static inline void WRITEINT16(char *pointer, const quint16 integer)
56 {
57  *pointer = (quint8)(integer & 0xFF);
58  *(pointer + 1) = (quint8)((integer >> 8) & 0xFF);
59 }
60 static inline void WRITEINT8(char *pointer, const quint8 integer)
61 {
62  *pointer = (quint8)(integer & 0xFF);
63 }
64 
65 static inline quint32 MAKEID(quint8 a, quint8 b, quint8 c, quint8 d)
66 {
67  return quint32(a) | (quint32(b) << 8) | (quint32(c) << 16) | (quint32(d) << 24);
68 }
69 
70 // Now we set it up so symbols are properly exported/imported on Windows
71 #ifdef Q_OS_WIN32
72 #ifdef doomseeker_EXPORTS
73 #define MAIN_EXPORT __declspec(dllexport)
74 #define PLUGIN_EXPORT __declspec(dllimport)
75 #else
76 #define MAIN_EXPORT __declspec(dllimport)
77 #define PLUGIN_EXPORT __declspec(dllexport)
78 #endif
79 #else
80 #define MAIN_EXPORT
81 #define PLUGIN_EXPORT
82 #endif
83 
84 class Sleep : private QThread
85 {
86 public:
87  static void sleep(int time)
88  {
89  QThread::sleep(time);
90  }
91 };
92 
93 #endif /* __GLOBAL_H__ */