]> git.sesse.net Git - casparcg/blob - common/os/page_locked_allocator.h
Fix a few Clang warnings.
[casparcg] / common / os / page_locked_allocator.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG 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
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #pragma once
23
24 #include <cstdlib>
25
26 namespace caspar {
27
28 namespace detail {
29
30 void* alloc_page_locked(size_t size);
31 void free_page_locked(void* p);
32
33 }
34         
35 template <class T>
36 class page_locked_allocator
37 {
38 public:
39         typedef size_t    size_type;
40         typedef ptrdiff_t difference_type;
41         typedef T*        pointer;
42         typedef const T*  const_pointer;
43         typedef T&        reference;
44         typedef const T&  const_reference;
45         typedef T         value_type;
46
47         page_locked_allocator() {}
48         page_locked_allocator(const page_locked_allocator&) {}
49   
50         pointer allocate(size_type n, const void * = 0) 
51         {
52                 return reinterpret_cast<T*>(detail::alloc_page_locked(n));
53         }
54   
55         void deallocate(void* p, size_type) 
56         {
57                 detail::free_page_locked(p);            
58         }
59
60         pointer           address(reference x) const { return &x; }
61         const_pointer     address(const_reference x) const { return &x; }
62         page_locked_allocator<T>&  operator=(const page_locked_allocator&) { return *this; }
63         void              construct(pointer p, const T& val) { new ((T*) p) T(val); }
64         void              destroy(pointer p) { p->~T(); }
65
66         size_type         max_size() const { return size_t(-1); }
67
68         template <class U>
69         struct rebind { typedef page_locked_allocator<U> other; };
70
71         template <class U>
72         page_locked_allocator(const page_locked_allocator<U>&) {}
73
74         template <class U>
75         page_locked_allocator& operator=(const page_locked_allocator<U>&) { return *this; }
76 };
77 }