CFx SDK Documentation  2020SP3
OdMemory.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 
26 
27 #ifndef _OD_MEMORY_H_
28 #define _OD_MEMORY_H_
29 
30 #define STL_USING_MEMORY
31 #include "OdaSTL.h"
32 
33 #include "OdPlatform.h"
34 #include "OdAlloc.h"
35 
36 // TEMPLATE CLASS allocator
37 // Some compilers don't have support for construct & destroy functions.
38 
39 #ifndef OD_STD_ALLOCATOR
40 
50 template<class T>
51 class OdAllocator : public std::allocator<T>
52 {
53 public:
54  typedef typename std::allocator<T>::size_type size_type;
55  typedef typename std::allocator<T>::difference_type difference_type;
57  typedef typename std::allocator<T>::const_pointer const_pointer;
58  typedef typename std::allocator<T>::reference reference;
59  typedef typename std::allocator<T>::const_reference const_reference;
60  typedef typename std::allocator<T>::value_type value_type;
61 
62 private:
63  inline void constructn(size_type N, pointer ptr, const T& _V = T())
64  {
65  while(N--) construct(ptr + N, _V);
66  }
67  inline void destroyn(size_type N, pointer ptr)
68  {
69  while(N--) destroy(ptr + N);
70  }
71 public:
78  pointer allocate(size_type N, const void * = 0)
79  {
80  pointer res = NULL;
81  if (N)
82  {
83  res = (pointer)::odrxAlloc(N * sizeof(T));
84  constructn(N, res);
85  }
86  return res;
87  }
88 
90 
92  {
93  pointer res = NULL;
94  if (N)
95  {
96  res = (pointer)::odrxAlloc(N * sizeof(T));
97  constructn(N, res);
98  }
99  return res;
100  }
101 
102 #ifdef _MSC_VER
103 
104 #if _MSC_VER > 1600
105 #ifndef _FARQ /* specify standard memory model */
106  #define _FARQ
107  #define _PDFT ptrdiff_t
108  #define _SIZT size_t
109 #endif
110 #endif
111 
120  char _FARQ *_Charalloc(size_type N)
121  {
122  return (char _FARQ*)::odrxAlloc(N);
123  }
124 #endif
125 
130  void deallocate(void* P, size_type = 0 ) { ::odrxFree(P); }
131 };
132 
133 #else
134 
138 template<class T>
139 class OdAllocator : public std::allocator<T>
140 {};
141 
142 
143 #endif
144 
145 
146 #endif //_OD_MEMORY_H_
147 
NULL
#define NULL
Definition: GsProperties.h:177
OdPlatform.h
OdAllocator::allocate
pointer allocate(size_type N, const void *=0)
Definition: OdMemory.h:78
OdAllocator::reference
std::allocator< T >::reference reference
Definition: OdMemory.h:58
OdaSTL.h
odrxFree
ALLOCDLL_EXPORT void odrxFree(void *pMemBlock)
OdAllocator::difference_type
std::allocator< T >::difference_type difference_type
Definition: OdMemory.h:55
OdAlloc.h
OdAllocator::value_type
std::allocator< T >::value_type value_type
Definition: OdMemory.h:60
OdAllocator::const_pointer
std::allocator< T >::const_pointer const_pointer
Definition: OdMemory.h:57
OdAllocator::pointer
std::allocator< T >::pointer pointer
Definition: OdMemory.h:56
pointer
GLenum void ** pointer
Definition: gles2_ext.h:288
OdAllocator::allocate
pointer allocate(size_type N, const_pointer=0)
DOM For CodeWarrior.
Definition: OdMemory.h:91
odrxAlloc
ALLOCDLL_EXPORT void * odrxAlloc(size_t nBytes)
OdAllocator::size_type
std::allocator< T >::size_type size_type
Definition: OdMemory.h:54
OdAllocator
Definition: OdMemory.h:52
OdAllocator::deallocate
void deallocate(void *P, size_type=0)
Definition: OdMemory.h:130
OdAllocator::const_reference
std::allocator< T >::const_reference const_reference
Definition: OdMemory.h:59