libpqxx 3.1.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-2009, 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 _MSC_VER
25
26 /* Work around a particularly pernicious and deliberate bug in Visual C++:
27 * min() and max() are defined as macros, which can have some very nasty
28 * consequences. This compiler bug can be switched off by defining NOMINMAX.
29 *
30 * We don't like making choices for the user and defining environmental macros
31 * of our own accord, but in this case it's the only way to compile without
32 * incurring a significant risk of bugs--and there doesn't appear to be any
33 * downside. One wonders why this compiler wart is being maintained at all,
34 * since the introduction of inline functions back in the 20th century.
35 */
36 #if defined(min) || defined(max)
37 #error "Oops: min() and/or max() are defined as preprocessor macros.\
38 Define NOMINMAX macro before including any system headers!"
39 #endif
40
41 #ifndef NOMINMAX
42 #define NOMINMAX
43 #endif
44
45 // Suppress vtables on abstract classes.
46 #define PQXX_NOVTABLE __declspec(novtable)
47
48 #endif // _MSC_VER
49
50
51 // Workarounds & definitions that need to be included even in library's headers
52 #include "pqxx/config-public-compiler.h"
53
54
55 #ifdef PQXX_BROKEN_ITERATOR
56 #include <cstddef>
57 #include <cstdlib>
59
67 namespace PGSTD
68 {
70 template<typename Cat,
71 typename T,
72 typename Dist,
73 typename Ptr=T*,
74 typename Ref=T&> struct iterator
75 {
76 typedef Cat iterator_category;
77 typedef T value_type;
78 typedef Dist difference_type;
79 typedef Ptr pointer;
80 typedef Ref reference;
81 };
82 }
83 #else
84 #include <iterator>
85 #endif // PQXX_BROKEN_ITERATOR
86
87 #ifndef PQXX_HAVE_CHAR_TRAITS
88 #include <cstddef>
89 namespace PGSTD
90 {
92 template<typename CHAR> struct char_traits {};
94 template<> struct char_traits<char>
95 {
96 typedef int int_type;
97 typedef size_t pos_type;
98 typedef long off_type;
99 typedef char char_type;
100
101 static int_type eof() { return -1; }
102 };
104 template<> struct char_traits<unsigned char>
105 {
106 typedef int int_type;
107 typedef size_t pos_type;
108 typedef long off_type;
109 typedef unsigned char char_type;
110
111 static int_type eof() { return -1; }
112 };
113 }
114 #endif
115
116 // Workarounds for SUN Workshop 6
117 #if defined(__SUNPRO_CC)
118 #if __SUNPRO_CC_COMPAT < 5
119 #error "This compiler version is not capable of building libpqxx."
120 #endif // __SUNPRO_CC_COMPAT < 5
121 #define PQXX_PRIVATE __hidden
122 #endif // __SUNPRO_CC
123
124
125 // Workarounds for Compaq C++ for Alpha
126 #if defined(__DECCXX_VER)
127 #define __USE_STD_IOSTREAM
128 #endif // __DECCXX_VER
129
130 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_DEPRECATED)
131 #define PQXX_DEPRECATED __attribute__ ((deprecated))
132 #else
133 #define PQXX_DEPRECATED
134 #endif
135
136 // Workarounds for Windows
137 #ifdef _WIN32
138
139
140 /* For now, export DLL symbols if _DLL is defined. This is done automatically
141 * by the compiler when linking to the dynamic version of the runtime library,
142 * according to "gzh"
143 */
144 // TODO: Define custom macro to govern how libpqxx will be linked to client
145 #if !defined(PQXX_LIBEXPORT) && defined(PQXX_SHARED)
146 #define PQXX_LIBEXPORT __declspec(dllimport)
147 #endif // !PQXX_LIBEXPORT && PQXX_SHARED
148
149
150 // Workarounds for Microsoft Visual C++
151 #ifdef _MSC_VER
152
153 #if _MSC_VER < 1300
154 #error If you're using Visual C++, you'll need at least version 7 (.NET)
155 #elif _MSC_VER < 1310
156 // Workarounds for pre-2003 Visual C++.NET
157 #undef PQXX_HAVE_REVERSE_ITERATOR
158 #define PQXX_NO_PARTIAL_CLASS_TEMPLATE_SPECIALISATION
159 #define PQXX_TYPENAME
160 #endif // _MSC_VER < 1310
161
162 // Automatically link with the appropriate libpq (static or dynamic, debug or
163 // release). The default is to use the release DLL. Define PQXX_PQ_STATIC to
164 // link to a static version of libpq, and _DEBUG to link to a debug version.
165 // The two may be combined.
166 #if defined(PQXX_AUTOLINK)
167 #if defined(PQXX_PQ_STATIC)
168 #ifdef _DEBUG
169 #pragma comment(lib, "libpqd")
170 #else
171 #pragma comment(lib, "libpq")
172 #endif
173 #else
174 #ifdef _DEBUG
175 #pragma comment(lib, "libpqddll")
176 #else
177 #pragma comment(lib, "libpqdll")
178 #endif
179 #endif
180 #endif
181
182 // If we're not compiling libpqxx itself, automatically link with the correct
183 // libpqxx library. To link with the libpqxx DLL, define PQXX_SHARED; the
184 // default is to link with the static library. This is also the recommended
185 // practice.
186 // Note that the preprocessor macro PQXX_INTERNAL is used to detect whether we
187 // are compiling the libpqxx library itself. When you compile the library
188 // yourself using your own project file, make sure to include this define.
189 #if defined(PQXX_AUTOLINK) && !defined(PQXX_INTERNAL)
190 #ifdef PQXX_SHARED
191 #ifdef _DEBUG
192 #pragma comment(lib, "libpqxxD")
193 #else
194 #pragma comment(lib, "libpqxx")
195 #endif
196 #else // !PQXX_SHARED
197 #ifdef _DEBUG
198 #pragma comment(lib, "libpqxx_staticD")
199 #else
200 #pragma comment(lib, "libpqxx_static")
201 #endif
202 #endif
203 #endif
204
206
218 #define PQXX_QUIET_DESTRUCTORS
219
220 #endif // _MSC_VER
221 #endif // _WIN32
222
223 #ifndef PQXX_LIBEXPORT
224 #define PQXX_LIBEXPORT
225 #endif
226
227 #ifndef PQXX_PRIVATE
228 #define PQXX_PRIVATE
229 #endif
230
231 // Some compilers (well, VC) stumble over some required cases of "typename"
232 #ifndef PQXX_TYPENAME
233 #define PQXX_TYPENAME typename
234 #endif
235
236 #ifndef PQXX_NOVTABLE
237 #define PQXX_NOVTABLE
238 #endif
239
240 #endif
241