kDB: Knowledge DataBase
Loading...
Searching...
No Matches
Point.h
1#ifndef _KDBPOINTCLOUDS_POINT_H_
2#define _KDBPOINTCLOUDS_POINT_H_
3
4#include <QByteArray>
5#include <QSharedDataPointer>
6
7#include <tuple>
8
9namespace kDBPointClouds
10{
11 class PointSpecification;
12
13 class Point
14 {
15 friend class Patch;
16 public:
17 Point();
18 Point(const PointSpecification& _specification);
19 Point(const Point& _rhs);
20 Point& operator=(const Point& _rhs);
21 ~Point();
22 private:
23 template<int Index>
24 struct setter;
25 template<int Index>
26 struct getter;
27 public:
28 template<typename... Types>
29 inline void set(const std::tuple<Types...>& _values);
30 template<typename... Types>
31 void set(Types... _values)
32 {
33 set(std::make_tuple(_values...));
34 }
35 template<typename... Types>
36 inline std::tuple<Types...> get() const;
37 bool operator==(const Point& _point) const;
38 private:
39 QByteArray& array();
40 QByteArray array() const;
41 private:
42 struct Private;
43 QSharedDataPointer<Private> d;
44 };
45
46 template<>
47 struct Point::setter<0>
48 {
49 template<typename... Types>
50 inline static void doit(std::size_t _pos, QByteArray& _data,
51 const std::tuple<Types...>& _values)
52 {
53 Q_UNUSED(_pos);
54 Q_UNUSED(_data);
55 Q_UNUSED(_values);
56 }
57 };
58
59 template<int Index_>
61 {
62 template<typename... Types>
63 inline static void doit(std::size_t _pos, QByteArray& _data,
64 const std::tuple<Types...>& _values)
65 {
66 constexpr int Index = sizeof...(Types) - Index_;
67 using ValType = typename std::tuple_element<Index, std::tuple<Types...>>::type;
68 ValType val = std::get<Index>(_values);
69 std::size_t val_size = sizeof(ValType);
70 memcpy(_data.data() + _pos, &val, val_size);
71 Point::setter<Index_ - 1>::doit(_pos + val_size, _data, _values);
72 }
73 };
74
75 template<>
76 struct Point::getter<0>
77 {
78 template<typename... Types>
79 inline static void doit(std::size_t _pos, const QByteArray& _data,
80 std::tuple<Types...>& _values)
81 {
82 Q_UNUSED(_pos);
83 Q_UNUSED(_data);
84 Q_UNUSED(_values);
85 }
86 };
87
88 template<int Index_>
90 {
91 template<typename... Types>
92 inline static void doit(std::size_t _pos, const QByteArray& _data,
93 std::tuple<Types...>& _values)
94 {
95 constexpr int Index = sizeof...(Types) - Index_;
96 using ValType = typename std::tuple_element<Index, std::tuple<Types...>>::type;
97 ValType val;
98 std::size_t val_size = sizeof(ValType);
99 memcpy(&val, _data.data() + _pos, val_size);
100 std::get<Index>(_values) = val;
101 Point::getter<Index_ - 1>::doit(_pos + val_size, _data, _values);
102 }
103 };
104
105 template<typename... Types>
106 void Point::set(const std::tuple<Types...>& _values)
107 {
108 setter<sizeof...(Types)>::doit(0, array(), _values);
109 }
110 template<typename... Types>
111 std::tuple<Types...> Point::get() const
112 {
113 std::tuple<Types...> values;
114 getter<sizeof...(Types)>::doit(0, array(), values);
115 return values;
116 }
117} // namespace kDBPointClouds
118
119#endif
Definition Patch.h:18
Definition PointSpecification.h:13
Definition Point.h:14
Definition Point.h:90
Definition Point.h:61