OpenNI 1.3.2
XnDataTypes.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * OpenNI 1.1 Alpha *
4 * Copyright (C) 2011 PrimeSense Ltd. *
5 * *
6 * This file is part of OpenNI. *
7 * *
8 * OpenNI is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published *
10 * by the Free Software Foundation, either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * OpenNI is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20 * *
21 ****************************************************************************/
22 #ifndef _XN_DATA_TYPES_H_
23 #define _XN_DATA_TYPES_H_
24 
25 //---------------------------------------------------------------------------
26 // Includes
27 //---------------------------------------------------------------------------
28 #include "XnOS.h"
29 
30 //---------------------------------------------------------------------------
31 // Types
32 //---------------------------------------------------------------------------
36 typedef void* XnValue;
37 
42 #define XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, Type, ClassName) \
43  class decl ClassName \
44  { \
45  public: \
46  static XnValue CreateValueCopy(Type const& orig) \
47  { \
48  if (sizeof(Type) > sizeof(XnValue)) \
49  { \
50  Type* pNew = XN_NEW(Type, orig); \
51  return (XnValue)pNew; \
52  } \
53  else \
54  { \
55  XnValue result = 0; \
56  xnOSMemCopy(&result, &orig, sizeof(Type)); \
57  return result; \
58  } \
59  } \
60  static void FreeValue(XnValue& Value) \
61  { \
62  if (sizeof(Type) > sizeof(XnValue)) \
63  { \
64  Type* p = (Type*)Value; \
65  XN_DELETE(p); \
66  } \
67  } \
68  static XnValue GetAsValue(Type const& orig) \
69  { \
70  if (sizeof(Type) > sizeof(XnValue)) \
71  { \
72  return (XnValue)&orig; \
73  } \
74  else \
75  { \
76  XnValue result = 0; \
77  xnOSMemCopy(&result, &orig, sizeof(Type)); \
78  return result; \
79  } \
80  } \
81  static Type const& GetFromValue(const XnValue& Value) \
82  { \
83  if (sizeof(Type) > sizeof(XnValue)) \
84  { \
85  Type const* p = (Type const*)Value; \
86  return *p; \
87  } \
88  else \
89  { \
90  Type const* p = (Type const*)&Value; \
91  return *p; \
92  } \
93  } \
94  static Type& GetFromValue(XnValue& Value) \
95  { \
96  if (sizeof(Type) > sizeof(XnValue)) \
97  { \
98  Type* p = (Type*)Value; \
99  return *p; \
100  } \
101  else \
102  { \
103  Type* p = (Type*)&Value; \
104  return *p; \
105  } \
106  } \
107  };
108 
112 #define XN_DECLARE_DEFAULT_VALUE_TRANSLATOR(Type, ClassName) \
113  XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(, Type, ClassName)
114 
115 #define XN_DEFAULT_TRANSLATOR_NAME(ClassName) ClassName ## Translator
116 
117 #endif // _XN_DATA_TYPES_H_