All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  }
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 }
GENAPI_NAMESPACE
Lexical analyzer for CIntSwissKnife.
Definition: Destructible.h:30
GENAPI_NAMESPACE::DeAllocate
void DeAllocate(void *)
GENAPI_NAMESPACE::MyAlloc::const_pointer
const typedef T * const_pointer
Definition: gcmemory.h:18
GENAPI_NAMESPACE::MyAlloc::~MyAlloc
~MyAlloc()
Definition: gcmemory.h:48
GENAPI_NAMESPACE::MyAlloc::difference_type
std::ptrdiff_t difference_type
Definition: gcmemory.h:22
GENAPI_NAMESPACE::MyAlloc::pointer
T * pointer
Definition: gcmemory.h:17
GENAPI_NAMESPACE::MyAlloc::reference
T & reference
Definition: gcmemory.h:19
GENAPI_NAMESPACE::MyAlloc
Definition: gcmemory.h:13
GENAPI_NAMESPACE::MyAlloc::construct
void construct(pointer p, const T &value)
Definition: gcmemory.h:72
GENAPI_NAMESPACE::MyAlloc::MyAlloc
MyAlloc(const MyAlloc &)
Definition: gcmemory.h:43
GENAPI_NAMESPACE::MyAlloc::rebind::other
MyAlloc< U > other
Definition: gcmemory.h:27
GENAPI_NAMESPACE::MyAlloc::deallocate
void deallocate(pointer p, size_type)
Definition: gcmemory.h:85
GENAPI_NAMESPACE::operator==
bool operator==(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:98
GENAPI_NAMESPACE::MyAlloc::value_type
T value_type
Definition: gcmemory.h:16
GENAPI_NAMESPACE::MyAlloc::destroy
void destroy(pointer p)
Definition: gcmemory.h:78
GENAPI_NAMESPACE::MyAlloc::MyAlloc
MyAlloc(const MyAlloc< U > &)
Definition: gcmemory.h:46
GCTypes.h
Platform-dependent type definitions.
GENAPI_NAMESPACE::MyAlloc::max_size
size_type max_size() const
Definition: gcmemory.h:53
GENAPI_NAMESPACE::MyAlloc::MyAlloc
MyAlloc()
Definition: gcmemory.h:41
GENAPI_NAMESPACE::MyAllocate
void * MyAllocate(std::size_t)
GENAPI_NAMESPACE::operator!=
bool operator!=(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
Definition: gcmemory.h:103
GENAPI_NAMESPACE::MyAlloc::size_type
std::size_t size_type
Definition: gcmemory.h:21
GENAPI_NAMESPACE::MyAlloc::const_reference
const typedef T & const_reference
Definition: gcmemory.h:20
GENAPI_NAMESPACE::MyAlloc::address
pointer address(reference value) const
Definition: gcmemory.h:31
GENAPI_NAMESPACE::MyAlloc::address
const_pointer address(const_reference value) const
Definition: gcmemory.h:34
GENAPI_NAMESPACE::MyAlloc::allocate
pointer allocate(size_type num, const void *=0)
Definition: gcmemory.h:58
GENAPI_NAMESPACE::MyAlloc::rebind
Definition: gcmemory.h:26


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11