merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / postgresql / pq_allocator.hxx
blob8862ce68fafc9a4c2a235ac5eeb73afb7526d80c
1 /*************************************************************************
3 * $RCSfile: pq_allocator.hxx,v $
5 * $Revision: 1.1.2.3 $
7 * last change: $Author: jbu $ $Date: 2007/08/28 21:24:00 $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 * MA 02111-1307 USA
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
53 * Copyright: 2002 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): _______________________________________
60 ************************************************************************/
62 #ifndef _PQ_ALLOCATOR_
63 #define _PQ_ALLOCATOR_
65 #include <cstddef>
66 #include "sal/types.h"
68 /** jbu: This source has been copied from sal/inc/internal/allocator.hxx,
69 because it is not a public interface. Thx a lot for figuring this
70 out.
73 //######################################################
74 // This is no general purpose STL allocator but one
75 // necessary to use STL for some implementation but
76 // avoid linking sal against the STLPort library!!!
77 // For more information on when and how to define a
78 // custom stl allocator have a look at Scott Meyers:
79 // "Effective STL", Nicolai M. Josuttis:
80 // "The C++ Standard Library - A Tutorial and Reference"
81 // and at http://www.josuttis.com/cppcode/allocator.html
83 namespace pq_sdbc_driver {
85 template<class T>
86 class Allocator
88 public:
89 typedef T value_type;
90 typedef T* pointer;
91 typedef const T* const_pointer;
92 typedef T& reference;
93 typedef const T& const_reference;
94 typedef ::std::size_t size_type;
95 typedef ::std::ptrdiff_t difference_type;
97 //-----------------------------------------
98 template<class U>
99 struct rebind
101 typedef Allocator<U> other;
104 //-----------------------------------------
105 pointer address (reference value) const
107 return &value;
110 //-----------------------------------------
111 const_pointer address (const_reference value) const
113 return &value;
116 //-----------------------------------------
117 Allocator() SAL_THROW(())
120 //-----------------------------------------
121 template<class U>
122 Allocator (const Allocator<U>&) SAL_THROW(())
125 //-----------------------------------------
126 Allocator(const Allocator&) SAL_THROW(())
129 //-----------------------------------------
130 ~Allocator() SAL_THROW(())
133 //-----------------------------------------
134 size_type max_size() const SAL_THROW(())
136 return size_type(-1)/sizeof(T);
139 //-----------------------------------------
140 /* Normally the code for allocate should
141 throw a std::bad_alloc exception if the
142 requested memory could not be allocated:
143 (C++ standard 20.4.1.1):
145 pointer allocate (size_type n, const void* hint = 0)
147 pointer p = reinterpret_cast<pointer>(
148 rtl_allocateMemory(sal_uInt32(n * sizeof(T))));
150 if (NULL == p)
151 throw ::std::bad_alloc();
153 return p;
156 but some compilers do not compile it if exceptions
157 are not enabled, e.g. GCC under Linux and it is
158 in general not desired to compile sal with exceptions
159 enabled. */
160 pointer allocate (size_type n, const void* hint = 0)
162 return reinterpret_cast<pointer>(
163 rtl_allocateMemory(sal_uInt32(n * sizeof(T))));
166 //-----------------------------------------
167 void deallocate (pointer p, size_type n)
169 rtl_freeMemory(p);
172 //-----------------------------------------
173 void construct (pointer p, const T& value)
175 new ((void*)p)T(value);
178 //-----------------------------------------
179 void destroy (pointer p)
181 p->~T();
185 //######################################################
186 // Custom STL allocators must be stateless (see
187 // references above) that's why the operators below
188 // return always true or false
189 template<class T, class U>
190 inline bool operator== (const Allocator<T>&, const Allocator<U>&) SAL_THROW(())
192 return true;
195 template<class T, class U>
196 inline bool operator!= (const Allocator<T>&, const Allocator<U>&) SAL_THROW(())
198 return false;
201 } /* namespace sal */
203 //######################################################
204 /* REQUIRED BY STLPort (see stlport '_alloc.h'):
205 Hack for compilers that do not support member
206 template classes (e.g. MSVC 6) */
207 #if defined (_MSC_VER)
208 #if (_MSC_VER < 1400) // MSVC 6
209 namespace _STL
211 #endif
212 #endif
213 template<class T, class U>
214 inline pq_sdbc_driver::Allocator<U> & __stl_alloc_rebind (
215 pq_sdbc_driver::Allocator<T> & a, U const *)
217 return (pq_sdbc_driver::Allocator<U>&)(a);
219 #if defined (_MSC_VER)
220 #if (_MSC_VER < 1400) // MSVC 6
222 #endif
223 #endif
225 #endif /* INCLUDED_SAL_INTERNAL_ALLOCATOR_HXX */