NEST  2.6.0,not_revisioned_source_dir@0
libc_allocator_with_realloc.h
Go to the documentation of this file.
1 // Copyright (c) 2010, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 // ---
31 
32 #ifndef UTIL_GTL_LIBC_ALLOCATOR_WITH_REALLOC_H_
33 #define UTIL_GTL_LIBC_ALLOCATOR_WITH_REALLOC_H_
34 
35 #include <sparseconfig.h>
36 #include <stdlib.h> // for malloc/realloc/free
37 #include <stddef.h> // for ptrdiff_t
38 #include <new> // for placement new
39 
40 _START_GOOGLE_NAMESPACE_
41 
42 template<class T>
44  public:
45  typedef T value_type;
46  typedef size_t size_type;
47  typedef ptrdiff_t difference_type;
48 
49  typedef T* pointer;
50  typedef const T* const_pointer;
51  typedef T& reference;
52  typedef const T& const_reference;
53 
57 
58  pointer address(reference r) const { return &r; }
59  const_pointer address(const_reference r) const { return &r; }
60 
62  return static_cast<pointer>(malloc(n * sizeof(value_type)));
63  }
65  free(p);
66  }
68  return static_cast<pointer>(realloc(p, n * sizeof(value_type)));
69  }
70 
71  size_type max_size() const {
72  return static_cast<size_type>(-1) / sizeof(value_type);
73  }
74 
75  void construct(pointer p, const value_type& val) {
76  new(p) value_type(val);
77  }
78  void destroy(pointer p) { p->~value_type(); }
79 
80  template <class U>
82 
83  template<class U>
84  struct rebind {
86  };
87 };
88 
89 // libc_allocator_with_realloc<void> specialization.
90 template<>
92  public:
93  typedef void value_type;
94  typedef size_t size_type;
95  typedef ptrdiff_t difference_type;
96  typedef void* pointer;
97  typedef const void* const_pointer;
98 
99  template<class U>
100  struct rebind {
102  };
103 };
104 
105 template<class T>
108  return true;
109 }
110 
111 template<class T>
114  return false;
115 }
116 
117 _END_GOOGLE_NAMESPACE_
118 
119 #endif // UTIL_GTL_LIBC_ALLOCATOR_WITH_REALLOC_H_
libc_allocator_with_realloc(const libc_allocator_with_realloc &)
Definition: libc_allocator_with_realloc.h:55
bool operator==(const libc_allocator_with_realloc< T > &, const libc_allocator_with_realloc< T > &)
Definition: libc_allocator_with_realloc.h:106
libc_allocator_with_realloc()
Definition: libc_allocator_with_realloc.h:54
Definition: libc_allocator_with_realloc.h:84
void value_type
Definition: libc_allocator_with_realloc.h:93
pointer address(reference r) const
Definition: libc_allocator_with_realloc.h:58
Definition: libc_allocator_with_realloc.h:43
libc_allocator_with_realloc(const libc_allocator_with_realloc< U > &)
Definition: libc_allocator_with_realloc.h:81
ptrdiff_t difference_type
Definition: libc_allocator_with_realloc.h:47
T value_type
Definition: libc_allocator_with_realloc.h:45
void destroy(pointer p)
Definition: libc_allocator_with_realloc.h:78
const T & const_reference
Definition: libc_allocator_with_realloc.h:52
~libc_allocator_with_realloc()
Definition: libc_allocator_with_realloc.h:56
const T * const_pointer
Definition: libc_allocator_with_realloc.h:50
T & reference
Definition: libc_allocator_with_realloc.h:51
pointer reallocate(pointer p, size_type n)
Definition: libc_allocator_with_realloc.h:67
size_t size_type
Definition: libc_allocator_with_realloc.h:46
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
ptrdiff_t difference_type
Definition: libc_allocator_with_realloc.h:95
pointer allocate(size_type n, const_pointer=0)
Definition: libc_allocator_with_realloc.h:61
void deallocate(pointer p, size_type)
Definition: libc_allocator_with_realloc.h:64
void * pointer
Definition: libc_allocator_with_realloc.h:96
size_type max_size() const
Definition: libc_allocator_with_realloc.h:71
libc_allocator_with_realloc< U > other
Definition: libc_allocator_with_realloc.h:85
libc_allocator_with_realloc< U > other
Definition: libc_allocator_with_realloc.h:101
size_t size_type
Definition: libc_allocator_with_realloc.h:94
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218
const void * const_pointer
Definition: libc_allocator_with_realloc.h:97
const_pointer address(const_reference r) const
Definition: libc_allocator_with_realloc.h:59
T * pointer
Definition: libc_allocator_with_realloc.h:49
bool operator!=(const libc_allocator_with_realloc< T > &, const libc_allocator_with_realloc< T > &)
Definition: libc_allocator_with_realloc.h:112
void construct(pointer p, const value_type &val)
Definition: libc_allocator_with_realloc.h:75