LCOV - code coverage report
Current view: top level - connectivity/source/drivers/postgresql - pq_allocator.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 26 0.0 %
Date: 2014-04-11 Functions: 0 123 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  Effective License of whole file:
       5             :  *
       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.
       9             :  *
      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.
      14             :  *
      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,
      18             :  *    MA  02111-1307  USA
      19             :  *
      20             :  *  Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
      21             :  *
      22             :  *    The Contents of this file are made available subject to the terms of
      23             :  *    the GNU Lesser General Public License Version 2.1
      24             :  *
      25             :  *    Copyright: 2002 by Sun Microsystems, Inc.
      26             :  *
      27             :  *  All parts contributed on or after August 2011:
      28             :  *
      29             :  *    This Source Code Form is subject to the terms of the Mozilla Public
      30             :  *    License, v. 2.0. If a copy of the MPL was not distributed with this
      31             :  *    file, You can obtain one at http://mozilla.org/MPL/2.0/.
      32             :  *
      33             :  ************************************************************************/
      34             : 
      35             : #ifndef _PQ_ALLOCATOR_
      36             : #define _PQ_ALLOCATOR_
      37             : 
      38             : #include <cstddef>
      39             : #include "sal/types.h"
      40             : 
      41             : /** jbu: This source has been copied from sal/inc/internal/allocator.hxx,
      42             :          because it is not a public interface. Thx a lot for figuring this
      43             :          out.
      44             :  */
      45             : 
      46             : 
      47             : // This is no general purpose STL allocator but one
      48             : // necessary to use STL for some implementation but
      49             : // avoid linking sal against the STLPort library!!!
      50             : // For more information on when and how to define a
      51             : // custom stl allocator have a look at Scott Meyers:
      52             : // "Effective STL", Nicolai M. Josuttis:
      53             : // "The C++ Standard Library - A Tutorial and Reference"
      54             : // and at http://www.josuttis.com/cppcode/allocator.html
      55             : 
      56             : namespace pq_sdbc_driver {
      57             : 
      58             : template<class T>
      59             : class Allocator
      60             : {
      61             : public:
      62             :     typedef T value_type;
      63             :     typedef T* pointer;
      64             :     typedef const T* const_pointer;
      65             :     typedef T& reference;
      66             :     typedef const T& const_reference;
      67             :     typedef ::std::size_t size_type;
      68             :     typedef ::std::ptrdiff_t difference_type;
      69             : 
      70             : 
      71             :     template<class U>
      72             :     struct rebind
      73             :     {
      74             :         typedef Allocator<U> other;
      75             :     };
      76             : 
      77             : 
      78             :     pointer address (reference value) const
      79             :     {
      80             :         return &value;
      81             :     }
      82             : 
      83             : 
      84             :     const_pointer address (const_reference value) const
      85             :     {
      86             :         return &value;
      87             :     }
      88             : 
      89             : 
      90           0 :     Allocator() SAL_THROW(())
      91           0 :     {}
      92             : 
      93             : 
      94             :     template<class U>
      95           0 :     Allocator (const Allocator<U>&) SAL_THROW(())
      96           0 :     {}
      97             : 
      98             : 
      99           0 :     Allocator(const Allocator&) SAL_THROW(())
     100           0 :     {}
     101             : 
     102             : 
     103           0 :     ~Allocator() SAL_THROW(())
     104           0 :     {}
     105             : 
     106             : 
     107           0 :     size_type max_size() const SAL_THROW(())
     108             :     {
     109           0 :         return size_type(-1)/sizeof(T);
     110             :     }
     111             : 
     112             : 
     113             :     /* Normally the code for allocate should
     114             :        throw a std::bad_alloc exception if the
     115             :        requested memory could not be allocated:
     116             :        (C++ standard 20.4.1.1):
     117             : 
     118             :        pointer allocate (size_type n, const void* hint = 0)
     119             :        {
     120             :          pointer p = reinterpret_cast<pointer>(
     121             :              rtl_allocateMemory(sal_uInt32(n * sizeof(T))));
     122             : 
     123             :          if (NULL == p)
     124             :              throw ::std::bad_alloc();
     125             : 
     126             :          return p;
     127             :        }
     128             : 
     129             :        but some compilers do not compile it if exceptions
     130             :        are not enabled, e.g. GCC under Linux and it is
     131             :        in general not desired to compile sal with exceptions
     132             :        enabled. */
     133           0 :     pointer allocate (size_type n, SAL_UNUSED_PARAMETER const void* = 0)
     134             :     {
     135             :         return reinterpret_cast<pointer>(
     136           0 :             rtl_allocateMemory(sal_uInt32(n * sizeof(T))));
     137             :     }
     138             : 
     139             : 
     140           0 :     void deallocate (pointer p, SAL_UNUSED_PARAMETER size_type)
     141             :     {
     142           0 :         rtl_freeMemory(p);
     143           0 :     }
     144             : 
     145             : 
     146           0 :     void construct (pointer p, const T& value)
     147             :     {
     148           0 :         new ((void*)p)T(value);
     149           0 :     }
     150             : 
     151             :     // LEM: GNU libstdc++ vectors expect this one to exist,
     152             :     // at least if one intends to create vectors by giving
     153             :     // only a size and no initialising value.
     154             : 
     155           0 :     void construct (pointer p)
     156             :     {
     157           0 :         new ((void*)p)T;
     158           0 :     }
     159             : 
     160             : 
     161           0 :     void destroy (pointer p)
     162             :     {
     163           0 :         p->~T();
     164             : #ifdef _MSC_VER
     165             :         (void) p; // spurious warning C4100: 'p': unreferenced formal parameter
     166             : #endif
     167           0 :     }
     168             : };
     169             : 
     170             : 
     171             : // Custom STL allocators must be stateless (see
     172             : // references above) that's why the operators below
     173             : // return always true or false
     174             : template<class T, class U>
     175           0 : inline bool operator== (const Allocator<T>&, const Allocator<U>&) SAL_THROW(())
     176             : {
     177           0 :     return true;
     178             : }
     179             : 
     180             : template<class T, class U>
     181             : inline bool operator!= (const Allocator<T>&, const Allocator<U>&) SAL_THROW(())
     182             : {
     183             :     return false;
     184             : }
     185             : 
     186             : } /* namespace sal */
     187             : 
     188             : #endif /* _PQ_ALLOCATOR_ */
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10