commore  1.0.6-SNAPSHOT
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArrayImpl.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2014 Raphael David / CANTOR
3 //
4 
5 
6 #ifndef CMR_ARRAY_IMPL_INCLUDED
7 #define CMR_ARRAY_IMPL_INCLUDED
8 #include <new>
9 #include <string.h>
10 #include "commore/Commore.h"
11 #include "commore/Array.h"
12 
16 #define CMR_ARRAY_XML_IMPL_SCALAR(T) \
17  template <> long CMREXD Array<T,CmrScalarArrayAllocator<T> >::read_xml(IBStream& i) \
18  { \
19  return -1; \
20  } \
21  template <> long CMREXD Array<T,CmrScalarArrayAllocator<T> >::write_xml(OBStream& o) const \
22  { \
23  return -1; \
24  } \
25 
26 
30 #define CMR_ARRAY_IMPL(T) \
31  namespace commore { \
32  template <> void CMREXD CmrArrayAllocator<T>::constructor(Byte* data, const Byte* value) \
33  { \
34  if (value) \
35  { \
36  new (data) T(*(T*)value); \
37  } else { \
38  new (data) T(); \
39  } \
40  } \
41  template <> void CMREXD CmrArrayAllocator<T>::destructor(Byte* data) \
42  { \
43  ((T*)data)->T::~T(); \
44  } \
45  template <> int CMREXD CmrArrayAllocator<T>::comparator(const Dummy& v1, const Dummy& v2) \
46  { \
47  const T& ov1 = (const T&)v1; \
48  const T& ov2 = (const T&)v2; \
49  return ov1.compare(ov2); \
50  } \
51  }
52 
53 
57 #define CMR_ARRAY_IMPL_SCALAR(T) \
58  namespace commore { \
59  CMR_ARRAY_XML_IMPL_SCALAR(T) \
60  template <> void CMREXD CmrScalarArrayAllocator<T>::constructor(Byte* data, const Byte* value) \
61  { \
62  T& v = *(T*)data; \
63  if (value) { \
64  const T& ov = *(const T*)value; \
65  v = ov; \
66  } else { \
67  v = 0; /*memset(data, 0,size)*/; \
68  } \
69  } \
70  template <> void CMREXD CmrScalarArrayAllocator<T>::destructor(Byte* data) \
71  { \
72  } \
73  template <> int CMREXD CmrScalarArrayAllocator<T>::comparator(const Dummy& v1, const Dummy& v2) \
74  { \
75  const T& ov1 = (const T&)v1; \
76  const T& ov2 = (const T&)v2; \
77  if (ov1 < ov2) return -1; \
78  else if (ov1 == ov2) return 0; \
79  else return 1; \
80  } \
81  }
82 
83 #endif // CMR_ARRAY_IMPL_INCLUDED
84