2015-11-13 17:17:37 +11:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2015-11-13 17:17:37 +11:00
|
|
|
*
|
|
|
|
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
2018-12-19 17:55:24 +11:00
|
|
|
#pragma once
|
2015-11-13 17:17:37 +11:00
|
|
|
|
2018-12-19 17:55:24 +11:00
|
|
|
#include "../view.hpp"
|
2018-02-28 17:55:56 +11:00
|
|
|
|
2015-11-13 17:17:37 +11:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
|
2018-12-19 17:55:24 +11:00
|
|
|
namespace cruft::alloc {
|
2015-11-13 17:17:37 +11:00
|
|
|
// allocator that always fails, throwing bad_alloc. deallocate will
|
|
|
|
// succeed with nullptr as with delete, but is undefined with other values
|
|
|
|
// (it is likely to at least assert).
|
|
|
|
class null {
|
|
|
|
public:
|
2016-10-10 20:59:26 +11:00
|
|
|
null () = default;
|
|
|
|
null (const null&) = delete;
|
|
|
|
null& operator= (const null&) = delete;
|
2016-02-10 14:04:08 +11:00
|
|
|
|
2018-05-10 13:53:06 +10:00
|
|
|
template <typename T>
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::view<T*>
|
2018-05-10 13:53:06 +10:00
|
|
|
allocate (size_t count)
|
|
|
|
{
|
|
|
|
return allocate<T> (count, alignof (T));
|
|
|
|
}
|
2018-05-10 12:50:37 +10:00
|
|
|
|
2018-05-10 13:53:06 +10:00
|
|
|
template <typename T>
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::view<T*>
|
2018-05-10 13:53:06 +10:00
|
|
|
allocate (size_t count, size_t align)
|
|
|
|
{
|
|
|
|
(void)count;
|
|
|
|
(void)align;
|
|
|
|
|
|
|
|
throw std::bad_alloc ();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void
|
2018-08-05 14:42:02 +10:00
|
|
|
deallocate (cruft::view<T*> ptr)
|
2018-05-10 13:53:06 +10:00
|
|
|
{
|
|
|
|
(void)ptr;
|
|
|
|
CHECK_EQ (ptr.data (), static_cast<const void*> (nullptr));
|
|
|
|
}
|
2016-06-22 19:51:18 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::view<std::byte*> data (void);
|
|
|
|
cruft::view<const std::byte*> data (void) const;
|
2018-02-28 17:55:56 +11:00
|
|
|
|
|
|
|
std::byte* begin (void);
|
|
|
|
const std::byte* begin (void) const;
|
|
|
|
std::byte* end (void);
|
|
|
|
const std::byte* end (void) const;
|
|
|
|
|
2016-10-10 20:59:26 +11:00
|
|
|
size_t offset (const void*) const;
|
2016-02-10 14:04:08 +11:00
|
|
|
|
2016-10-10 20:59:26 +11:00
|
|
|
void reset (void);
|
|
|
|
|
|
|
|
size_t capacity (void) const;
|
|
|
|
size_t used (void) const;
|
|
|
|
size_t remain (void) const;
|
2015-11-13 17:17:37 +11:00
|
|
|
};
|
2016-10-10 17:58:59 +11:00
|
|
|
}
|