libcommonc++  0.7
Common.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Common_hxx
24 #define __ccxx_Common_hxx
25 
53 #define CCXX_VERSION 0x00000606
54 #define CCXX_VERSION_MAJOR ((uint_t)((CCXX_VERSION >> 16) & 0xFF))
55 #define CCXX_VERSION_MINOR ((uint_t)((CCXX_VERSION >> 8) & 0xFF))
56 #define CCXX_VERSION_MICRO ((uint_t)(CCXX_VERSION & 0xFF))
57 
58 // platform detection
59 
76 #if defined(__CYGWIN__)
77 #define CCXX_OS_POSIX
78 #define COMMONCPP_API
79 #define COMMONCPPDB_API
80 #define COMMONCPPJVM_API
81 #define COMMONCPPXML_API
82 #else
83 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) \
84  || defined(_WIN64) || defined(WIN64)
85 #define CCXX_OS_WINDOWS
86 
87 #ifdef __MINGW32__
88 #define CCXX_OS_WINDOWS_GNU
89 #endif
90 
91 #if defined(COMMONCPP_EXPORTS)
92 #define COMMONCPP_API __declspec(dllexport)
93 #else // ! COMMONCPP_EXPORTS
94 #define COMMONCPP_API __declspec(dllimport)
95 #endif // COMMONCPP_EXPORTS
96 
97 #if defined(COMMONCPPDB_EXPORTS)
98 #define COMMONCPPDB_API __declspec(dllexport)
99 #else // ! COMMONCPPDB_EXPORTS
100 #define COMMONCPPDB_API __declspec(dllimport)
101 #endif // COMMONCPPDB_EXPORTS
102 
103 #if defined(COMMONCPPJVM_EXPORTS)
104 #define COMMONCPPJVM_API __declspec(dllexport)
105 #else // ! COMMONCPPJVM_EXPORTS
106 #define COMMONCPPJVM_API __declspec(dllimport)
107 #endif // COMMONCPPJVM_EXPORTS
108 
109 #if defined(COMMONCPPXML_EXPORTS)
110 #define COMMONCPPXML_API __declspec(dllexport)
111 #else // ! COMMONCPPXML_EXPORTS
112 #define COMMONCPPXML_API __declspec(dllimport)
113 #endif // COMMONCPPXML_EXPORTS
114 
115 #else // !WIN32
116 #define CCXX_OS_POSIX
117 
118 #ifdef __APPLE__
119 #define CCXX_OS_MACOSX
120 #endif
121 
122 #ifdef __ANDROID__
123 #define CCXX_OS_ANDROID
124 #endif
125 
126 #define COMMONCPP_API
127 #define COMMONCPPDB_API
128 #define COMMONCPPJVM_API
129 #define COMMONCPPXML_API
130 #endif // WIN32
131 #endif // __CYGWIN__
132 
133 #ifdef CCXX_OS_WINDOWS
134 
135 #ifndef NOMINMAX
136 #define NOMINMAX
137 #endif
138 
139 #define _WINSOCKAPI_
140 #ifdef _WIN32_WINNT
141 #undef _WIN32_WINNT
142 #endif
143 #define _WIN32_WINNT 0x0500 // Windows 2000 or later ONLY
144 #ifdef FD_SETSIZE
145 #undef FD_SETSIZE
146 #endif
147 #define FD_SETSIZE 1024
148 #include <winsock2.h> // compilation of MulticastSocket fails otherwise.
149 #include <windows.h>
150 #endif // CCXX_OS_WINDOWS
151 
162 #if defined(__GNUC__) && ((__GNUC__ > 3) \
163  || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 0)))
164 
165 #define ___DEPRECATED(DECL) DECL __attribute__((deprecated))
166 #define ___UNUSED __attribute__((unused))
167 #define ___NORETURN(DECL) DECL __attribute__((noreturn))
168 #define ___PRINTF(M, N) __attribute__((format(printf, M, N)))
169 
170 #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
171 
172 #define ___DEPRECATED(DECL) __declspec(deprecated) DECL
173 #define ___UNUSED
174 #define ___NORETURN(DECL) __declspec(noreturn) DECL
175 #define ___PRINTF(M, N)
176 
177 #else
178 
179 #define ___DEPRECATED(DECL) DECL
180 #define ___UNUSED
181 #define ___NORETURN(DECL) DECL
182 #define ___PRINTF(M, N)
183 
184 #endif
185 
186 #include <cstddef>
187 
188 #ifndef CCXX_OS_WINDOWS
189 #include <sys/types.h>
190 #include <pthread.h>
191 #endif
192 
193 #include <commonc++/Integers.h++>
194 
195 namespace ccxx {
196 
201 typedef uint16_t char16_t;
202 
207 typedef uint32_t char32_t;
208 
209 #ifdef CCXX_OS_WINDOWS
210 
211 typedef HANDLE ProcessHandle;
212 typedef DWORD ProcessID;
213 typedef HANDLE ThreadHandle;
214 typedef DWORD ThreadID;
215 typedef HANDLE FileHandle;
216 
217 #define CCXX_INVALID_FILE_HANDLE INVALID_HANDLE_VALUE
218 
219 #else // ! CCXX_OS_WINDOWS
220 
221 typedef pid_t ProcessHandle;
222 typedef pid_t ProcessID;
223 typedef pthread_t ThreadHandle;
224 typedef pthread_t ThreadID;
225 typedef int FileHandle;
226 
229 #define CCXX_INVALID_FILE_HANDLE (-1)
230 
231 #endif // CCXX_OS_WINDOWS
232 
237 #ifdef NUL
238 #undef NUL
239 #endif
240 #define NUL '\0'
241 
247 #define CCXX_LENGTHOF(A) \
248  (sizeof(A) / sizeof(A[0]))
249 
254 #define CCXX_OFFSETOF(S, F) \
255  ((size_t)(((void *)(&(((S *)NULL)->F))) - ((void *)NULL)))
256 
261 #define CCXX_ZERO(V) \
262  (std::memset(&(V), 0, sizeof(V)))
263 
266 #define __CCXX_STRINGIFY__(S) #S
267 
272 #define CCXX_STRINGIFY(S) __CCXX_STRINGIFY__(S)
273 
278 #define __CCXX_UNIQUE_VARNAME__(pfx, id, sfx) pfx ## _ ## id ## _ ## sfx
279 #define CCXX_UNIQUE_VARNAME(pfx, id, sfx) \
280  __CCXX_UNIQUE_VARNAME__(pfx, id, sfx)
281 
284 #define CCXX_STATIC_INITIALIZER \
285  static void __ccxx_static_init__(void); \
286  static bool __ccxx_static_init_done__ = (__ccxx_static_init__(), true); \
287  static void __ccxx_static_init__(void)
288 
295 #define CCXX_COPY_DECLS(CLASS) \
296  CLASS(const CLASS &other); \
297  CLASS& operator=(const CLASS &other);
298 
299 #define CCXX_PIMPL_DECL(TYPE) \
300  class TYPE ## Private; \
301  TYPE ## Private *pimpl_;
302 
303 #define CCXX_PIMPL(TYPE) \
304  TYPE ## Private *pimpl = this->pimpl_;
305 
307 enum Priority {
318 };
319 
326 };
327 
328 }; // namespace ccxx
329 
335 #define CCXX_FWD_DECL(CLASS) \
336  namespace ccxx { class CLASS; };
337 
338 #endif // __ccxx_Common_hxx
Highest priority.
Definition: Common.h++:317
Lowest priority.
Definition: Common.h++:309
Big-endian (network byte order).
Definition: Common.h++:323
pid_t ProcessID
Definition: Common.h++:222
uint32_t char32_t
A UTF-32 character.
Definition: Common.h++:207
pthread_t ThreadHandle
Definition: Common.h++:223
int FileHandle
Definition: Common.h++:225
pthread_t ThreadID
Definition: Common.h++:224
pid_t ProcessHandle
Definition: Common.h++:221
Normal (default) priority.
Definition: Common.h++:313
uint16_t char16_t
A UTF-16 character.
Definition: Common.h++:201
Priority
Thread and Process priority levels.
Definition: Common.h++:307
Endianness
Byte endianness.
Definition: Common.h++:321
Definition: AllocationMap.c++:25
Low priority.
Definition: Common.h++:311
Little-endian.
Definition: Common.h++:325
High priority.
Definition: Common.h++:315