gcmemory.h
Go to the documentation of this file.
1 #pragma once
2 #include <xmemory>
3 #include <limits>
4 #include "Base/GCTypes.h"
5 
6 namespace GENAPI_NAMESPACE
7 {
8 
9  void* MyAllocate( std::size_t );
10  void DeAllocate( void * );
11 
12  template <class T>
13  class MyAlloc {
14  public:
15  // type definitions
16  typedef T value_type;
17  typedef T* pointer;
18  typedef const T* const_pointer;
19  typedef T& reference;
20  typedef const T& const_reference;
21  typedef std::size_t size_type;
22  typedef std::ptrdiff_t difference_type;
23 
24  // rebind allocator to type U
25  template <class U>
26  struct rebind {
27  typedef MyAlloc<U> other;
28  };
29 
30  // return address of values
31  pointer address (reference value) const {
32  return &value;
33  }
34  const_pointer address (const_reference value) const {
35  return &value;
36  }
37 
38  /* constructors and destructor
39  * - nothing to do because the allocator has no state
40  */
41  MyAlloc() throw() {
42  }
43  MyAlloc(const MyAlloc&) throw() {
44  }
45  template <class U>
46  MyAlloc (const MyAlloc<U>&) throw() {
47  }
48  ~MyAlloc() throw() {
49  }
50 
51  // return maximum number of elements that can be allocated
52 #undef max
53  size_type max_size () const throw() {
54  return std::numeric_limits<std::size_t>::max() / sizeof(T);
55  }
56 
57  // allocate but don't initialize num elements of type T
58  pointer allocate (size_type num, const void* = 0) {
59  // print message and allocate memory with global new
60 #if 0
61  std::cerr << "allocate " << num << " element(s)"
62  << " of size " << sizeof(T) << std::endl;
63 #endif
64  pointer ret = (pointer)MyAllocate( num*sizeof(T) );
65 #if 0
66  std::cerr << " allocated at: " << (void*)ret << std::endl;
67 #endif
68  return ret;
69  }
70 
71  // initialize elements of allocated storage p with value value
72  void construct (pointer p, const T& value) {
73  // initialize memory with placement new
74  new((void*)p)T(value);
75  }
76 
77  // destroy elements of initialized storage p
78  void destroy (pointer p) {
79  p=p;
80  // destroy objects by calling their destructor
81  p->~T();
82  }
83 
84  // deallocate storage p of deleted elements
85  void deallocate (pointer p, size_type /* num */) {
86  // print message and deallocate memory with global delete
87 #if 0
88  std::cerr << "deallocate " << num << " element(s)"
89  << " of size " << sizeof(T)
90  << " at: " << (void*)p << std::endl;
91 #endif
92  DeAllocate( p );
93  }
94  };
95 
96  // return that all specializations of this allocator are interchangeable
97  template <class T1, class T2>
98  bool operator== (const MyAlloc<T1>&,
99  const MyAlloc<T2>&) throw() {
100  return true;
101  }
102  template <class T1, class T2>
104  const MyAlloc<T2>&) throw() {
105  return false;
106  }
107 }
MyAlloc(const MyAlloc &)
Definition: gcmemory.h:43
bool operator!=(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:103
MyAlloc(const MyAlloc< U > &)
Definition: gcmemory.h:46
void DeAllocate(void *)
void deallocate(pointer p, size_type)
Definition: gcmemory.h:85
void destroy(pointer p)
Definition: gcmemory.h:78
bool operator==(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:98
pointer allocate(size_type num, const void *=0)
Definition: gcmemory.h:58
const_pointer address(const_reference value) const
Definition: gcmemory.h:34
std::size_t size_type
Definition: gcmemory.h:21
pointer address(reference value) const
Definition: gcmemory.h:31
std::ptrdiff_t difference_type
Definition: gcmemory.h:22
size_type max_size() const
Definition: gcmemory.h:53
const T & const_reference
Definition: gcmemory.h:20
void * MyAllocate(std::size_t)
Part of the generic device API.
Definition: Autovector.h:48
void construct(pointer p, const T &value)
Definition: gcmemory.h:72
Platform-dependent type definitions.


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54