IODA
macros.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * (C) Copyright 2020 UCAR
4  *
5  * This software is licensed under the terms of the Apache Licence Version 2.0
6  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7  */
8 /// \file macros.h
9 /// \brief Python bindings - macros
10 
11 #include <string>
12 #include <vector>
13 
14 #ifdef _MSC_FULL_VER
15 #pragma warning(disable : 4267) // Python interface
16 #endif
17 #if defined(__GNUC__)
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wunused-value"
20 #endif
21 
22 #define TYPE_TEMPLATE(x) \
23  x<std::string>(); \
24  x<float>(); \
25  x<double>(); \
26  x<long double>(); \
27  x<char>(); \
28  x<unsigned char>(); \
29  x<signed char>(); \
30  x<wchar_t>(); \
31  x<char16_t>(); \
32  x<char32_t>(); \
33  x<bool>(); \
34  x<short int>(); \
35  x<unsigned short int>(); \
36  x<int>(); \
37  x<unsigned int>(); \
38  x<long int>(); \
39  x<unsigned long int>(); \
40  x<long long int>(); \
41  x<unsigned long long int>();
42 
43 #define SETFILL_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
44  .def(funcnamestr, &classname ::funcname<T>)
45 
46 #define VARCREATE_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
47  .def(funcnamestr, \
48  (Variable(classname::*)(const std::string&, const std::vector<Dimensions_t>&, \
49  const std::vector<Dimensions_t>&, const VariableCreationParameters&)) & \
50  classname ::funcname<T>, \
51  "Create a variable", py::arg("name"), py::arg("dimensions") = std::vector<Dimensions_t>{1}, \
52  py::arg("max_dimensions") = std::vector<Dimensions_t>{}, \
53  py::arg("params") = VariableCreationParameters())
54 
55 #define VARCREATESCALES_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
56  .def(funcnamestr, \
57  (Variable(classname::*)(const std::string&, const std::vector<Variable>&, \
58  const VariableCreationParameters&)) & \
59  classname ::funcname<T>, \
60  "Create a variable", py::arg("name"), py::arg("dimension_scales"), \
61  py::arg("params") = VariableCreationParameters())
62 
63 #define ISA_ATT_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
64  .def(funcnamestr, &classname ::funcname<T>, "Is " #T " the storage type of the data?")
65 
66 #define READ_ATT_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
67  .def(funcnamestr, &classname ::funcname<T>, "Read as type " #T)
68 
69 #define WRITE_ATT_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
70  .def(funcnamestr, &classname ::funcname<T>, "Write as type " #T)
71 
72 #define READ_VAR_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
73  .def(funcnamestr, &classname ::funcname<T>, "Read as type " #T, py::arg("mem_selection") = Selection::all, \
74  py::arg("file_selection") = Selection::all)
75 
76 #define WRITE_VAR_CLASS_TEMPLATE_FUNCTION_T(funcnamestr, funcname, classname, T) \
77  .def(funcnamestr, &classname ::funcname<T>, "Write as type " #T, py::arg("vals"), \
78  py::arg("mem_selection") = Selection::all, py::arg("file_selection") = Selection::all)
79 
80 #define CLASS_TEMPLATE_FUNCTION_PATTERN_NOALIASES(actualname, classname, PATTERN) \
81  PATTERN("float", actualname, classname, float) \
82  PATTERN("double", actualname, classname, double) \
83  PATTERN("long_double", actualname, classname, long double) \
84  PATTERN("int32", actualname, classname, int32_t) \
85  PATTERN("uint32", actualname, classname, uint32_t) \
86  PATTERN("int16", actualname, classname, int16_t) \
87  PATTERN("uint16", actualname, classname, uint16_t) \
88  PATTERN("int64", actualname, classname, int64_t) \
89  PATTERN("uint64", actualname, classname, uint64_t)
90 /*
91 // bool has some problems
92 PATTERN("bool", funcname, classname, bool) \
93 */
94 
95 #define CLASS_TEMPLATE_FUNCTION_PATTERN_NOSTR(actualname, classname, PATTERN) \
96  CLASS_TEMPLATE_FUNCTION_PATTERN_NOALIASES(actualname, classname, PATTERN) \
97  PATTERN("short", actualname, classname, short int) \
98  PATTERN("ushort", actualname, classname, unsigned short int) \
99  PATTERN("int", actualname, classname, int) \
100  PATTERN("uint", actualname, classname, unsigned int) \
101  PATTERN("lint", actualname, classname, long int) \
102  PATTERN("ulint", actualname, classname, unsigned long int) \
103  PATTERN("llint", actualname, classname, long long int) \
104  PATTERN("ullint", actualname, classname, unsigned long long int)
105 
106 #define CLASS_TEMPLATE_FUNCTION_PATTERN(actualname, classname, PATTERN) \
107  PATTERN("str", actualname, classname, std::string) \
108  PATTERN("char", actualname, classname, char) \
109  CLASS_TEMPLATE_FUNCTION_PATTERN_NOSTR(actualname, classname, PATTERN)