libpqxx 4.0.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

compiler-public.hxx
1 /*-------------------------------------------------------------------------
2 *
3 * FILE
4 * pqxx/compiler-public.hxx
5 *
6 * DESCRIPTION
7 * Compiler deficiency workarounds for libpqxx clients
8 *
9 * Copyright (c) 2002-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
10 *
11 * See COPYING for copyright license. If you did not receive a file called
12 * COPYING with this source code, please notify the distributor of this mistake,
13 * or contact the author.
14 *
15 *-------------------------------------------------------------------------
16 */
17 #ifndef PQXX_H_COMPILER_PUBLIC
18 #define PQXX_H_COMPILER_PUBLIC
19
20 #ifdef PQXX_HAVE_BOOST_SMART_PTR
21 #include <boost/smart_ptr.hpp>
22 #endif
23
24 #ifdef PQXX_HAVE_MOVE
25 #include <utility>
26 #define PQXX_MOVE(value) (PGSTD::move(value))
27 #else
28 #define PQXX_MOVE(value) (value)
29 #endif
30
31 #ifdef _MSC_VER
32
33 /* Work around a particularly pernicious and deliberate bug in Visual C++:
34 * min() and max() are defined as macros, which can have some very nasty
35 * consequences. This compiler bug can be switched off by defining NOMINMAX.
36 *
37 * We don't like making choices for the user and defining environmental macros
38 * of our own accord, but in this case it's the only way to compile without
39 * incurring a significant risk of bugs--and there doesn't appear to be any
40 * downside. One wonders why this compiler wart is being maintained at all,
41 * since the introduction of inline functions back in the 20th century.
42 */
43 #if defined(min) || defined(max)
44 #error "Oops: min() and/or max() are defined as preprocessor macros.\
45 Define NOMINMAX macro before including any system headers!"
46 #endif
47
48 #ifndef NOMINMAX
49 #define NOMINMAX
50 #endif
51
52 // Suppress vtables on abstract classes.
53 #define PQXX_NOVTABLE __declspec(novtable)
54
55 #endif // _MSC_VER
56
57
58 // Workarounds & definitions that need to be included even in library's headers
59 #include "pqxx/config-public-compiler.h"
60
61
62 #ifdef PQXX_BROKEN_ITERATOR
63 #include <cstddef>
64 #include <cstdlib>
66
74 namespace PGSTD
75 {
77 template<typename Cat,
78 typename T,
79 typename Dist,
80 typename Ptr=T*,
81 typename Ref=T&> struct iterator
82 {
83 typedef Cat iterator_category;
84 typedef T value_type;
85 typedef Dist difference_type;
86 typedef Ptr pointer;
87 typedef Ref reference;
88 };
89 }
90 #else
91 #include <iterator>
92 #endif // PQXX_BROKEN_ITERATOR
93
94 #ifndef PQXX_HAVE_CHAR_TRAITS
95 #include <cstddef>
96 namespace PGSTD
97 {
99 template<typename CHAR> struct char_traits {};
101 template<> struct char_traits<char>
102 {
103 typedef int int_type;
104 typedef size_t pos_type;
105 typedef long off_type;
106 typedef char char_type;
107
108 static int_type eof() { return -1; }
109 };
111 template<> struct char_traits<unsigned char>
112 {
113 typedef int int_type;
114 typedef size_t pos_type;
115 typedef long off_type;
116 typedef unsigned char char_type;
117
118 static int_type eof() { return -1; }
119 };
120 }
121 #endif
122
123 // Workarounds for SUN Workshop 6
124 #if defined(__SUNPRO_CC)
125 #if __SUNPRO_CC_COMPAT < 5
126 #error "This compiler version is not capable of building libpqxx."
127 #endif // __SUNPRO_CC_COMPAT < 5
128 #define PQXX_PRIVATE __hidden
129 #endif // __SUNPRO_CC
130
131
132 // Workarounds for Compaq C++ for Alpha
133 #if defined(__DECCXX_VER)
134 #define __USE_STD_IOSTREAM
135 #endif // __DECCXX_VER
136
137 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_CONST)
138 #define PQXX_CONST __attribute__ ((const))
139 #else
140 #define PQXX_CONST
141 #endif
142
143 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_DEPRECATED)
144 #define PQXX_DEPRECATED __attribute__ ((deprecated))
145 #else
146 #define PQXX_DEPRECATED
147 #endif
148
149 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_NORETURN)
150 #define PQXX_NORETURN __attribute__ ((noreturn))
151 #else
152 #define PQXX_NORETURN
153 #endif
154
155 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_PURE)
156 #define PQXX_PURE __attribute__ ((pure))
157 #else
158 #define PQXX_PURE
159 #endif
160
161
162 // Workarounds for Windows
163 #ifdef _WIN32
164
165
166 /* For now, export DLL symbols if _DLL is defined. This is done automatically
167 * by the compiler when linking to the dynamic version of the runtime library,
168 * according to "gzh"
169 */
170 // TODO: Define custom macro to govern how libpqxx will be linked to client
171 #if !defined(PQXX_LIBEXPORT) && defined(PQXX_SHARED)
172 #define PQXX_LIBEXPORT __declspec(dllimport)
173 #endif // !PQXX_LIBEXPORT && PQXX_SHARED
174
175
176 // Workarounds for Microsoft Visual C++
177 #ifdef _MSC_VER
178
179 #if _MSC_VER < 1300
180 #error If you're using Visual C++, you'll need at least version 7 (.NET)
181 #elif _MSC_VER < 1310
182 // Workarounds for pre-2003 Visual C++.NET
183 #undef PQXX_HAVE_REVERSE_ITERATOR
184 #define PQXX_NO_PARTIAL_CLASS_TEMPLATE_SPECIALISATION
185 #define PQXX_TYPENAME
186 #endif // _MSC_VER < 1310
187
188 // Automatically link with the appropriate libpq (static or dynamic, debug or
189 // release). The default is to use the release DLL. Define PQXX_PQ_STATIC to
190 // link to a static version of libpq, and _DEBUG to link to a debug version.
191 // The two may be combined.
192 #if defined(PQXX_AUTOLINK)
193 #if defined(PQXX_PQ_STATIC)
194 #ifdef _DEBUG
195 #pragma comment(lib, "libpqd")
196 #else
197 #pragma comment(lib, "libpq")
198 #endif
199 #else
200 #ifdef _DEBUG
201 #pragma comment(lib, "libpqddll")
202 #else
203 #pragma comment(lib, "libpqdll")
204 #endif
205 #endif
206 #endif
207
208 // If we're not compiling libpqxx itself, automatically link with the correct
209 // libpqxx library. To link with the libpqxx DLL, define PQXX_SHARED; the
210 // default is to link with the static library. This is also the recommended
211 // practice.
212 // Note that the preprocessor macro PQXX_INTERNAL is used to detect whether we
213 // are compiling the libpqxx library itself. When you compile the library
214 // yourself using your own project file, make sure to include this define.
215 #if defined(PQXX_AUTOLINK) && !defined(PQXX_INTERNAL)
216 #ifdef PQXX_SHARED
217 #ifdef _DEBUG
218 #pragma comment(lib, "libpqxxD")
219 #else
220 #pragma comment(lib, "libpqxx")
221 #endif
222 #else // !PQXX_SHARED
223 #ifdef _DEBUG
224 #pragma comment(lib, "libpqxx_staticD")
225 #else
226 #pragma comment(lib, "libpqxx_static")
227 #endif
228 #endif
229 #endif
230
232
244 #define PQXX_QUIET_DESTRUCTORS
245
246 #endif // _MSC_VER
247 #endif // _WIN32
248
249 #ifndef PQXX_LIBEXPORT
250 #define PQXX_LIBEXPORT
251 #endif
252
253 #ifndef PQXX_PRIVATE
254 #define PQXX_PRIVATE
255 #endif
256
257 // Some compilers (well, VC) stumble over some required cases of "typename"
258 #ifndef PQXX_TYPENAME
259 #define PQXX_TYPENAME typename
260 #endif
261
262 #ifndef PQXX_NOVTABLE
263 #define PQXX_NOVTABLE
264 #endif
265
266 #endif
267