File: XnActualPropertiesHash.cpp

package info (click to toggle)
openni2 2.2.0.33%2Bdfsg-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,240 kB
  • sloc: cpp: 111,183; ansic: 35,511; sh: 10,556; python: 1,313; java: 952; makefile: 575; xml: 12
file content (233 lines) | stat: -rw-r--r-- 6,548 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*****************************************************************************
*                                                                            *
*  OpenNI 2.x Alpha                                                          *
*  Copyright (C) 2012 PrimeSense Ltd.                                        *
*                                                                            *
*  This file is part of OpenNI.                                              *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
*****************************************************************************/
#include "XnActualPropertiesHash.h"

#include "XnActualIntProperty.h"
#include "XnActualRealProperty.h"
#include "XnActualStringProperty.h"
#include "XnActualGeneralProperty.h"
#include <XnCore.h>

XnActualPropertiesHash::XnActualPropertiesHash(const XnChar* strName)
{
	strncpy(m_strName, strName, XN_DEVICE_MAX_STRING_LENGTH);
}

XnActualPropertiesHash::~XnActualPropertiesHash()
{
	// free all properties
	for (Iterator it = Begin(); it != End(); ++it)
	{
		XN_DELETE(it->Value());
	}
}

XnStatus XnActualPropertiesHash::Add(XnUInt32 propertyId, const XnChar* strName, XnUInt64 nValue)
{
	XnStatus nRetVal = XN_STATUS_OK;

	Iterator it = End();
	if (XN_STATUS_OK == Find(propertyId, it))
	{
		return XN_STATUS_DEVICE_PROPERTY_ALREADY_EXISTS;
	}

	// create property
	XnActualIntProperty* pProp;
	XN_VALIDATE_NEW(pProp, XnActualIntProperty, propertyId, strName, nValue, m_strName);

	// and add it to the hash
	nRetVal = m_Hash.Set(propertyId, pProp);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(pProp);
		return (nRetVal);
	}

	return (XN_STATUS_OK);
}

XnStatus XnActualPropertiesHash::Add(XnUInt32 propertyId, const XnChar* strName, XnDouble dValue)
{
	XnStatus nRetVal = XN_STATUS_OK;

	Iterator it = End();
	if (XN_STATUS_OK == Find(propertyId, it))
	{
		return XN_STATUS_DEVICE_PROPERTY_ALREADY_EXISTS;
	}

	// create property
	XnActualRealProperty* pProp;
	XN_VALIDATE_NEW(pProp, XnActualRealProperty, propertyId, strName, dValue, m_strName);

	// and add it to the hash
	nRetVal = m_Hash.Set(propertyId, pProp);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(pProp);
		return (nRetVal);
	}

	return (XN_STATUS_OK);
}

XnStatus XnActualPropertiesHash::Add(XnUInt32 propertyId, const XnChar* strName, const XnChar* strValue)
{
	XnStatus nRetVal = XN_STATUS_OK;

	Iterator it = End();
	if (XN_STATUS_OK == Find(propertyId, it))
	{
		return XN_STATUS_DEVICE_PROPERTY_ALREADY_EXISTS;
	}

	// create property
	XnActualStringProperty* pProp;
	XN_VALIDATE_NEW(pProp, XnActualStringProperty, propertyId, strName, strValue, m_strName);

	// and add it to the hash
	nRetVal = m_Hash.Set(propertyId, pProp);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(pProp);
		return (nRetVal);
	}

	return (XN_STATUS_OK);
}

XnStatus XnActualPropertiesHash::Add(XnUInt32 propertyId, const XnChar* strName, const OniGeneralBuffer& gbValue)
{
	XnStatus nRetVal = XN_STATUS_OK;

	Iterator it = End();
	if (XN_STATUS_OK == Find(propertyId, it))
	{
		return XN_STATUS_DEVICE_PROPERTY_ALREADY_EXISTS;
	}

	// create buffer
	OniGeneralBuffer gbNew;
	nRetVal = XnGeneralBufferAlloc(&gbNew, gbValue.dataSize);
	XN_IS_STATUS_OK(nRetVal);

	// copy content
	xnOSMemCopy(gbNew.data, gbValue.data, gbValue.dataSize);

	// create property
	XnActualGeneralProperty* pProp;
	XN_VALIDATE_NEW(pProp, XnActualGeneralProperty, propertyId, strName, gbNew, NULL, m_strName);

	pProp->SetAsBufferOwner(TRUE);

	// and add it to the hash
	nRetVal = m_Hash.Set(propertyId, pProp);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(pProp);
		return (nRetVal);
	}

	return (XN_STATUS_OK);
}

XnStatus XnActualPropertiesHash::Remove(XnUInt32 propertyId)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	ConstIterator it;
	nRetVal = Find(propertyId, it);
	XN_IS_STATUS_OK(nRetVal);

	return Remove(it);
}

XnStatus XnActualPropertiesHash::Remove(ConstIterator where)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnProperty* pProp = where->Value();

	nRetVal = m_Hash.Remove(where);
	XN_IS_STATUS_OK(nRetVal);

	XN_DELETE(pProp);

	return (XN_STATUS_OK);
}

XnStatus XnActualPropertiesHash::Clear()
{
	while (!IsEmpty())
	{
		Remove(Begin());
	}

	return XN_STATUS_OK;
}

XnStatus XnActualPropertiesHash::CopyFrom(const XnActualPropertiesHash& other)
{
	XnStatus nRetVal = XN_STATUS_OK;

	Clear();
	strncpy(m_strName, other.m_strName, XN_DEVICE_MAX_STRING_LENGTH);

	for (ConstIterator it = other.Begin(); it != other.End(); ++it)
	{
		switch (it->Value()->GetType())
		{
		case XN_PROPERTY_TYPE_INTEGER:
			{
				XnActualIntProperty* pProp = (XnActualIntProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_REAL:
			{
				XnActualRealProperty* pProp = (XnActualRealProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_STRING:
			{
				XnActualStringProperty* pProp = (XnActualStringProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_GENERAL:
			{
				XnActualGeneralProperty* pProp = (XnActualGeneralProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		default:
			XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d\n", it->Value()->GetType());
		}
	}

	return (XN_STATUS_OK);
}