1 /*************************************************************************
3 * $RCSfile: pq_allocator.hxx,v $
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,
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_
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
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
{
91 typedef const T
* const_pointer
;
93 typedef const T
& const_reference
;
94 typedef ::std::size_t size_type
;
95 typedef ::std::ptrdiff_t difference_type
;
97 //-----------------------------------------
101 typedef Allocator
<U
> other
;
104 //-----------------------------------------
105 pointer
address (reference value
) const
110 //-----------------------------------------
111 const_pointer
address (const_reference value
) const
116 //-----------------------------------------
117 Allocator() SAL_THROW(())
120 //-----------------------------------------
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))));
151 throw ::std::bad_alloc();
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
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
)
172 //-----------------------------------------
173 void construct (pointer p
, const T
& value
)
175 new ((void*)p
)T(value
);
178 //-----------------------------------------
179 void destroy (pointer p
)
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(())
195 template<class T
, class U
>
196 inline bool operator!= (const Allocator
<T
>&, const Allocator
<U
>&) SAL_THROW(())
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
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
225 #endif /* INCLUDED_SAL_INTERNAL_ALLOCATOR_HXX */