Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
unique-malloc-owner.hpp
Go to the documentation of this file.
1/*
2 UNIQUE-MALLOC-OWNER.hpp - automatic management of C-malloced memory
3
4 Copyright (C)
5 2014, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
27#ifndef LIB_UNIQUE_MALLOC_OWNER_H
28#define LIB_UNIQUE_MALLOC_OWNER_H
29
30
31#include "lib/error.hpp"
32
33#include <memory>
34
35
36namespace lib {
37
38
47 template<class X =void>
49 : public std::unique_ptr<X, void(*)(void*)>
50 {
51 using _Parent = std::unique_ptr<X, void(*)(void*)>;
52
53 public:
54 explicit
55 UniqueMallocOwner(void* memory =nullptr)
56 : _Parent(static_cast<X*>(memory), std::free)
57 { }
58
59 explicit
61 : _Parent(alloc, std::free)
62 { }
63
64
65 bool
66 empty() const
67 {
68 return ! bool(*this);
69 }
70 };
71
72
73
74
75
76} // namespace lib
77#endif /*LIB_UNIQUE_MALLOC_OWNER_H*/
Ownership token for a piece of heap memory allocated in plain-C style.
std::unique_ptr< X, void(*)(void *)> _Parent
UniqueMallocOwner(void *memory=nullptr)
Lumiera error handling (C++ interface).
Implementation namespace for support and library code.
STL namespace.