test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
allocators.h
Go to the documentation of this file.
1 #ifndef NPSTAT_ALLOCATORS_HH_
2 #define NPSTAT_ALLOCATORS_HH_
3 
14 #include <cassert>
15 
16 namespace npstat {
21  template <typename T>
22  inline T* makeBuffer(unsigned sizeNeeded, T* stackBuffer,
23  unsigned sizeofStackBuffer)
24  {
25  if (sizeNeeded > sizeofStackBuffer || stackBuffer == 0)
26  return new T[sizeNeeded];
27  else
28  return stackBuffer;
29  }
30 
32  template <typename T>
33  inline void destroyBuffer(T* thisBuffer, const T* stackBuffer)
34  {
35  if (thisBuffer != stackBuffer)
36  delete [] thisBuffer;
37  }
38 
40  template <typename T1, typename T2>
41  inline void copyBuffer(T1* dest, const T2* source, const unsigned long len)
42  {
43  if (len)
44  {
45  assert(dest);
46  assert(source);
47  for (unsigned long i=0; i<len; ++i)
48  *dest++ = static_cast<T1>(*source++);
49  }
50  }
51 
56  template <typename T1, typename T2>
57  inline void transposeBuffer(T1* dest, const T2* source,
58  const unsigned long dim)
59  {
60  if (dim)
61  {
62  assert(dest);
63  assert(source);
64  for (unsigned long i=0; i<dim; ++i)
65  {
66  for (unsigned long j=0; j<dim; ++j)
67  dest[j*dim] = static_cast<T1>(*source++);
68  ++dest;
69  }
70  }
71  }
72 
77  template <typename T1, typename T2>
78  inline void transposeBuffer(T1* dest, const T2* source,
79  const unsigned long M,
80  const unsigned long N)
81  {
82  if (M && N)
83  {
84  assert(dest);
85  assert(source);
86  for (unsigned long i=0; i<M; ++i)
87  {
88  for (unsigned long j=0; j<N; ++j)
89  dest[j*M] = static_cast<T1>(*source++);
90  ++dest;
91  }
92  }
93  }
94 
99  template <typename T>
100  inline void clearBuffer(T* buf, const unsigned long len)
101  {
102  if (len)
103  {
104  assert(buf);
105  const T zero = T();
106  for (unsigned long i=0; i<len; ++i)
107  *buf++ = zero;
108  }
109  }
110 }
111 
112 #endif // NPSTAT_ALLOCATORS_HH_
113 
void copyBuffer(T1 *dest, const T2 *source, const unsigned long len)
Definition: allocators.h:41
int i
Definition: DBlmapReader.cc:9
T * makeBuffer(unsigned sizeNeeded, T *stackBuffer, unsigned sizeofStackBuffer)
Definition: allocators.h:22
assert(m_qm.get())
void transposeBuffer(T1 *dest, const T2 *source, const unsigned long dim)
Definition: allocators.h:57
int j
Definition: DBlmapReader.cc:9
void clearBuffer(T *buf, const unsigned long len)
Definition: allocators.h:100
#define N
Definition: blowfish.cc:9
long double T
static std::string const source
Definition: EdmProvDump.cc:42
void destroyBuffer(T *thisBuffer, const T *stackBuffer)
Definition: allocators.h:33