Lagrange
Loading...
Searching...
No Matches
pcd_utils.h
1/*
2 * Copyright 2026 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/utils/Error.h>
15#include <lagrange/utils/fmt/format.h>
16
17#include <cstdint>
18#include <type_traits>
19
20namespace lagrange::io::internal {
21
24template <typename ValueType>
25constexpr char pcd_type_char()
26{
27 if constexpr (std::is_floating_point_v<ValueType>) {
28 return 'F';
29 } else if constexpr (std::is_signed_v<ValueType>) {
30 return 'I';
31 } else {
32 return 'U';
33 }
34}
35
45template <typename Func>
46void dispatch_pcd_type(char type, int size, Func&& func)
47{
48 switch (type) {
49 case 'F':
50 if (size == 4) return void(func(float{}));
51 if (size == 8) return void(func(double{}));
52 break;
53 case 'I':
54 if (size == 1) return void(func(int8_t{}));
55 if (size == 2) return void(func(int16_t{}));
56 if (size == 4) return void(func(int32_t{}));
57 if (size == 8) return void(func(int64_t{}));
58 break;
59 case 'U':
60 if (size == 1) return void(func(uint8_t{}));
61 if (size == 2) return void(func(uint16_t{}));
62 if (size == 4) return void(func(uint32_t{}));
63 if (size == 8) return void(func(uint64_t{}));
64 break;
65 default: break;
66 }
67 throw Error(lagrange::format("Unsupported PCD field type '{}' with size {}", type, size));
68}
69
70} // namespace lagrange::io::internal
void dispatch_pcd_type(char type, int size, Func &&func)
Dispatches a (type, size) pair from a PCD header to the matching C++ value type and invokes func with...
Definition pcd_utils.h:46
constexpr char pcd_type_char()
Returns the PCD TYPE character corresponding to a C++ value type: signed integer ('I'),...
Definition pcd_utils.h:25
@ Error
Throw an error if collision is detected.
Definition MappingPolicy.h:24