1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2002 by Sun Microsystems, Inc.
27 * All parts contributed on or after August 2011:
29 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
31 * The contents of this file are subject to the Mozilla Public License Version
32 * 1.1 (the "License"); you may not use this file except in compliance with
33 * the License or as specified alternatively below. You may obtain a copy of
34 * the License at http://www.mozilla.org/MPL/
36 * Software distributed under the License is distributed on an "AS IS" basis,
37 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
38 * for the specific language governing rights and limitations under the
41 * Major Contributor(s):
42 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
44 * All Rights Reserved.
46 * For minor contributions see the git repository.
48 * Alternatively, the contents of this file may be used under the terms of
49 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
50 * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
51 * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
52 * instead of those above.
54 ************************************************************************/
56 #ifndef _PQ_ALLOCATOR_
57 #define _PQ_ALLOCATOR_
60 #include "sal/types.h"
62 /** jbu: This source has been copied from sal/inc/internal/allocator.hxx,
63 because it is not a public interface. Thx a lot for figuring this
67 //######################################################
68 // This is no general purpose STL allocator but one
69 // necessary to use STL for some implementation but
70 // avoid linking sal against the STLPort library!!!
71 // For more information on when and how to define a
72 // custom stl allocator have a look at Scott Meyers:
73 // "Effective STL", Nicolai M. Josuttis:
74 // "The C++ Standard Library - A Tutorial and Reference"
75 // and at http://www.josuttis.com/cppcode/allocator.html
77 namespace pq_sdbc_driver
{
85 typedef const T
* const_pointer
;
87 typedef const T
& const_reference
;
88 typedef ::std::size_t size_type
;
89 typedef ::std::ptrdiff_t difference_type
;
91 //-----------------------------------------
95 typedef Allocator
<U
> other
;
98 //-----------------------------------------
99 pointer
address (reference value
) const
104 //-----------------------------------------
105 const_pointer
address (const_reference value
) const
110 //-----------------------------------------
111 Allocator() SAL_THROW(())
114 //-----------------------------------------
116 Allocator (const Allocator
<U
>&) SAL_THROW(())
119 //-----------------------------------------
120 Allocator(const Allocator
&) SAL_THROW(())
123 //-----------------------------------------
124 ~Allocator() SAL_THROW(())
127 //-----------------------------------------
128 size_type
max_size() const SAL_THROW(())
130 return size_type(-1)/sizeof(T
);
133 //-----------------------------------------
134 /* Normally the code for allocate should
135 throw a std::bad_alloc exception if the
136 requested memory could not be allocated:
137 (C++ standard 20.4.1.1):
139 pointer allocate (size_type n, const void* hint = 0)
141 pointer p = reinterpret_cast<pointer>(
142 rtl_allocateMemory(sal_uInt32(n * sizeof(T))));
145 throw ::std::bad_alloc();
150 but some compilers do not compile it if exceptions
151 are not enabled, e.g. GCC under Linux and it is
152 in general not desired to compile sal with exceptions
154 pointer
allocate (size_type n
, SAL_UNUSED_PARAMETER
const void* = 0)
156 return reinterpret_cast<pointer
>(
157 rtl_allocateMemory(sal_uInt32(n
* sizeof(T
))));
160 //-----------------------------------------
161 void deallocate (pointer p
, SAL_UNUSED_PARAMETER size_type
)
166 //-----------------------------------------
167 void construct (pointer p
, const T
& value
)
169 new ((void*)p
)T(value
);
172 // LEM: GNU libstdc++ vectors expect this one to exist,
173 // at least if one intends to create vectors by giving
174 // only a size and no initialising value.
175 //-----------------------------------------
176 void construct (pointer p
)
181 //-----------------------------------------
182 void destroy (pointer p
)
186 (void) p
; // spurious warning C4100: 'p': unreferenced formal parameter
191 //######################################################
192 // Custom STL allocators must be stateless (see
193 // references above) that's why the operators below
194 // return always true or false
195 template<class T
, class U
>
196 inline bool operator== (const Allocator
<T
>&, const Allocator
<U
>&) SAL_THROW(())
201 template<class T
, class U
>
202 inline bool operator!= (const Allocator
<T
>&, const Allocator
<U
>&) SAL_THROW(())
207 } /* namespace sal */
209 //######################################################
210 /* REQUIRED BY STLPort (see stlport '_alloc.h'):
211 Hack for compilers that do not support member
212 template classes (e.g. MSVC 6) */
213 #if defined (_MSC_VER)
214 #if (_MSC_VER < 1400) // MSVC 6
219 template<class T
, class U
>
220 inline pq_sdbc_driver::Allocator
<U
> & __stl_alloc_rebind (
221 pq_sdbc_driver::Allocator
<T
> & a
, U
const *)
223 return (pq_sdbc_driver::Allocator
<U
>&)(a
);
225 #if defined (_MSC_VER)
226 #if (_MSC_VER < 1400) // MSVC 6
231 #endif /* _PQ_ALLOCATOR_ */