LCOV - code coverage report
Current view: directory - usr/include/c++/4.2.1/bits - allocator.h (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 5 5 100.0 %
Date: 2014-06-18 Functions: 0 0 -

       1                 : // Allocators -*- C++ -*-
       2                 : 
       3                 : // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
       4                 : // Free Software Foundation, Inc.
       5                 : //
       6                 : // This file is part of the GNU ISO C++ Library.  This library is free
       7                 : // software; you can redistribute it and/or modify it under the
       8                 : // terms of the GNU General Public License as published by the
       9                 : // Free Software Foundation; either version 2, or (at your option)
      10                 : // any later version.
      11                 : 
      12                 : // This library is distributed in the hope that it will be useful,
      13                 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 : // GNU General Public License for more details.
      16                 : 
      17                 : // You should have received a copy of the GNU General Public License along
      18                 : // with this library; see the file COPYING.  If not, write to the Free
      19                 : // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
      20                 : // USA.
      21                 : 
      22                 : // As a special exception, you may use this file as part of a free software
      23                 : // library without restriction.  Specifically, if other files instantiate
      24                 : // templates or use macros or inline functions from this file, or you compile
      25                 : // this file and link it with other files to produce an executable, this
      26                 : // file does not by itself cause the resulting executable to be covered by
      27                 : // the GNU General Public License.  This exception does not however
      28                 : // invalidate any other reasons why the executable file might be covered by
      29                 : // the GNU General Public License.
      30                 : 
      31                 : /*
      32                 :  * Copyright (c) 1996-1997
      33                 :  * Silicon Graphics Computer Systems, Inc.
      34                 :  *
      35                 :  * Permission to use, copy, modify, distribute and sell this software
      36                 :  * and its documentation for any purpose is hereby granted without fee,
      37                 :  * provided that the above copyright notice appear in all copies and
      38                 :  * that both that copyright notice and this permission notice appear
      39                 :  * in supporting documentation.  Silicon Graphics makes no
      40                 :  * representations about the suitability of this software for any
      41                 :  * purpose.  It is provided "as is" without express or implied warranty.
      42                 :  */
      43                 : 
      44                 : /** @file allocator.h
      45                 :  *  This is an internal header file, included by other library headers.
      46                 :  *  You should not attempt to use it directly.
      47                 :  */
      48                 : 
      49                 : #ifndef _ALLOCATOR_H
      50                 : #define _ALLOCATOR_H 1
      51                 : 
      52                 : // Define the base class to std::allocator.
      53                 : #include <bits/c++allocator.h>
      54                 : 
      55                 : #include <bits/cpp_type_traits.h> // for __is_empty
      56                 : 
      57                 : _GLIBCXX_BEGIN_NAMESPACE(std)
      58                 : 
      59                 :   template<typename _Tp>
      60                 :     class allocator;
      61                 : 
      62                 :   /// allocator<void> specialization.
      63                 :   template<>
      64                 :     class allocator<void>
      65                 :     {
      66                 :     public:
      67                 :       typedef size_t      size_type;
      68                 :       typedef ptrdiff_t   difference_type;
      69                 :       typedef void*       pointer;
      70                 :       typedef const void* const_pointer;
      71                 :       typedef void        value_type;
      72                 : 
      73                 :       template<typename _Tp1>
      74                 :         struct rebind
      75                 :         { typedef allocator<_Tp1> other; };
      76                 :     };
      77                 : 
      78                 :   /**
      79                 :    * @brief  The "standard" allocator, as per [20.4].
      80                 :    *
      81                 :    *  Further details:
      82                 :    *  http://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html
      83                 :    */
      84                 :   template<typename _Tp>
      85                 :     class allocator: public __glibcxx_base_allocator<_Tp>
      86                 :     {
      87                 :    public:
      88                 :       typedef size_t     size_type;
      89                 :       typedef ptrdiff_t  difference_type;
      90                 :       typedef _Tp*       pointer;
      91                 :       typedef const _Tp* const_pointer;
      92                 :       typedef _Tp&       reference;
      93                 :       typedef const _Tp& const_reference;
      94                 :       typedef _Tp        value_type;
      95                 : 
      96                 :       template<typename _Tp1>
      97                 :         struct rebind
      98                 :         { typedef allocator<_Tp1> other; };
      99                 : 
     100           43406 :       allocator() throw() { }
     101                 : 
     102          160987 :       allocator(const allocator& __a) throw()
     103          160987 :       : __glibcxx_base_allocator<_Tp>(__a) { }
     104                 : 
     105                 :       template<typename _Tp1>
     106           22466 :         allocator(const allocator<_Tp1>&) throw() { }
     107                 : 
     108          226760 :       ~allocator() throw() { }
     109                 : 
     110                 :       // Inherit everything else.
     111                 :     };
     112                 : 
     113                 :   template<typename _T1, typename _T2>
     114                 :     inline bool
     115                 :     operator==(const allocator<_T1>&, const allocator<_T2>&)
     116                 :     { return true; }
     117                 : 
     118                 :   template<typename _T1, typename _T2>
     119                 :     inline bool
     120                 :     operator!=(const allocator<_T1>&, const allocator<_T2>&)
     121                 :     { return false; }
     122                 : 
     123                 :   // Inhibit implicit instantiations for required instantiations,
     124                 :   // which are defined via explicit instantiations elsewhere.
     125                 :   // NB: This syntax is a GNU extension.
     126                 : #if _GLIBCXX_EXTERN_TEMPLATE
     127                 :   extern template class allocator<char>;
     128                 :   extern template class allocator<wchar_t>;
     129                 : #endif
     130                 : 
     131                 :   // Undefine.
     132                 : #undef __glibcxx_base_allocator
     133                 : 
     134                 :   // To implement Option 3 of DR 431.
     135                 :   template<typename _Alloc, bool = std::__is_empty<_Alloc>::__value>
     136                 :     struct __alloc_swap
     137                 :     { static void _S_do_it(_Alloc&, _Alloc&) { } };
     138                 : 
     139                 :   template<typename _Alloc>
     140                 :     struct __alloc_swap<_Alloc, false>
     141                 :     {
     142                 :       static void
     143                 :       _S_do_it(_Alloc& __one, _Alloc& __two)
     144                 :       {
     145                 :         // Precondition: swappable allocators.
     146                 :         if (__one != __two)
     147                 :           swap(__one, __two);
     148                 :       }
     149                 :     };
     150                 : 
     151                 : _GLIBCXX_END_NAMESPACE
     152                 : 
     153                 : #endif

Generated by: LCOV version 1.7