Common.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_Common_hxx
00024 #define __ccxx_Common_hxx
00025 
00053 #define CCXX_VERSION 0x00000606
00054 #define CCXX_VERSION_MAJOR ((uint_t)((CCXX_VERSION >> 16) & 0xFF))
00055 #define CCXX_VERSION_MINOR ((uint_t)((CCXX_VERSION >> 8) & 0xFF))
00056 #define CCXX_VERSION_MICRO ((uint_t)(CCXX_VERSION & 0xFF))
00057 
00058 // platform detection
00059 
00074 #if defined(__CYGWIN__)
00075 #define CCXX_OS_POSIX
00076 #define COMMONCPP_API
00077 #define COMMONCPPDB_API
00078 #define COMMONCPPJVM_API
00079 #define COMMONCPPXML_API
00080 #else
00081 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
00082 #define CCXX_OS_WINDOWS
00083 
00084 #ifdef __MINGW32__
00085 #define CCXX_OS_WINDOWS_GNU
00086 #endif
00087 
00088 #if defined(COMMONCPP_EXPORTS)
00089 #define COMMONCPP_API __declspec(dllexport)
00090 #else // ! COMMONCPP_EXPORTS
00091 #define COMMONCPP_API __declspec(dllimport)
00092 #endif // COMMONCPP_EXPORTS
00093 
00094 #if defined(COMMONCPPDB_EXPORTS)
00095 #define COMMONCPPDB_API __declspec(dllexport)
00096 #else // ! COMMONCPPDB_EXPORTS
00097 #define COMMONCPPDB_API __declspec(dllimport)
00098 #endif // COMMONCPPDB_EXPORTS
00099 
00100 #if defined(COMMONCPPJVM_EXPORTS)
00101 #define COMMONCPPJVM_API __declspec(dllexport)
00102 #else // ! COMMONCPPJVM_EXPORTS
00103 #define COMMONCPPJVM_API __declspec(dllimport)
00104 #endif // COMMONCPPJVM_EXPORTS
00105 
00106 #if defined(COMMONCPPXML_EXPORTS)
00107 #define COMMONCPPXML_API __declspec(dllexport)
00108 #else // ! COMMONCPPXML_EXPORTS
00109 #define COMMONCPPXML_API __declspec(dllimport)
00110 #endif // COMMONCPPXML_EXPORTS
00111 
00112 #else // !WIN32
00113 #define CCXX_OS_POSIX
00114 
00115 #ifdef __APPLE__
00116 #define CCXX_OS_MACOSX
00117 #endif
00118 
00119 #define COMMONCPP_API
00120 #define COMMONCPPDB_API
00121 #define COMMONCPPJVM_API
00122 #define COMMONCPPXML_API
00123 #endif // WIN32
00124 #endif //__CYGWIN
00125 
00126 #ifdef CCXX_OS_WINDOWS
00127 
00128 #ifndef NOMINMAX
00129 #define NOMINMAX
00130 #endif
00131 
00132 #define _WINSOCKAPI_
00133 #ifdef _WIN32_WINNT
00134 #undef _WIN32_WINNT
00135 #endif
00136 #define _WIN32_WINNT 0x0500 // Windows 2000 or later ONLY
00137 #ifdef FD_SETSIZE
00138 #undef FD_SETSIZE
00139 #endif
00140 #define FD_SETSIZE 1024
00141 #include <winsock2.h> // compilation of MulticastSocket fails otherwise.
00142 #include <windows.h>
00143 #endif // CCXX_OS_WINDOWS
00144 
00155 #if defined(__GNUC__) && ((__GNUC__ > 3)                                \
00156                           || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 0)))
00157 
00158 #define ___DEPRECATED(DECL) DECL __attribute__((deprecated))
00159 #define ___UNUSED __attribute__((unused))
00160 #define ___NORETURN(DECL) DECL __attribute__((noreturn))
00161 #define ___PRINTF(M, N) __attribute__((format(printf, M, N)))
00162 
00163 #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
00164 
00165 #define ___DEPRECATED(DECL) __declspec(deprecated) DECL
00166 #define ___UNUSED
00167 #define ___NORETURN(DECL) __declspec(noreturn) DECL
00168 #define ___PRINTF(M, N)
00169 
00170 #else
00171 
00172 #define ___DEPRECATED(DECL) DECL
00173 #define ___UNUSED
00174 #define ___NORETURN(DECL) DECL
00175 #define ___PRINTF(M, N)
00176 
00177 #endif
00178 
00179 #include <cstddef>
00180 
00181 #ifndef CCXX_OS_WINDOWS
00182 #include <sys/types.h>
00183 #include <pthread.h>
00184 #endif
00185 
00186 #include <commonc++/Integers.h++>
00187 
00188 namespace ccxx {
00189 
00190 typedef uint16_t char16_t;
00191 
00192 #ifdef CCXX_OS_WINDOWS
00193 
00194 typedef HANDLE ProcessHandle;
00195 typedef DWORD ProcessID;
00196 typedef HANDLE ThreadHandle;
00197 typedef DWORD ThreadID;
00198 typedef HANDLE FileHandle;
00199 
00200 #define CCXX_INVALID_FILE_HANDLE INVALID_HANDLE_VALUE
00201 
00202 #else // ! CCXX_OS_WINDOWS
00203 
00204 typedef pid_t ProcessHandle;
00205 typedef pid_t ProcessID;
00206 typedef pthread_t ThreadHandle;
00207 typedef pthread_t ThreadID;
00208 typedef int FileHandle;
00209 
00212 #define CCXX_INVALID_FILE_HANDLE (-1)
00213 
00214 #endif // CCXX_OS_WINDOWS
00215 
00220 #ifdef NUL
00221 #undef NUL
00222 #endif
00223 #define NUL '\0'
00224 
00229 #ifdef WNUL
00230 #undef WNUL
00231 #endif
00232 #define WNUL L'\0'
00233 
00239 #define CCXX_LENGTHOF(A)                        \
00240   (sizeof(A) / sizeof(A[0]))
00241 
00246 #define CCXX_OFFSETOF(S, F)                                     \
00247   ((size_t)(((void *)(&(((S)NULL)->F))) - ((void *)NULL)))
00248 
00253 #define CCXX_ZERO(V)                            \
00254   (std::memset(&(V), 0, sizeof(V)))
00255 
00258 #define __CCXX_STRINGIFY__(S) #S
00259 
00264 #define CCXX_STRINGIFY(S) __CCXX_STRINGIFY__(S)
00265 
00270 #define __CCXX_UNIQUE_VARNAME__(pfx, id, sfx) pfx ## _ ## id ## _ ## sfx
00271 #define CCXX_UNIQUE_VARNAME(pfx, id, sfx)       \
00272   __CCXX_UNIQUE_VARNAME__(pfx, id, sfx)
00273 
00276 #define CCXX_STATIC_INITIALIZER                                         \
00277   static void __ccxx_static_init__(void);                               \
00278   static bool __ccxx_static_init_done__ = (__ccxx_static_init__(), true); \
00279   static void __ccxx_static_init__(void)
00280 
00287 #define CCXX_COPY_DECLS(CLASS)                  \
00288   CLASS(const CLASS &other);                    \
00289   CLASS& operator=(const CLASS &other);
00290 
00291 #define CCXX_PIMPL_DECL(TYPE)                   \
00292   class TYPE ## Private;                        \
00293   TYPE ## Private *pimpl_;
00294 
00295 #define CCXX_PIMPL(TYPE)                        \
00296   TYPE ## Private *pimpl = this->pimpl_;
00297 
00299 enum Priority { PrioLowest, PrioLow, PrioNormal, PrioHigh, PrioHighest };
00300 
00302 enum Endianness { BigEndian = 0, LittleEndian = 1 };
00303 
00304 }; // namespace ccxx
00305 
00311 #define CCXX_FWD_DECL(CLASS)                    \
00312   namespace ccxx { class CLASS; };
00313 
00314 #endif // __ccxx_Common_hxx
00315 
00316 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3