forked from chaosct/ofxPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofxPython.h
More file actions
142 lines (131 loc) · 4.22 KB
/
Copy pathofxPython.h
File metadata and controls
142 lines (131 loc) · 4.22 KB
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
#pragma once
#include "ofTypes.h"
extern "C"{
#include <Python.h>
}
class ofxPythonObjectManaged;
class ofxPythonMappingValue;
class ofxPythonAttrValue;
class ofxPythonTupleMaker;
class ofxPythonObject: public ofPtr<ofxPythonObjectManaged>
{
public:
ofxPythonObject method(const string &method_name); //call method without arguments
ofxPythonObject operator ()(); //call objects without arguments
ofxPythonObject operator ()(ofxPythonObject); //call objects 1 argument
ofxPythonObject operator ()(ofxPythonObject, ofxPythonObject); //call objects 2 arguments
ofxPythonObject operator ()(ofxPythonObject, ofxPythonObject, ofxPythonObject); //call objects 3 arguments
ofxPythonAttrValue attr(const string& attribute);
ofxPythonMappingValue operator [](const string& key);
ofxPythonMappingValue operator [](const char * key);
bool isNone() const;
bool isBool() const;
bool isInt() const;
bool isFloat() const;
bool isString() const;
bool isList() const;
bool isTuple() const;
bool asBool( ) const;
long int asInt() const;
double asFloat() const;
string asString() const;
vector<ofxPythonObject> asVector() const;
static ofxPythonObject _None();
static ofxPythonObject fromBool(bool);
static ofxPythonObject fromInt(long int);
static ofxPythonObject fromFloat(double);
static ofxPythonObject fromString(const string&);
// use makeTuple like this:
// ofxPythonObject tuple = ofxPythonObject::makeTuple() << obj1 << obj2 << obj3;
static ofxPythonTupleMaker makeTuple();
operator bool() const;
const string repr();
protected:
void insert_borrowed(PyObject *);
void insert_owned(PyObject *);
friend ofxPythonObject make_object_owned(PyObject * obj, bool);
friend ofxPythonObject make_object_borrowed(PyObject * obj, bool);
friend class ofxPython;
};
class ofxPython
{
public:
ofxPython();
virtual ~ofxPython();
int init(); //returns the number of ofxPython instances,
//if it's 1 you should initialize your custom bindings if any
void reset();
void executeScript(const string& path);
void executeString(const string& script);
ofxPythonObject evalString(const string& expression);
static ofxPythonObject getObject(const string& name, const string& module);
ofxPythonObject getObject(const string& name);
void setObject(const string& name, ofxPythonObject o);
protected:
// ofxPythonObject globals;
ofxPythonObject locals;
static unsigned int instances;
bool initialized;
friend class ofxPythonObjectManaged;
};
class ofxPythonObjectManaged
{
public:
ofxPythonObjectManaged(PyObject*);
~ofxPythonObjectManaged();
PyObject * obj;
};
class ofxPythonObjectLike
{
public:
ofxPythonObject method(const string &method_name); //call method without arguments
ofxPythonObject operator ()(); //call objects without arguments
ofxPythonObject operator ()(ofxPythonObject); //call objects 1 argument
ofxPythonObject operator ()(ofxPythonObject, ofxPythonObject); //call objects 2 arguments
ofxPythonObject operator ()(ofxPythonObject, ofxPythonObject, ofxPythonObject); //call objects 3 arguments
ofxPythonAttrValue attr(const string& attribute);
ofxPythonMappingValue operator [](const string& key);
ofxPythonMappingValue operator [](const char * key);
bool isNone();
bool isBool();
bool isInt();
bool isFloat();
bool isString();
bool isList();
bool isTuple();
bool asBool();
long int asInt();
double asFloat();
string asString();
vector<ofxPythonObject> asVector();
operator bool();
const string repr();
virtual operator ofxPythonObject()=0;
};
class ofxPythonMappingValue: public ofxPythonObjectLike
{
ofxPythonObject object;
string key;
public:
ofxPythonMappingValue(ofxPythonObject o, const string& k);
operator ofxPythonObject();
ofxPythonMappingValue & operator =(ofxPythonObject);
ofxPythonMappingValue & operator =(ofxPythonMappingValue & o);
};
class ofxPythonAttrValue: public ofxPythonObjectLike
{
ofxPythonObject object;
string attribute;
public:
ofxPythonAttrValue(ofxPythonObject o, const string& attr);
operator ofxPythonObject();
ofxPythonAttrValue & operator =(ofxPythonObject);
ofxPythonAttrValue & operator =(ofxPythonAttrValue & o);
};
class ofxPythonTupleMaker: public ofxPythonObjectLike
{
vector<ofxPythonObject> contents;
public:
ofxPythonTupleMaker& operator<<(ofxPythonObject);
operator ofxPythonObject();
};