libpqxx 4.0
compiler-public.hxx
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/compiler-public.hxx
00005  *
00006  *   DESCRIPTION
00007  *      Compiler deficiency workarounds for libpqxx clients
00008  *
00009  * Copyright (c) 2002-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
00010  *
00011  * See COPYING for copyright license.  If you did not receive a file called
00012  * COPYING with this source code, please notify the distributor of this mistake,
00013  * or contact the author.
00014  *
00015  *-------------------------------------------------------------------------
00016  */
00017 #ifndef PQXX_H_COMPILER_PUBLIC
00018 #define PQXX_H_COMPILER_PUBLIC
00019 
00020 #ifdef PQXX_HAVE_BOOST_SMART_PTR
00021 #include <boost/smart_ptr.hpp>
00022 #endif
00023 
00024 #ifdef PQXX_HAVE_MOVE
00025 #include <utility>
00026 #define PQXX_MOVE(value) (PGSTD::move(value))
00027 #else
00028 #define PQXX_MOVE(value) (value)
00029 #endif
00030 
00031 #ifdef _MSC_VER
00032 
00033 /* Work around a particularly pernicious and deliberate bug in Visual C++:
00034  * min() and max() are defined as macros, which can have some very nasty
00035  * consequences.  This compiler bug can be switched off by defining NOMINMAX.
00036  *
00037  * We don't like making choices for the user and defining environmental macros
00038  * of our own accord, but in this case it's the only way to compile without
00039  * incurring a significant risk of bugs--and there doesn't appear to be any
00040  * downside.  One wonders why this compiler wart is being maintained at all,
00041  * since the introduction of inline functions back in the 20th century.
00042  */
00043 #if defined(min) || defined(max)
00044 #error "Oops: min() and/or max() are defined as preprocessor macros.\
00045   Define NOMINMAX macro before including any system headers!"
00046 #endif
00047 
00048 #ifndef NOMINMAX
00049 #define NOMINMAX
00050 #endif
00051 
00052 // Suppress vtables on abstract classes.
00053 #define PQXX_NOVTABLE __declspec(novtable)
00054 
00055 #endif  // _MSC_VER
00056 
00057 
00058 // Workarounds & definitions that need to be included even in library's headers
00059 #include "pqxx/config-public-compiler.h"
00060 
00061 
00062 #ifdef PQXX_BROKEN_ITERATOR
00063 #include <cstddef>
00064 #include <cstdlib>
00066 
00074 namespace PGSTD
00075 {
00077 template<typename Cat,
00078          typename T,
00079          typename Dist,
00080          typename Ptr=T*,
00081          typename Ref=T&> struct iterator
00082 {
00083   typedef Cat iterator_category;
00084   typedef T value_type;
00085   typedef Dist difference_type;
00086   typedef Ptr pointer;
00087   typedef Ref reference;
00088 };
00089 }
00090 #else
00091 #include <iterator>
00092 #endif // PQXX_BROKEN_ITERATOR
00093 
00094 #ifndef PQXX_HAVE_CHAR_TRAITS
00095 #include <cstddef>
00096 namespace PGSTD
00097 {
00099 template<typename CHAR> struct char_traits {};
00101 template<> struct char_traits<char>
00102 {
00103   typedef int int_type;
00104   typedef size_t pos_type;
00105   typedef long off_type;
00106   typedef char char_type;
00107 
00108   static int_type eof() { return -1; }
00109 };
00111 template<> struct char_traits<unsigned char>
00112 {
00113   typedef int int_type;
00114   typedef size_t pos_type;
00115   typedef long off_type;
00116   typedef unsigned char char_type;
00117 
00118   static int_type eof() { return -1; }
00119 };
00120 }
00121 #endif
00122 
00123 // Workarounds for SUN Workshop 6
00124 #if defined(__SUNPRO_CC)
00125 #if __SUNPRO_CC_COMPAT < 5
00126 #error "This compiler version is not capable of building libpqxx."
00127 #endif  // __SUNPRO_CC_COMPAT < 5
00128 #define PQXX_PRIVATE __hidden
00129 #endif  // __SUNPRO_CC
00130 
00131 
00132 // Workarounds for Compaq C++ for Alpha
00133 #if defined(__DECCXX_VER)
00134 #define __USE_STD_IOSTREAM
00135 #endif  // __DECCXX_VER
00136 
00137 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_CONST)
00138 #define PQXX_CONST __attribute__ ((const))
00139 #else
00140 #define PQXX_CONST
00141 #endif
00142 
00143 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_DEPRECATED)
00144 #define PQXX_DEPRECATED __attribute__ ((deprecated))
00145 #else
00146 #define PQXX_DEPRECATED
00147 #endif
00148 
00149 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_NORETURN)
00150 #define PQXX_NORETURN __attribute__ ((noreturn))
00151 #else
00152 #define PQXX_NORETURN
00153 #endif
00154 
00155 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_PURE)
00156 #define PQXX_PURE __attribute__ ((pure))
00157 #else
00158 #define PQXX_PURE
00159 #endif
00160 
00161 
00162 // Workarounds for Windows
00163 #ifdef _WIN32
00164 
00165 
00166 /* For now, export DLL symbols if _DLL is defined.  This is done automatically
00167  * by the compiler when linking to the dynamic version of the runtime library,
00168  * according to "gzh"
00169  */
00170 // TODO: Define custom macro to govern how libpqxx will be linked to client
00171 #if !defined(PQXX_LIBEXPORT) && defined(PQXX_SHARED)
00172 #define PQXX_LIBEXPORT __declspec(dllimport)
00173 #endif  // !PQXX_LIBEXPORT && PQXX_SHARED
00174 
00175 
00176 // Workarounds for Microsoft Visual C++
00177 #ifdef _MSC_VER
00178 
00179 #if _MSC_VER < 1300
00180 #error If you're using Visual C++, you'll need at least version 7 (.NET)
00181 #elif _MSC_VER < 1310
00182 // Workarounds for pre-2003 Visual C++.NET
00183 #undef PQXX_HAVE_REVERSE_ITERATOR
00184 #define PQXX_NO_PARTIAL_CLASS_TEMPLATE_SPECIALISATION
00185 #define PQXX_TYPENAME
00186 #endif  // _MSC_VER < 1310
00187 
00188 // Automatically link with the appropriate libpq (static or dynamic, debug or
00189 // release).  The default is to use the release DLL.  Define PQXX_PQ_STATIC to
00190 // link to a static version of libpq, and _DEBUG to link to a debug version.
00191 // The two may be combined.
00192 #if defined(PQXX_AUTOLINK)
00193 #if defined(PQXX_PQ_STATIC)
00194 #ifdef _DEBUG
00195 #pragma comment(lib, "libpqd")
00196 #else
00197 #pragma comment(lib, "libpq")
00198 #endif
00199 #else
00200 #ifdef _DEBUG
00201 #pragma comment(lib, "libpqddll")
00202 #else
00203 #pragma comment(lib, "libpqdll")
00204 #endif
00205 #endif
00206 #endif
00207 
00208 // If we're not compiling libpqxx itself, automatically link with the correct
00209 // libpqxx library.  To link with the libpqxx DLL, define PQXX_SHARED; the
00210 // default is to link with the static library.  This is also the recommended
00211 // practice.
00212 // Note that the preprocessor macro PQXX_INTERNAL is used to detect whether we
00213 // are compiling the libpqxx library itself. When you compile the library
00214 // yourself using your own project file, make sure to include this define.
00215 #if defined(PQXX_AUTOLINK) && !defined(PQXX_INTERNAL)
00216   #ifdef PQXX_SHARED
00217     #ifdef _DEBUG
00218       #pragma comment(lib, "libpqxxD")
00219     #else
00220       #pragma comment(lib, "libpqxx")
00221     #endif
00222   #else // !PQXX_SHARED
00223     #ifdef _DEBUG
00224       #pragma comment(lib, "libpqxx_staticD")
00225     #else
00226       #pragma comment(lib, "libpqxx_static")
00227     #endif
00228   #endif
00229 #endif
00230 
00232 
00244 #define PQXX_QUIET_DESTRUCTORS
00245 
00246 #endif  // _MSC_VER
00247 #endif  // _WIN32
00248 
00249 #ifndef PQXX_LIBEXPORT
00250 #define PQXX_LIBEXPORT
00251 #endif
00252 
00253 #ifndef PQXX_PRIVATE
00254 #define PQXX_PRIVATE
00255 #endif
00256 
00257 // Some compilers (well, VC) stumble over some required cases of "typename"
00258 #ifndef PQXX_TYPENAME
00259 #define PQXX_TYPENAME typename
00260 #endif
00261 
00262 #ifndef PQXX_NOVTABLE
00263 #define PQXX_NOVTABLE
00264 #endif
00265 
00266 #endif
00267