forked from huningxin/DSSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProperty.hxx
602 lines (496 loc) · 20.4 KB
/
Property.hxx
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
////////////////////////////////////////////////////////////////////////////////
// SoftKinetic DepthSense SDK
//
// COPYRIGHT AND CONFIDENTIALITY NOTICE - SOFTKINETIC CONFIDENTIAL
// INFORMATION
//
// All rights reserved to SOFTKINETIC SENSORS NV (a
// company incorporated and existing under the laws of Belgium, with
// its principal place of business at Boulevard de la Plainelaan 15,
// 1050 Brussels (Belgium), registered with the Crossroads bank for
// enterprises under company number 0811 341 454 - "Softkinetic
// Sensors").
//
// The source code of the SoftKinetic DepthSense Camera Drivers is
// proprietary and confidential information of Softkinetic Sensors NV.
//
// For any question about terms and conditions, please contact:
// [email protected] Copyright (c) 2002-2015 Softkinetic Sensors NV
////////////////////////////////////////////////////////////////////////////////
#ifndef _Property_hxx
#define _Property_hxx
#include <string>
#include <functional>
#include <DepthSenseAPI.h>
#include <DepthSenseTypes.h>
#include <String.hxx>
#include <Vector.hxx>
namespace DepthSense
{
namespace Utils
{
class BinaryReader;
class BinaryWriter;
}
class Interface;
class Type;
template <class T>
class Property;
class PropertyPrivate;
/// \class PropertyBase DepthSense.hxx
/// The base property class
///
/// The PropertyBase class is the common base class for the
/// strongly-typed Property template instantiations. It provides
/// runtime property introspection facilities for Interface and
/// its subclasses.
///
/// A PropertyBase object can be obtained by using
/// Type::getProperty(), Type::getProperties() or by connecting to
/// the \c propertyChanged event of the Interface class.
///
/// The PropertyBase class and its subclasses feature automatic
/// memory management, implemented with reference counted smart
/// pointer mechanisms.
class PropertyBase
{
public:
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API PropertyBase ();
DEPTHSENSE_API PropertyBase (const PropertyBase& other);
DEPTHSENSE_API PropertyBase& operator= (const PropertyBase& other);
#endif
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
~PropertyBase ();
/// Returns the declaring type of the current property
///
/// Returns the type in which the current property was
/// declared. This type might or might not correspond to the
/// derived runtime type of the interface being queried.
///
/// \return the declaring type
///
/// \exception std::bad_alloc not enough memory to perform the requested operation
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
Type declaringType () const;
/// Returns the name of the current property
///
/// Returns the name of the current property.
///
/// \return the property name
///
/// \exception std::bad_alloc not enough memory to perform the requested operation
std::string name () const
{
return name_p().unmarshal();
}
/// Returns whether the current property is read-only
///
/// Returns whether the current property is
/// read-only. Contrast with isReadOnly(Interface) const, which
/// determines whether the current property is read-only in
/// the provided interface.
///
/// \return whether the current property is read-only
///
/// \exception std::bad_alloc not enough memory to perform the requested operation
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
bool isReadOnly () const;
/// Returns whether the current property is read-only in the provided interface
///
/// Returns whether the current property is read-only in \p
/// iface. Properties which are read-write by design (that
/// is, for which isReadOnly() returns true) can be read-only
/// in a given interface if, for instance, the interface is a
/// Node and the client application did not request full
/// control access of the node, which can be done with
/// Context::requestControl(Node).
///
/// Contrast with isReadOnly(), which returns whether the
/// current property is read-only as per its static,
/// compile-time specifications.
///
/// \param iface the interface to examine
///
/// \return whether the current property is read-only in \p iface
///
/// \exception DepthSense::ArgumentException \p iface is unset
/// \exception std::bad_alloc not enough memory to perform the requested operation
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
bool isReadOnly (Interface iface) const;
/// Checks if the current property instance is set
///
/// Checks if the current property instance is set.
///
/// Given a variable \c prop (of type PropertyBase) and a
/// variable \c ptr (of type \c void*), the
/// <tt>prop.isSet()</tt> expression is semantically
/// equivalent to <tt>ptr != NULL</tt>.
///
/// \par Example:
/// <pre>
/// DepthSense::PropertyBase prop;
/// bool b = prop.isSet(); // b is false
/// </pre>
///
/// \return whether the current property instance is set
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
bool isSet () const;
/// Unsets the current property instance
///
/// Unsets the current property instance.
///
/// Given a variable \c prop (of type PropertyBase) and a variable
/// \c ptr (of type \c void*), the <tt>prop.unset();</tt> statement
/// is semantically equivalent to <tt>p = NULL;</tt>.
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
void unset ();
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API bool operator== (const PropertyBase& other) const;
DEPTHSENSE_API bool operator!= (const PropertyBase& other) const;
// allows to use a property as std::map key
DEPTHSENSE_API bool operator< (const PropertyBase& other) const;
DEPTHSENSE_API bool operator> (const PropertyBase& other) const;
template <class T>
bool is () const;
template <class T>
T as () const;
bool isPublic() const;
#endif
private:
void* _data;
// does not take ownership of the passed data
PropertyBase (void* _data);
DEPTHSENSE_API DSI::String name_p () const;
void serialize (DepthSense::Utils::BinaryWriter& writer);
static PropertyBase deserialize (DepthSense::Utils::BinaryReader& reader, Type (*typeFactory) (int32_t typeID));
friend class PropertyPrivate;
template <class T>
friend class Property;
};
/// \class Property DepthSense.hxx
/// The strongly-typed property leaf class
///
/// The Property class provides strongly-typed runtime property
/// introspection facilities for Interface and its subclasses.
///
/// \tparam T the property type
template <class T>
class Property
#ifdef DEPTHSENSE_DOC
: public PropertyBase
#endif
{
public:
/// The property type
///
/// Exposes the property type.
typedef T Type;
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API Property ();
DEPTHSENSE_API explicit Property (const PropertyBase& prop);
DEPTHSENSE_API Property (const Property& other);
DEPTHSENSE_API Property& operator= (const Property& other);
DEPTHSENSE_API ~Property ();
DEPTHSENSE_API DepthSense::Type declaringType () const;
std::string name () const
{
return name_p().unmarshal();
}
DEPTHSENSE_API bool isReadOnly () const;
DEPTHSENSE_API bool isReadOnly (Interface iface) const;
DEPTHSENSE_API bool isSet () const;
DEPTHSENSE_API void unset ();
DEPTHSENSE_API bool operator== (const Property& other) const;
DEPTHSENSE_API bool operator!= (const Property& other) const;
// allows to use a property as std::map key
DEPTHSENSE_API bool operator< (const Property& other) const;
DEPTHSENSE_API bool operator> (const Property& other) const;
DEPTHSENSE_API operator PropertyBase () const;
#endif
/// Returns the value of the current property in an interface
///
/// Returns the value of the current property in \p iface.
///
/// \param iface the interface to examine
///
/// \return the property value
///
/// \exception DepthSense::ArgumentException \p iface is unset, or the current property does not exist in the type of \p iface
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the getter of
/// the property.
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
T getValue (Interface iface) const;
/// Sets the value of the current property in an interface
///
/// Sets the value of the current property in \p iface.
///
/// \param iface the interface to modify
/// \param value the value to set
///
/// \exception DepthSense::ArgumentException \p iface is unset, or the current property does not exist in the type of \p iface
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the setter of
/// the property.
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
void setValue (Interface iface, T value) const;
/// Returns the value of a property in an interface
///
/// Returns the value of property named \p propertyName in \p iface.
///
/// \param iface the interface to examine
/// \param propertyName the name of the property to query
///
/// \return the property value
///
/// \exception DepthSense::ArgumentException \p iface is unset, or no property named \p propertyName exists in the type of \p iface
/// \exception DepthSense::InvalidOperationException the type of the looked up property does not match \p T
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the getter of
/// the property.
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
static T getValue (Interface iface, const char* propertyName);
/// Sets the value of a property in an interface
///
/// Sets the value of property named \p propertyName in \p iface.
///
/// \param iface the interface to modify
/// \param propertyName the name of the property whose value to set
/// \param value the value to set
///
/// \exception DepthSense::ArgumentException \p iface is unset, or no property named \p propertyName exists in the type of \p iface
/// \exception DepthSense::InvalidOperationException the type of the looked up property does not match \p T
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the setter of
/// the property.
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
static void setValue (Interface iface, const char* propertyName, T value);
private:
void *_data;
// does not take ownership of the passed data
Property (void* data);
// takes ownership of the passed data
static Property take (void* data);
DEPTHSENSE_API DSI::String name_p () const;
friend class PropertyBase;
friend class PropertyPrivate;
};
/// The string property class
///
/// In DepthSense SDK, properties of type \c std::string are
/// particular in so that they are asymmetric: while the getter
/// returns a \c std::string value, the setter accepts a <tt>const
/// char*</tt> argument.
///
/// To account for this peculiarity, the Property<std::string>
/// template specialization is defined. The only difference with
/// the non-specialized Property template is that the setValue()
/// methods accept a \p value argument of type <tt>const
/// char*</tt> rather than of type \c T.
template <>
class Property<std::string>
#ifdef DEPTHSENSE_DOC
: public PropertyBase
#endif
{
public:
/// The property type
///
/// Exposes the property type.
typedef std::string Type;
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API Property ();
DEPTHSENSE_API explicit Property (const PropertyBase& prop);
DEPTHSENSE_API Property (const Property& other);
DEPTHSENSE_API Property& operator= (const Property& other);
DEPTHSENSE_API ~Property ();
DEPTHSENSE_API DepthSense::Type declaringType () const;
std::string name () const
{
return name_p().unmarshal();
}
DEPTHSENSE_API bool isReadOnly () const;
DEPTHSENSE_API bool isReadOnly (Interface iface) const;
DEPTHSENSE_API bool isSet () const;
DEPTHSENSE_API void unset ();
DEPTHSENSE_API bool operator== (const Property& other) const;
DEPTHSENSE_API bool operator!= (const Property& other) const;
// allows to use a property as std::map key
DEPTHSENSE_API bool operator< (const Property& other) const;
DEPTHSENSE_API bool operator> (const Property& other) const;
DEPTHSENSE_API operator PropertyBase () const;
#endif
/// Returns the value of the current property in an interface
///
/// Returns the value of the current property in \p iface.
///
/// \param iface the interface to examine
///
/// \return the property value
///
/// \exception DepthSense::ArgumentException \p iface is unset, or the current property does not exist in the type of \p iface
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the getter of
/// the property.
std::string getValue (Interface iface) const;
/// Sets the value of the current property in an interface
///
/// Sets the value of the current property in \p iface.
///
/// \param iface the interface to modify
/// \param value the value to set
///
/// \exception DepthSense::ArgumentException \p iface is unset, or the current property does not exist in the type of \p iface
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the setter of
/// the property.
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
void setValue (Interface iface, const char* value) const;
/// Returns the value of a property in an interface
///
/// Returns the value of property named \p propertyName in \p iface.
///
/// \param iface the interface to examine
/// \param propertyName the name of the property to query
///
/// \return the property value
///
/// \exception DepthSense::ArgumentException \p iface is unset, or no property named \p propertyName exists in the type of \p iface
/// \exception DepthSense::InvalidOperationException the type of the looked up property does not match \p T
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the getter of
/// the property.
static std::string getValue (Interface iface, const char* propertyName);
/// Sets the value of a property in an interface
///
/// Sets the value of property named \p propertyName in \p iface.
///
/// \param iface the interface to modify
/// \param propertyName the name of the property whose value to set
/// \param value the value to set
///
/// \exception DepthSense::ArgumentException \p iface is unset, or no property named \p propertyName exists in the type of \p iface
/// \exception DepthSense::InvalidOperationException the type of the looked up property does not match \p T
/// \exception std::bad_alloc not enough memory to perform the requested operation
///
/// \note
/// In addition to the exceptions specified above, this method
/// can throw any of the exceptions specified in the setter of
/// the property.
#ifndef DEPTHSENSE_DOC
DEPTHSENSE_API
#endif
static void setValue (Interface iface, const char* propertyName, const char* value);
private:
void *_data;
// does not take ownership of the passed data
Property (void* data);
// takes ownership of the passed data
static Property take (void* data);
DEPTHSENSE_API DSI::String name_p () const;
DEPTHSENSE_API DSI::String getValue_p (Interface iface) const;
DEPTHSENSE_API static DSI::String getValue_p (Interface iface, const char* propertyName);
friend class PropertyBase;
friend class PropertyPrivate;
};
#ifndef DEPTHSENSE_DOC
template <class T>
class Property< std::vector<T> >
{
public:
typedef std::vector<T> Type;
DEPTHSENSE_API Property ();
DEPTHSENSE_API explicit Property (const PropertyBase& prop);
DEPTHSENSE_API Property (const Property& other);
DEPTHSENSE_API Property& operator= (const Property& other);
DEPTHSENSE_API ~Property ();
DEPTHSENSE_API DepthSense::Type declaringType () const;
std::string name () const
{
return name_p().c_str();
}
DEPTHSENSE_API bool isReadOnly () const;
DEPTHSENSE_API bool isReadOnly (Interface iface) const;
DEPTHSENSE_API bool isSet () const;
DEPTHSENSE_API void unset ();
DEPTHSENSE_API bool operator== (const Property& other) const;
DEPTHSENSE_API bool operator!= (const Property& other) const;
// allows to use a property as std::map key
DEPTHSENSE_API bool operator< (const Property& other) const;
DEPTHSENSE_API bool operator> (const Property& other) const;
DEPTHSENSE_API operator PropertyBase () const;
std::vector<T> getValue (Interface iface) const;
void setValue (Interface iface, std::vector<T> value) const;
static std::vector<T> getValue (Interface iface, const char* propertyName);
static void setValue (Interface iface, const char* propertyName, std::vector<T> value);
private:
void *_data;
// does not take ownership of the passed data
Property (void* data);
// takes ownership of the passed data
static Property take (void* data);
DEPTHSENSE_API DSI::String name_p () const;
DEPTHSENSE_API DSI::Vector<T> getValue_p (Interface iface) const;
DEPTHSENSE_API void setValue_p (Interface iface, DSI::Vector<T> value) const;
DEPTHSENSE_API static DSI::Vector<T> getValue_p (Interface iface, const char* propertyName);
DEPTHSENSE_API static void setValue_p (Interface iface, const char* propertyName, DSI::Vector<T> value);
friend class PropertyBase;
friend class PropertyPrivate;
};
#endif
}
#ifdef __DS_HAVE_STD_HASH
namespace std
{
template <>
struct DEPTHSENSE_API hash<DepthSense::PropertyBase>
{
size_t operator() (DepthSense::PropertyBase property) const;
};
}
#endif
#endif