197403Sobrien// Backward-compat support -*- C++ -*-
297403Sobrien
397403Sobrien// Copyright (C) 2001 Free Software Foundation, Inc.
497403Sobrien//
597403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
697403Sobrien// software; you can redistribute it and/or modify it under the
797403Sobrien// terms of the GNU General Public License as published by the
897403Sobrien// Free Software Foundation; either version 2, or (at your option)
997403Sobrien// any later version.
1097403Sobrien
1197403Sobrien// This library is distributed in the hope that it will be useful,
1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1497403Sobrien// GNU General Public License for more details.
1597403Sobrien
1697403Sobrien// You should have received a copy of the GNU General Public License along
1797403Sobrien// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1997403Sobrien// USA.
2097403Sobrien
2197403Sobrien// As a special exception, you may use this file as part of a free software
2297403Sobrien// library without restriction.  Specifically, if other files instantiate
2397403Sobrien// templates or use macros or inline functions from this file, or you compile
2497403Sobrien// this file and link it with other files to produce an executable, this
2597403Sobrien// file does not by itself cause the resulting executable to be covered by
2697403Sobrien// the GNU General Public License.  This exception does not however
2797403Sobrien// invalidate any other reasons why the executable file might be covered by
2897403Sobrien// the GNU General Public License.
2997403Sobrien
3097403Sobrien/*
3197403Sobrien *
3297403Sobrien * Copyright (c) 1994
3397403Sobrien * Hewlett-Packard Company
3497403Sobrien *
3597403Sobrien * Permission to use, copy, modify, distribute and sell this software
3697403Sobrien * and its documentation for any purpose is hereby granted without fee,
3797403Sobrien * provided that the above copyright notice appear in all copies and
3897403Sobrien * that both that copyright notice and this permission notice appear
3997403Sobrien * in supporting documentation.  Hewlett-Packard Company makes no
4097403Sobrien * representations about the suitability of this software for any
4197403Sobrien * purpose.  It is provided "as is" without express or implied warranty.
4297403Sobrien *
4397403Sobrien */
4497403Sobrien
4597403Sobrien// Inclusion of this file is DEPRECATED.  This is the original HP
4697403Sobrien// default allocator.  It is provided only for backward compatibility.
4797403Sobrien// This file WILL BE REMOVED in a future release.
4897403Sobrien//
4997403Sobrien// DO NOT USE THIS FILE unless you have an old container implementation
50132720Skan// that requires an allocator with the HP-style interface.
5197403Sobrien//
5297403Sobrien// Standard-conforming allocators have a very different interface.  The
5397403Sobrien// standard default allocator is declared in the header <memory>.
5497403Sobrien
55132720Skan#ifndef _BACKWARD_DEFALLOC_H
56132720Skan#define _BACKWARD_DEFALLOC_H 1
5797403Sobrien
5897403Sobrien#include "backward_warning.h"
5997403Sobrien#include "new.h"
6097403Sobrien#include <stddef.h>
6197403Sobrien#include <stdlib.h>
62132720Skan#include <limits.h>
63132720Skan#include "iostream.h"
6497403Sobrien#include "algobase.h"
6597403Sobrien
6697403Sobrien
6797403Sobrientemplate <class _Tp>
6897403Sobrieninline _Tp* allocate(ptrdiff_t __size, _Tp*) {
6997403Sobrien    set_new_handler(0);
7097403Sobrien    _Tp* __tmp = (_Tp*)(::operator new((size_t)(__size * sizeof(_Tp))));
7197403Sobrien    if (__tmp == 0) {
72132720Skan	cerr << "out of memory" << endl;
7397403Sobrien	exit(1);
7497403Sobrien    }
7597403Sobrien    return __tmp;
7697403Sobrien}
7797403Sobrien
7897403Sobrien
7997403Sobrientemplate <class _Tp>
8097403Sobrieninline void deallocate(_Tp* __buffer) {
8197403Sobrien    ::operator delete(__buffer);
8297403Sobrien}
8397403Sobrien
8497403Sobrientemplate <class _Tp>
8597403Sobrienclass allocator {
8697403Sobrienpublic:
8797403Sobrien    typedef _Tp value_type;
8897403Sobrien    typedef _Tp* pointer;
8997403Sobrien    typedef const _Tp* const_pointer;
9097403Sobrien    typedef _Tp& reference;
9197403Sobrien    typedef const _Tp& const_reference;
9297403Sobrien    typedef size_t size_type;
9397403Sobrien    typedef ptrdiff_t difference_type;
94132720Skan    pointer allocate(size_type __n) {
9597403Sobrien	return ::allocate((difference_type)__n, (pointer)0);
9697403Sobrien    }
9797403Sobrien    void deallocate(pointer __p) { ::deallocate(__p); }
9897403Sobrien    pointer address(reference __x) { return (pointer)&__x; }
99132720Skan    const_pointer const_address(const_reference __x) {
100132720Skan	return (const_pointer)&__x;
10197403Sobrien    }
102132720Skan    size_type init_page_size() {
103132720Skan	return max(size_type(1), size_type(4096/sizeof(_Tp)));
10497403Sobrien    }
105132720Skan    size_type max_size() const {
106132720Skan	return max(size_type(1), size_type(UINT_MAX/sizeof(_Tp)));
10797403Sobrien    }
10897403Sobrien};
10997403Sobrien
11097403Sobrienclass allocator<void> {
11197403Sobrienpublic:
11297403Sobrien    typedef void* pointer;
11397403Sobrien};
11497403Sobrien
11597403Sobrien
11697403Sobrien
117132720Skan#endif /* _BACKWARD_DEFALLOC_H */
118