| 1 | // Backward-compat support -*- C++ -*-
|
|---|
| 2 |
|
|---|
| 3 | // Copyright (C) 2001 Free Software Foundation, Inc.
|
|---|
| 4 | //
|
|---|
| 5 | // This file is part of the GNU ISO C++ Library. This library is free
|
|---|
| 6 | // software; you can redistribute it and/or modify it under the
|
|---|
| 7 | // terms of the GNU General Public License as published by the
|
|---|
| 8 | // Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | // any later version.
|
|---|
| 10 |
|
|---|
| 11 | // This library is distributed in the hope that it will be useful,
|
|---|
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | // GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | // You should have received a copy of the GNU General Public License along
|
|---|
| 17 | // with this library; see the file COPYING. If not, write to the Free
|
|---|
| 18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|---|
| 19 | // USA.
|
|---|
| 20 |
|
|---|
| 21 | // As a special exception, you may use this file as part of a free software
|
|---|
| 22 | // library without restriction. Specifically, if other files instantiate
|
|---|
| 23 | // templates or use macros or inline functions from this file, or you compile
|
|---|
| 24 | // this file and link it with other files to produce an executable, this
|
|---|
| 25 | // file does not by itself cause the resulting executable to be covered by
|
|---|
| 26 | // the GNU General Public License. This exception does not however
|
|---|
| 27 | // invalidate any other reasons why the executable file might be covered by
|
|---|
| 28 | // the GNU General Public License.
|
|---|
| 29 |
|
|---|
| 30 | /*
|
|---|
| 31 | *
|
|---|
| 32 | * Copyright (c) 1994
|
|---|
| 33 | * Hewlett-Packard Company
|
|---|
| 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. Hewlett-Packard Company 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 |
|
|---|
| 45 | // Inclusion of this file is DEPRECATED. This is the original HP
|
|---|
| 46 | // default allocator. It is provided only for backward compatibility.
|
|---|
| 47 | // This file WILL BE REMOVED in a future release.
|
|---|
| 48 | //
|
|---|
| 49 | // DO NOT USE THIS FILE unless you have an old container implementation
|
|---|
| 50 | // that requires an allocator with the HP-style interface.
|
|---|
| 51 | //
|
|---|
| 52 | // Standard-conforming allocators have a very different interface. The
|
|---|
| 53 | // standard default allocator is declared in the header <memory>.
|
|---|
| 54 |
|
|---|
| 55 | #ifndef _CPP_BACKWARD_DEFALLOC_H
|
|---|
| 56 | #define _CPP_BACKWARD_DEFALLOC_H 1
|
|---|
| 57 |
|
|---|
| 58 | #include "backward_warning.h"
|
|---|
| 59 | #include "new.h"
|
|---|
| 60 | #include <stddef.h>
|
|---|
| 61 | #include <stdlib.h>
|
|---|
| 62 | #include <limits.h>
|
|---|
| 63 | #include "iostream.h"
|
|---|
| 64 | #include "algobase.h"
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | template <class _Tp>
|
|---|
| 68 | inline _Tp* allocate(ptrdiff_t __size, _Tp*) {
|
|---|
| 69 | set_new_handler(0);
|
|---|
| 70 | _Tp* __tmp = (_Tp*)(::operator new((size_t)(__size * sizeof(_Tp))));
|
|---|
| 71 | if (__tmp == 0) {
|
|---|
| 72 | cerr << "out of memory" << endl;
|
|---|
| 73 | exit(1);
|
|---|
| 74 | }
|
|---|
| 75 | return __tmp;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | template <class _Tp>
|
|---|
| 80 | inline void deallocate(_Tp* __buffer) {
|
|---|
| 81 | ::operator delete(__buffer);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | template <class _Tp>
|
|---|
| 85 | class allocator {
|
|---|
| 86 | public:
|
|---|
| 87 | typedef _Tp value_type;
|
|---|
| 88 | typedef _Tp* pointer;
|
|---|
| 89 | typedef const _Tp* const_pointer;
|
|---|
| 90 | typedef _Tp& reference;
|
|---|
| 91 | typedef const _Tp& const_reference;
|
|---|
| 92 | typedef size_t size_type;
|
|---|
| 93 | typedef ptrdiff_t difference_type;
|
|---|
| 94 | pointer allocate(size_type __n) {
|
|---|
| 95 | return ::allocate((difference_type)__n, (pointer)0);
|
|---|
| 96 | }
|
|---|
| 97 | void deallocate(pointer __p) { ::deallocate(__p); }
|
|---|
| 98 | pointer address(reference __x) { return (pointer)&__x; }
|
|---|
| 99 | const_pointer const_address(const_reference __x) {
|
|---|
| 100 | return (const_pointer)&__x;
|
|---|
| 101 | }
|
|---|
| 102 | size_type init_page_size() {
|
|---|
| 103 | return max(size_type(1), size_type(4096/sizeof(_Tp)));
|
|---|
| 104 | }
|
|---|
| 105 | size_type max_size() const {
|
|---|
| 106 | return max(size_type(1), size_type(UINT_MAX/sizeof(_Tp)));
|
|---|
| 107 | }
|
|---|
| 108 | };
|
|---|
| 109 |
|
|---|
| 110 | class allocator<void> {
|
|---|
| 111 | public:
|
|---|
| 112 | typedef void* pointer;
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | #endif /* _CPP_BACKWARD_DEFALLOC_H */
|
|---|