ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Dispatch.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Logging.h>
11 
12 #include "cloudViewer/core/Dtype.h"
13 
31 #define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE, ...) \
32  [&] { \
33  if (DTYPE == cloudViewer::core::Float32) { \
34  using scalar_t = float; \
35  return __VA_ARGS__(); \
36  } else if (DTYPE == cloudViewer::core::Float64) { \
37  using scalar_t = double; \
38  return __VA_ARGS__(); \
39  } else if (DTYPE == cloudViewer::core::Int8) { \
40  using scalar_t = int8_t; \
41  return __VA_ARGS__(); \
42  } else if (DTYPE == cloudViewer::core::Int16) { \
43  using scalar_t = int16_t; \
44  return __VA_ARGS__(); \
45  } else if (DTYPE == cloudViewer::core::Int32) { \
46  using scalar_t = int32_t; \
47  return __VA_ARGS__(); \
48  } else if (DTYPE == cloudViewer::core::Int64) { \
49  using scalar_t = int64_t; \
50  return __VA_ARGS__(); \
51  } else if (DTYPE == cloudViewer::core::UInt8) { \
52  using scalar_t = uint8_t; \
53  return __VA_ARGS__(); \
54  } else if (DTYPE == cloudViewer::core::UInt16) { \
55  using scalar_t = uint16_t; \
56  return __VA_ARGS__(); \
57  } else if (DTYPE == cloudViewer::core::UInt32) { \
58  using scalar_t = uint32_t; \
59  return __VA_ARGS__(); \
60  } else if (DTYPE == cloudViewer::core::UInt64) { \
61  using scalar_t = uint64_t; \
62  return __VA_ARGS__(); \
63  } else { \
64  cloudViewer::utility::LogError("Unsupported data type."); \
65  } \
66  }()
67 
68 #define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE, ...) \
69  [&] { \
70  if (DTYPE == cloudViewer::core::Bool) { \
71  using scalar_t = bool; \
72  return __VA_ARGS__(); \
73  } else { \
74  DISPATCH_DTYPE_TO_TEMPLATE(DTYPE, __VA_ARGS__); \
75  } \
76  }()
77 
78 #define DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(DTYPE, ...) \
79  [&] { \
80  if (DTYPE == cloudViewer::core::Float32) { \
81  using scalar_t = float; \
82  return __VA_ARGS__(); \
83  } else if (DTYPE == cloudViewer::core::Float64) { \
84  using scalar_t = double; \
85  return __VA_ARGS__(); \
86  } else { \
87  cloudViewer::utility::LogError("Unsupported data type."); \
88  } \
89  }()
90 
91 #define DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE(FDTYPE, IDTYPE, ...) \
92  [&] { \
93  if (FDTYPE == cloudViewer::core::Float32 && \
94  IDTYPE == cloudViewer::core::Int32) { \
95  using scalar_t = float; \
96  using int_t = int32_t; \
97  return __VA_ARGS__(); \
98  } else if (FDTYPE == cloudViewer::core::Float32 && \
99  IDTYPE == cloudViewer::core::Int64) { \
100  using scalar_t = float; \
101  using int_t = int64_t; \
102  return __VA_ARGS__(); \
103  } else if (FDTYPE == cloudViewer::core::Float64 && \
104  IDTYPE == cloudViewer::core::Int32) { \
105  using scalar_t = double; \
106  using int_t = int32_t; \
107  return __VA_ARGS__(); \
108  } else if (FDTYPE == cloudViewer::core::Float64 && \
109  IDTYPE == cloudViewer::core::Int64) { \
110  using scalar_t = double; \
111  using int_t = int64_t; \
112  return __VA_ARGS__(); \
113  } else { \
114  cloudViewer::utility::LogError("Unsupported data type."); \
115  } \
116  }()
117 
118 #define DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE(DTYPE, PREFIX, ...) \
119  [&] { \
120  if (DTYPE == cloudViewer::core::Int8) { \
121  using scalar_##PREFIX##_t = int8_t; \
122  return __VA_ARGS__(); \
123  } else if (DTYPE == cloudViewer::core::Int16) { \
124  using scalar_##PREFIX##_t = int16_t; \
125  return __VA_ARGS__(); \
126  } else if (DTYPE == cloudViewer::core::Int32) { \
127  using scalar_##PREFIX##_t = int32_t; \
128  return __VA_ARGS__(); \
129  } else if (DTYPE == cloudViewer::core::Int64) { \
130  using scalar_##PREFIX##_t = int64_t; \
131  return __VA_ARGS__(); \
132  } else if (DTYPE == cloudViewer::core::UInt8) { \
133  using scalar_##PREFIX##_t = uint8_t; \
134  return __VA_ARGS__(); \
135  } else if (DTYPE == cloudViewer::core::UInt16) { \
136  using scalar_##PREFIX##_t = uint16_t; \
137  return __VA_ARGS__(); \
138  } else if (DTYPE == cloudViewer::core::UInt32) { \
139  using scalar_##PREFIX##_t = uint32_t; \
140  return __VA_ARGS__(); \
141  } else if (DTYPE == cloudViewer::core::UInt64) { \
142  using scalar_##PREFIX##_t = uint64_t; \
143  return __VA_ARGS__(); \
144  } else { \
145  cloudViewer::utility::LogError("Unsupported data type."); \
146  } \
147  }()