UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pythondata.h
Go to the documentation of this file.
1 #ifndef UGDK_SCRIPT_PYTHON_PYTHONDATA_H_
2 #define UGDK_SCRIPT_PYTHON_PYTHONDATA_H_
3 
4 #include <Python.h>
5 #include <vector>
8 
9 namespace ugdk {
10 namespace script {
11 
12 class VirtualObj;
13 class VirtualType;
14 
15 namespace python {
16 
17 class PythonData : public VirtualData {
18  public:
19  PythonData(PythonWrapper* wrapper, PyObject* data_object, bool owns_ref) : VirtualData(),
20  wrapper_(wrapper), own_ref_(owns_ref), py_data_(data_object) {}
21 
22  virtual ~PythonData() {
23  if (own_ref_)
24  Py_XDECREF(py_data_);
25  }
26 
28  virtual void* Unwrap(const VirtualType& type, bool disown) const;
29  const char* UnwrapString() const;
30  bool UnwrapBoolean() const;
31  int UnwrapInteger() const;
32  double UnwrapNumber() const;
33  Vector UnwrapVector() const;
34  List UnwrapList() const;
35  Map UnwrapMap() const;
36 
38  virtual void Wrap(void* data, const VirtualType& type);
39  virtual void WrapString(const char* str);
40  virtual void WrapBoolean(bool boolean);
41  virtual void WrapInteger(int number);
42  virtual void WrapNumber(double number);
43 
44  virtual LangWrapper* wrapper () const { return wrapper_; }
45 
48  virtual Ptr Execute(const std::vector<Ptr>& args);
49 
51  virtual Ptr GetAttribute(Ptr key);
52 
53  virtual Ptr SetAttribute(Ptr key, Ptr value);
54 
55  void* unsafe_data() const {
56  return static_cast<void*>(py_data_);
57  }
58 
59  protected:
61  bool own_ref_; //if true, we own a ref to our PyObject* (py_data_), so we need to DECREF it in due time.
62  PyObject* py_data_;
63 };
64 
65 }
66 } /* namespace script */
67 } /* namespace ugdk */
68 
69 #endif /* UGDK_SCRIPT_PYTHON_PYTHONDATA_H_ */