HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PyImathFixedArrayTraits.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5 
6 // clang-format off
7 
8 #ifndef _PYIMATH_FIXEDARRAY_TRAITS_H
9 #define _PYIMATH_FIXEDARRAY_TRAITS_H
10 
11 #include <Python.h>
12 #include <ImathVec.h>
13 #include <half.h>
14 #include <string>
15 
16 
17 namespace PyImath {
18 
19 // See https://docs.python.org/2/library/struct.html
20 //
21 // Section 7.3.2.2
22 //
23 static char PyFmtStr_int[2] = {'i', '\0'};
24 static char PyFmtStr_float[2] = {'f', '\0'};
25 static char PyFmtStr_double[2] = {'d', '\0'};
26 static char PyFmtStr_bool[2] = {'?', '\0'};
27 static char PyFmtStr_char[2] = {'b', '\0'};
28 static char PyFmtStr_short[2] = {'h', '\0'};
29 static char PyFmtStr_long[2] = {'l', '\0'};
30 static char PyFmtStr_longlong[2] = {'q', '\0'};
31 static char PyFmtStr_uchar[2] = {'B', '\0'};
32 static char PyFmtStr_ushort[2] = {'H', '\0'};
33 static char PyFmtStr_uint[2] = {'I', '\0'};
34 static char PyFmtStr_ulong[2] = {'L', '\0'};
35 static char PyFmtStr_ulonglong[2] = {'Q', '\0'};
36 static char PyFmtStr_half[2] = {'e', '\0'};
37 
38 
39 template <typename T> constexpr char* PyFormat();
40 
41 template <> constexpr char* PyFormat<int>() { return PyFmtStr_int; }
42 template <> constexpr char* PyFormat<float>() { return PyFmtStr_float; }
43 template <> constexpr char* PyFormat<double>() { return PyFmtStr_double; }
44 template <> constexpr char* PyFormat<bool>() { return PyFmtStr_bool; }
45 template <> constexpr char* PyFormat<char>() { return PyFmtStr_char; }
46 template <> constexpr char* PyFormat<short>() { return PyFmtStr_short; }
47 template <> constexpr char* PyFormat<long>() { return PyFmtStr_long; }
48 template <> constexpr char* PyFormat<long long>() { return PyFmtStr_longlong; }
49 template <> constexpr char* PyFormat<unsigned char>() { return PyFmtStr_uchar; }
50 template <> constexpr char* PyFormat<unsigned short>() { return PyFmtStr_ushort; }
51 template <> constexpr char* PyFormat<unsigned int>() { return PyFmtStr_uint; }
52 template <> constexpr char* PyFormat<unsigned long>() { return PyFmtStr_ulong; }
53 template <> constexpr char* PyFormat<unsigned long long>() { return PyFmtStr_ulonglong; }
54 template <> constexpr char* PyFormat<half>() { return PyFmtStr_half; }
55 
56 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec2<short> >() { return PyFmtStr_short; }
57 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec2<int> >() { return PyFmtStr_int; }
58 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec2<int64_t> >() { return PyFmtStr_long; }
59 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec2<float> >() { return PyFmtStr_float; }
60 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec2<double> >() { return PyFmtStr_double; }
61 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec3<short> >() { return PyFmtStr_short; }
62 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec3<int> >() { return PyFmtStr_int; }
63 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec3<int64_t> >() { return PyFmtStr_long; }
64 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec3<float> >() { return PyFmtStr_float; }
65 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec3<double> >() { return PyFmtStr_double; }
66 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec4<short> >() { return PyFmtStr_short; }
67 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec4<int> >() { return PyFmtStr_int; }
68 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec4<int64_t> >() { return PyFmtStr_long; }
69 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec4<float> >() { return PyFmtStr_float; }
70 template <> constexpr char* PyFormat<IMATH_NAMESPACE::Vec4<double> >() { return PyFmtStr_double; }
71 
72 
73 template <typename T> struct FixedArrayWidth { static const Py_ssize_t value; };
74 
75 template <> struct FixedArrayWidth<short> { static const Py_ssize_t value = 1; };
76 template <> struct FixedArrayWidth<int> { static const Py_ssize_t value = 1; };
77 template <> struct FixedArrayWidth<int64_t> { static const Py_ssize_t value = 1; };
78 template <> struct FixedArrayWidth<float> { static const Py_ssize_t value = 1; };
79 template <> struct FixedArrayWidth<double> { static const Py_ssize_t value = 1; };
80 template <> struct FixedArrayWidth<unsigned char> { static const Py_ssize_t value = 1; };
81 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec2<short> > { static const Py_ssize_t value = 2; };
82 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec2<int> > { static const Py_ssize_t value = 2; };
83 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec2<int64_t> > { static const Py_ssize_t value = 2; };
84 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec2<float> > { static const Py_ssize_t value = 2; };
85 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec2<double> > { static const Py_ssize_t value = 2; };
86 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec3<short> > { static const Py_ssize_t value = 3; };
87 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec3<int> > { static const Py_ssize_t value = 3; };
88 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec3<int64_t> > { static const Py_ssize_t value = 3; };
89 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec3<float> > { static const Py_ssize_t value = 3; };
90 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec3<double> > { static const Py_ssize_t value = 3; };
91 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec4<short> > { static const Py_ssize_t value = 4; };
92 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec4<int> > { static const Py_ssize_t value = 4; };
93 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec4<int64_t> > { static const Py_ssize_t value = 4; };
94 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec4<float> > { static const Py_ssize_t value = 4; };
95 template <> struct FixedArrayWidth<IMATH_NAMESPACE::Vec4<double> > { static const Py_ssize_t value = 4; };
96 
97 
98 template <typename T> struct FixedArrayDimension { static const Py_ssize_t value; };
99 
100 template <> struct FixedArrayDimension<short> { static const Py_ssize_t value = 1; };
101 template <> struct FixedArrayDimension<int> { static const Py_ssize_t value = 1; };
102 template <> struct FixedArrayDimension<int64_t> { static const Py_ssize_t value = 1; };
103 template <> struct FixedArrayDimension<float> { static const Py_ssize_t value = 1; };
104 template <> struct FixedArrayDimension<double> { static const Py_ssize_t value = 1; };
105 template <> struct FixedArrayDimension<unsigned char> { static const Py_ssize_t value = 1; };
106 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec2<short> > { static const Py_ssize_t value = 2; };
107 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec2<int> > { static const Py_ssize_t value = 2; };
108 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec2<int64_t> > { static const Py_ssize_t value = 2; };
109 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec2<float> > { static const Py_ssize_t value = 2; };
110 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec2<double> > { static const Py_ssize_t value = 2; };
111 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec3<short> > { static const Py_ssize_t value = 2; };
112 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec3<int> > { static const Py_ssize_t value = 2; };
113 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec3<int64_t> > { static const Py_ssize_t value = 2; };
114 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec3<float> > { static const Py_ssize_t value = 2; };
115 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec3<double> > { static const Py_ssize_t value = 2; };
116 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec4<short> > { static const Py_ssize_t value = 2; };
117 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec4<int> > { static const Py_ssize_t value = 2; };
118 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec4<int64_t> > { static const Py_ssize_t value = 2; };
119 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec4<float> > { static const Py_ssize_t value = 2; };
120 template <> struct FixedArrayDimension<IMATH_NAMESPACE::Vec4<double> > { static const Py_ssize_t value = 2; };
121 
122 
123 template <typename T> struct FixedArrayAtomicSize { static const Py_ssize_t value; };
124 
125 template <> struct FixedArrayAtomicSize<short> { static const Py_ssize_t value = sizeof(short); };
126 template <> struct FixedArrayAtomicSize<int> { static const Py_ssize_t value = sizeof(int); };
127 template <> struct FixedArrayAtomicSize<int64_t> { static const Py_ssize_t value = sizeof(int); };
128 template <> struct FixedArrayAtomicSize<float> { static const Py_ssize_t value = sizeof(float); };
129 template <> struct FixedArrayAtomicSize<double> { static const Py_ssize_t value = sizeof(double); };
130 template <> struct FixedArrayAtomicSize<unsigned char> { static const Py_ssize_t value = sizeof(unsigned char); };
131 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec2<short> > { static const Py_ssize_t value = sizeof(short); };
132 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec2<int> > { static const Py_ssize_t value = sizeof(int); };
133 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec2<int64_t> > { static const Py_ssize_t value = sizeof(int64_t); };
134 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec2<float> > { static const Py_ssize_t value = sizeof(float); };
135 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec2<double> > { static const Py_ssize_t value = sizeof(double); };
136 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec3<short> > { static const Py_ssize_t value = sizeof(short); };
137 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec3<int> > { static const Py_ssize_t value = sizeof(int); };
138 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec3<int64_t> > { static const Py_ssize_t value = sizeof(int64_t); };
139 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec3<float> > { static const Py_ssize_t value = sizeof(float); };
140 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec3<double> > { static const Py_ssize_t value = sizeof(double); };
141 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec4<short> > { static const Py_ssize_t value = sizeof(short); };
142 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec4<int> > { static const Py_ssize_t value = sizeof(int); };
143 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec4<int64_t> > { static const Py_ssize_t value = sizeof(int64_t); };
144 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec4<float> > { static const Py_ssize_t value = sizeof(float); };
145 template <> struct FixedArrayAtomicSize<IMATH_NAMESPACE::Vec4<double> > { static const Py_ssize_t value = sizeof(double); };
146 
147 } // namespace
148 
149 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
Definition: ImathVec.h:40
#define IMATH_NAMESPACE
Definition: ImathConfig.h:43
constexpr char * PyFormat< half >()
GLsizei const GLfloat * value
Definition: glcorearb.h:824
constexpr char * PyFormat< char >()
constexpr char * PyFormat< short >()
constexpr char * PyFormat< long long >()
constexpr char * PyFormat< unsigned long long >()
constexpr char * PyFormat< unsigned int >()
constexpr char * PyFormat< unsigned long >()
IMATH_NAMESPACE::V2f IMATH_NAMESPACE::Box2i std::string this attribute is obsolete as of OpenEXR v3 float
Definition: ImathVec.h:39
static const Py_ssize_t value
constexpr char * PyFormat< double >()
constexpr char * PyFormat< int >()
constexpr char * PyFormat< unsigned char >()
constexpr char * PyFormat< float >()
constexpr char * PyFormat< long >()
Definition: ImathVec.h:41
constexpr char * PyFormat< unsigned short >()
constexpr char * PyFormat()
constexpr char * PyFormat< bool >()