use ffi;
use python::{Python, PythonObject, ToPythonPointer};
use conversion::ToPyObject;
use err::{self, PyResult};
use super::object::PyObject;
use super::tuple::PyTuple;
use super::dict::PyDict;
pub struct PyClass(PyObject);
pyobject_newtype!(PyClass, PyClass_Check, PyClass_Type);
pub struct PyInstance(PyObject);
pyobject_newtype!(PyInstance, PyInstance_Check, PyInstance_Type);
impl PyClass {
pub fn is_subclass_of(&self, _py: Python, base: &PyClass) -> bool {
unsafe { ffi::PyClass_IsSubclass(self.as_ptr(), base.as_ptr()) != 0 }
}
pub fn create_instance<T>(&self, py: Python, args: T, kw: Option<&PyDict>) -> PyResult<PyInstance>
where T: ToPyObject<ObjectType=PyTuple>
{
args.with_borrowed_ptr(py, |args| unsafe {
err::result_cast_from_owned_ptr(py,
ffi::PyInstance_New(self.as_ptr(), args, kw.as_ptr()))
})
}
pub fn create_instance_raw(&self, py: Python, dict: &PyDict) -> PyResult<PyInstance> {
unsafe {
err::result_cast_from_owned_ptr(py,
ffi::PyInstance_NewRaw(self.as_ptr(), dict.as_object().as_ptr()))
}
}
}