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
23 private:
24 template<int Index>
25 struct setter;
26 template<int Index>
27 struct getter;
28 public:
29 template<typename... Types>
30 inline void set(const std::tuple<Types...>& _values);
31 template<typename... Types>
32 void set(Types... _values) {
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, const std::tuple<Types...>& _values)
51 {
52 Q_UNUSED(_pos);
53 Q_UNUSED(_data);
54 Q_UNUSED(_values);
55 }
56 };
57
58 template<int Index_>
60 {
61 template<typename... Types>
62 inline static void doit(std::size_t _pos, QByteArray& _data, const std::tuple<Types...>& _values)
63 {
64 constexpr int Index = sizeof...(Types) - Index_;
65 using ValType = typename std::tuple_element<Index, std::tuple<Types...>>::type;
66 ValType val = std::get<Index>(_values);
67 std::size_t val_size = sizeof(ValType);
68 memcpy(_data.data() + _pos, &val, val_size);
69 Point::setter<Index_-1>::doit(_pos + val_size, _data, _values);
70 }
71 };
72
73 template<>
74 struct Point::getter<0>
75 {
76 template<typename... Types>
77 inline static void doit(std::size_t _pos, const QByteArray& _data, std::tuple<Types...>& _values)
78 {
79 Q_UNUSED(_pos);
80 Q_UNUSED(_data);
81 Q_UNUSED(_values);
82 }
83 };
84
85 template<int Index_>
87 {
88 template<typename... Types>
89 inline static void doit(std::size_t _pos, const QByteArray& _data, std::tuple<Types...>& _values)
90 {
91 constexpr int Index = sizeof...(Types) - Index_;
92 using ValType = typename std::tuple_element<Index, std::tuple<Types...>>::type;
93 ValType val;
94 std::size_t val_size = sizeof(ValType);
95 memcpy(&val, _data.data() + _pos, val_size);
96 std::get<Index>(_values) = val;
97 Point::getter<Index_-1>::doit(_pos + val_size, _data, _values);
98 }
99 };
100
101 template<typename... Types>
102 void Point::set(const std::tuple<Types...>& _values)
103 {
104 setter<sizeof...(Types)>::doit(0, array(), _values);
105 }
106 template<typename... Types>
107 std::tuple<Types...> Point::get() const
108 {
109 std::tuple<Types...> values;
110 getter<sizeof...(Types)>::doit(0, array(), values);
111 return values;
112 }
113}
114
115#endif
Definition Patch.h:16
Definition PointSpecification.h:12
Definition Point.h:14
Definition Point.h:87
Definition Point.h:60