-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteger.h
52 lines (38 loc) · 885 Bytes
/
Integer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include "./PythonCore.h"
#include <concepts>
#include "./Object.h"
namespace xpo {
namespace python {
struct Integer : public Object {
Integer(PyObject* pyObject)
: Object(PyLong_Check(pyObject) ? pyObject : nullptr)
{
}
template <std::integral V>
Integer(V value)
: Object(PyLong_FromLongLong(value))
{
}
template <std::floating_point V>
Integer(V value)
: Object(PyLong_FromDouble(value))
{
}
Integer(char const* str, char** pend = nullptr, int base = 0)
: Object(PyLong_FromString(str, pend, base))
{
}
template <class T>
requires std::is_integral_v<T>
operator T() {
return static_cast<T>(PyLong_AsLongLong(m_pyObject));
}
template <class T>
requires std::is_floating_point_v<T>
operator T() {
return static_cast<T>(PyLong_AsDouble(m_pyObject));
}
};
}
}