commore  1.0.6-SNAPSHOT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ListImpl.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2006-2007 Raphael David / CANTOR
3 //
4 
5 
6 #ifndef CMR_LIST_IMPL_INCLUDED
7 #define CMR_LIST_IMPL_INCLUDED
8 #include <new>
9 #include <string.h>
10 #include "commore/Commore.h"
11 #include "commore/List.h"
12 
13 #define CMR_LIST_IMPL(T) \
14  namespace commore { \
15  template <> void CMREXD CmrListAllocator<T>::constructor(Byte* data, const Byte* value) \
16  { \
17  if (value) \
18  { \
19  new (data) T(*(T*)value); \
20  } else { \
21  new (data) T(); \
22  } \
23  } \
24  template <> void CMREXD CmrListAllocator<T>::destructor(Byte* data) \
25  { \
26  ((T*)data)->T::~T(); \
27  } \
28  template <> int CMREXD CmrListAllocator<T>::comparator(const Dummy& v1, const Dummy& v2) \
29  { \
30  const T& ov1 = (const T&)v1; \
31  const T& ov2 = (const T&)v2; \
32  return ov1.compare(ov2); \
33  } \
34  }
35 
36 
37 #define CMR_LIST_IMPL_SCALAR(T) \
38  namespace commore { \
39  template <> void CMREXD CmrScalarListAllocator<T>::constructor(Byte* data, const Byte* value) \
40  { \
41  T& v = *(T*)data; \
42  if (value) { \
43  const T& ov = *(const T*)value; \
44  v = ov; \
45  } else { \
46  v = 0; /*memset(data, 0,size)*/; \
47  } \
48  } \
49  template <> void CMREXD CmrScalarListAllocator<T>::destructor(Byte* data) \
50  { \
51  } \
52  template <> int CMREXD CmrScalarListAllocator<T>::comparator(const Dummy& v1, const Dummy& v2) \
53  { \
54  const T& ov1 = (const T&)v1; \
55  const T& ov2 = (const T&)v2; \
56  if (ov1 < ov2) return -1; \
57  else if (ov1 == ov2) return 0; \
58  else return 1; \
59  } \
60  }
61 
62 #endif
63