1 | /** @file
|
---|
2 | * IPRT / No-CRT - Minimal C++ std::memory.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_nocrt_memory
|
---|
27 | #define IPRT_INCLUDED_nocrt_memory
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/nocrt/cstddef>
|
---|
33 | #include <iprt/nocrt/new>
|
---|
34 |
|
---|
35 | namespace std
|
---|
36 | {
|
---|
37 | /**
|
---|
38 | * Simple allocator - not C++11 compliant.
|
---|
39 | */
|
---|
40 | template<class a_Type> class allocator
|
---|
41 | {
|
---|
42 | public:
|
---|
43 | typedef a_Type value_type;
|
---|
44 | typedef a_Type const &const_reference;
|
---|
45 | typedef a_Type *pointer;
|
---|
46 | typedef a_Type const *const_pointer;
|
---|
47 | typedef std::size_t size_type;
|
---|
48 | typedef std::ptrdiff_t difference_type;
|
---|
49 |
|
---|
50 | public:
|
---|
51 | allocator() RT_NOEXCEPT
|
---|
52 | { }
|
---|
53 |
|
---|
54 | allocator(allocator const &a_rThat) RT_NOEXCEPT
|
---|
55 | { RT_NOREF(a_rThat); }
|
---|
56 |
|
---|
57 | ~allocator()
|
---|
58 | { }
|
---|
59 |
|
---|
60 | a_Type *allocate(size_type a_cItems, const void *a_pvHint = NULL)
|
---|
61 | {
|
---|
62 | RT_NOREF(a_pvHint);
|
---|
63 | Assert(a_cItems <= max_size()); /** @todo throw stuff */
|
---|
64 | return static_cast<pointer>(::operator new(sizeof(value_type) * a_cItems));
|
---|
65 | }
|
---|
66 |
|
---|
67 | void deallocate(a_Type *a_paItems, size_type a_cItems)
|
---|
68 | {
|
---|
69 | if (a_paItems && a_cItems > 0)
|
---|
70 | ::operator delete(a_paItems);
|
---|
71 | }
|
---|
72 |
|
---|
73 | size_type max_size() const
|
---|
74 | {
|
---|
75 | /* whatever */
|
---|
76 | #if ARCH_BITS >= 64
|
---|
77 | return _4G / sizeof(value_type);
|
---|
78 | #else
|
---|
79 | return _512M / sizeof(value_type);
|
---|
80 | #endif
|
---|
81 | }
|
---|
82 |
|
---|
83 | void construct(pointer a_pDst, const_reference a_rSrc)
|
---|
84 | {
|
---|
85 | ::new (static_cast<void *>(a_pDst)) a_Type(a_rSrc);
|
---|
86 | }
|
---|
87 |
|
---|
88 | void destroy(pointer a_pDst)
|
---|
89 | {
|
---|
90 | a_pDst->~value_type();
|
---|
91 | }
|
---|
92 | };
|
---|
93 |
|
---|
94 | /** @todo make_unique and unique */
|
---|
95 | }
|
---|
96 |
|
---|
97 | #endif /* !IPRT_INCLUDED_nocrt_memory */
|
---|
98 |
|
---|