PLYwoot
Header-only C++17 library for parsing and writing PLY files
Loading...
Searching...
No Matches
reflect.hpp
Go to the documentation of this file.
1/*
2 This file is part of PLYwoot, a header-only PLY parser.
3
4 Copyright (C) 2023-2025, Ton van den Heuvel
5
6 PLYwoot is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef PLYWOOT_REFLECT_HPP
21#define PLYWOOT_REFLECT_HPP
22
24
25#include <type_traits>
26#include <vector>
27
28namespace plywoot::reflect {
29
34template<typename T, typename = void>
35struct Type
36{
38 using DestT = T;
39};
40
41template<typename T>
42struct Type<T, typename std::void_t<typename T::DestT>>
43{
45 using DestT = typename T::DestT;
46};
48
52template<typename T, std::size_t N>
53struct Array
54{
56 using DestT = T;
57};
58
61struct Skip
62{
63};
64
67template<typename T>
68struct Stride
69{
70};
71
74template<typename T, std::size_t N>
75struct Pack
76{
78 using DestT = T;
81 static constexpr std::size_t size = N;
82};
83
93template<typename... Ts>
94class Layout
95{
96public:
98 Layout() = default;
99
104 template<typename T>
105 Layout(const std::vector<T> &v)
106 : cdata_{reinterpret_cast<const std::uint8_t *>(v.data())},
107 size_{v.size()},
108 alignment_{alignof(T)}
109 {
110 }
111
117 const std::uint8_t *data() const { return cdata_; }
118
124 std::size_t size() const { return size_; }
125
129 std::size_t alignment() const { return alignment_; }
130
131private:
134 const std::uint8_t *cdata_{nullptr};
137 std::size_t size_{0};
140 std::size_t alignment_{0};
141};
142
143}
144
145#endif
Layout()=default
Constructor for an empty layout (no data will be read/written).
Layout(const std::vector< T > &v)
Definition reflect.hpp:105
std::size_t alignment() const
Definition reflect.hpp:129
std::size_t size() const
Definition reflect.hpp:124
const std::uint8_t * data() const
Definition reflect.hpp:117
T DestT
Type of the elements in the destination list type.
Definition reflect.hpp:56
T DestT
Type of the member types in the target type to pack.
Definition reflect.hpp:78
static constexpr std::size_t size
Definition reflect.hpp:81
T DestT
Target property type.
Definition reflect.hpp:38