UGDK
|
00001 #ifndef UGDK_SCRIPT_PYTHON_PYTHONDATA_H_ 00002 #define UGDK_SCRIPT_PYTHON_PYTHONDATA_H_ 00003 00004 #include <Python.h> 00005 #include <vector> 00006 #include <ugdk/script/virtualdata.h> 00007 #include <ugdk/script/languages/python/pythonwrapper.h> 00008 00009 namespace ugdk { 00010 namespace script { 00011 00012 class VirtualObj; 00013 class VirtualType; 00014 00015 namespace python { 00016 00017 class PythonData : public VirtualData { 00018 public: 00019 PythonData(PythonWrapper* wrapper, PyObject* data_object, bool owns_ref) : VirtualData(), 00020 wrapper_(wrapper), own_ref_(owns_ref), py_data_(data_object) {} 00021 00022 virtual ~PythonData() { 00023 if (own_ref_) 00024 Py_XDECREF(py_data_); 00025 } 00026 00028 virtual void* Unwrap(const VirtualType& type, bool disown) const; 00029 const char* UnwrapString() const; 00030 bool UnwrapBoolean() const; 00031 int UnwrapInteger() const; 00032 double UnwrapNumber() const; 00033 Vector UnwrapVector() const; 00034 List UnwrapList() const; 00035 Map UnwrapMap() const; 00036 00038 virtual void Wrap(void* data, const VirtualType& type); 00039 virtual void WrapString(const char* str); 00040 virtual void WrapBoolean(bool boolean); 00041 virtual void WrapInteger(int number); 00042 virtual void WrapNumber(double number); 00043 00044 virtual LangWrapper* wrapper () const { return wrapper_; } 00045 00048 virtual Ptr Execute(const std::vector<Ptr>& args); 00049 00051 virtual Ptr GetAttribute(Ptr key); 00052 00053 virtual Ptr SetAttribute(Ptr key, Ptr value); 00054 00055 void* unsafe_data() const { 00056 return static_cast<void*>(py_data_); 00057 } 00058 00059 protected: 00060 PythonWrapper* wrapper_; 00061 bool own_ref_; //if true, we own a ref to our PyObject* (py_data_), so we need to DECREF it in due time. 00062 PyObject* py_data_; 00063 }; 00064 00065 } 00066 } /* namespace script */ 00067 } /* namespace ugdk */ 00068 00069 #endif /* UGDK_SCRIPT_PYTHON_PYTHONDATA_H_ */