-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCPyObject.h
161 lines (146 loc) · 3.59 KB
/
CPyObject.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "Python.h"
#include <string>
class CPyIter;
class CPyTuple;
class CPyList;
class CPyString;
class CPyLong;
class CPyFloat;
class CPyNumber;
class CPyObject
{
public:
CPyObject();
CPyObject(PyObject *obj);
CPyObject(const CPyObject &cobj);
CPyObject(CPyObject &&cobj) noexcept;
~CPyObject();
CPyObject Call(const CPyTuple &args) const;
const CPyObject GetAttr(const CPyString &name) const;
bool SetAttr(const CPyString &name, const CPyObject &value);
bool DelAttr(const CPyString &name);
const CPyObject GetItem(ssize_t pos) const;
ssize_t Len() const;
CPyString Str() const;
CPyObject Type() const;
CPyIter GetIter() const;
CPyTuple AsTuple() const;
CPyList AsList() const;
CPyString AsString() const;
CPyLong AsLong() const;
CPyFloat AsFloat() const;
CPyNumber AsNumber() const;
bool IsTuple() const;
bool IsList() const;
bool IsString() const;
bool IsLong() const;
bool IsFloat() const;
bool IsNumber() const;
PyObject *GetRawObject() const;
CPyObject &operator =(const CPyObject &cobj);
CPyObject &operator =(CPyObject &&cobj) noexcept;
bool operator ==(const CPyObject &cobj) const;
bool operator !=(const CPyObject &cobj) const;
const CPyObject operator [](ssize_t pos) const;
operator CPyTuple() const;
operator CPyList() const;
operator CPyString() const;
operator CPyLong() const;
operator CPyFloat() const;
operator CPyNumber() const;
friend std::ostream & operator <<(std::ostream &stream, const CPyObject &cobj);
protected:
int Check2(int val) const;
Py_ssize_t Check3(Py_ssize_t val) const;
PyObject *CheckObj(PyObject *obj) const;
void CheckErr() const;
PyObject *m_obj;
private:
void SetObject(PyObject *obj);
void CopyObject(PyObject *obj);
};
class CPyException
{
public:
explicit CPyException(const CPyString &text);
const std::string &GetText() const;
private:
std::string m_text;
};
class CPyModule : public CPyObject
{
public:
explicit CPyModule(const CPyString &name);
CPyModule(PyObject *obj);
void Reload();
};
class CPyIter : public CPyObject
{
public:
CPyIter(PyObject *obj);
bool HasNext() const;
CPyObject Next();
private:
PyObject *m_next;
};
class CPyTuple : public CPyObject
{
public:
CPyTuple();
CPyTuple(ssize_t size);
CPyTuple(PyObject *obj);
CPyObject GetSlice(ssize_t low, ssize_t high) const;
CPyObject GetItem(ssize_t pos) const;
bool SetItem(ssize_t pos, const CPyObject& cobj);
ssize_t Size() const;
};
class CPyList : public CPyObject
{
public:
CPyList();
CPyList(ssize_t size);
CPyList(PyObject *obj);
void Append(const CPyObject& cobj);
CPyObject GetSlice(ssize_t low, ssize_t high) const;
CPyObject GetItem(ssize_t pos) const;
bool SetItem(ssize_t pos, const CPyObject& cobj);
ssize_t Size() const;
};
class CPyString : public CPyObject
{
public:
CPyString();
CPyString(const char *str);
CPyString(const std::string &str);
CPyString(PyObject *obj);
operator std::string() const;
};
class CPyLong : public CPyObject
{
public:
CPyLong();
CPyLong(long long val);
CPyLong(unsigned long long val);
CPyLong(PyObject *obj);
operator long() const;
operator long long() const;
operator unsigned long() const;
operator unsigned long long() const;
};
class CPyFloat : public CPyObject
{
public:
CPyFloat();
CPyFloat(double val);
CPyFloat(PyObject *obj);
operator double() const;
};
class CPyNumber : public CPyObject
{
public:
CPyNumber();
CPyNumber(ssize_t val);
CPyNumber(PyObject *obj);
CPyNumber operator >>(int shift) const;
operator unsigned long long() const;
};