openPMD-api
Datatype_internal.hpp
1 /* Copyright 2022 Franz Poeschel, Axel Huebl
2  *
3  * This file is part of openPMD-api.
4  *
5  * openPMD-api is free software: you can redistribute it and/or modify
6  * it under the terms of of either the GNU General Public License or
7  * the GNU Lesser 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  * openPMD-api 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 and the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * and the GNU Lesser General Public License along with openPMD-api.
19  * If not, see <http://www.gnu.org/licenses/>.
20  */
21 #pragma once
22 
23 #include "openPMD/auxiliary/TypeTraits.hpp"
24 
25 #include <array>
26 #include <cstddef>
27 #include <vector>
28 
29 namespace openPMD
30 {
31 namespace detail
32 {
33  template <typename DoDetermineDatatype>
35  {
36  using DT = typename DoDetermineDatatype::DT_enum;
37 
38  template <typename T>
39  constexpr static DT call()
40  {
41  if constexpr (auxiliary::IsVector_v<T>)
42  {
43  return DoDetermineDatatype::template call<
44  typename T::value_type>();
45  }
46  else if constexpr (auxiliary::IsArray_v<T>)
47  {
48  return DoDetermineDatatype::template call<
49  typename T::value_type>();
50  }
51  else
52  {
53  return DoDetermineDatatype::template call<T>();
54  }
55 #if defined(__INTEL_COMPILER)
56 /*
57  * ICPC has trouble with if constexpr, thinking that return statements are
58  * missing afterwards. Deactivate the warning.
59  * Note that putting a statement here will not help to fix this since it will
60  * then complain about unreachable code.
61  * https://community.intel.com/t5/Intel-C-Compiler/quot-if-constexpr-quot-and-quot-missing-return-statement-quot-in/td-p/1154551
62  */
63 #pragma warning(disable : 1011)
64  }
65 #pragma warning(default : 1011)
66 #else
67  }
68 #endif
69 
70  constexpr static char const *errorMsg =
71  "basicDatatype: received unknown datatype.";
72  };
73 
74  template <typename DoDetermineDatatype>
75  struct ToVectorType
76  {
77  using DT = typename DoDetermineDatatype::DT_enum;
78 
79  template <typename T>
80  constexpr static DT call()
81  {
82  if constexpr (auxiliary::IsVector_v<T>)
83  {
84  return DoDetermineDatatype::template call<T>();
85  }
86  else if constexpr (auxiliary::IsArray_v<T>)
87  {
88  return DoDetermineDatatype::template call<
89  std::vector<typename T::value_type>>();
90  }
91  else
92  {
93  return DoDetermineDatatype::template call<std::vector<T>>();
94  }
95 #if defined(__INTEL_COMPILER)
96 /*
97  * ICPC has trouble with if constexpr, thinking that return statements are
98  * missing afterwards. Deactivate the warning.
99  * Note that putting a statement here will not help to fix this since it will
100  * then complain about unreachable code.
101  * https://community.intel.com/t5/Intel-C-Compiler/quot-if-constexpr-quot-and-quot-missing-return-statement-quot-in/td-p/1154551
102  */
103 #pragma warning(disable : 1011)
104  }
105 #pragma warning(default : 1011)
106 #else
107  }
108 #endif
109 
110  constexpr static char const *errorMsg =
111  "toVectorType: received unknown datatype.";
112  };
113 } // namespace detail
114 } // namespace openPMD
Public definitions of openPMD-api.
Definition: Date.cpp:29
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:51
Definition: Datatype_internal.hpp:35
Definition: Datatype_internal.hpp:76