def __init__(self, space, w_vector): W_AbstractSeqIterObject.__init__(self, w_vector) # TODO: this should live in rpythonize.py or something so that the # imports can move to the top w/o getting circles from pypy.module.cppyy import interp_cppyy assert isinstance(w_vector, interp_cppyy.W_CPPInstance) vector = space.interp_w(interp_cppyy.W_CPPInstance, w_vector) self.overload = vector.cppclass.get_overload("__getitem__") from pypy.module.cppyy import capi v_type = capi.c_stdvector_valuetype(space, vector.cppclass.name) v_size = capi.c_stdvector_valuesize(space, vector.cppclass.name) if not v_type or not v_size: raise NotImplementedError # fallback on getitem w_arr = vector.cppclass.get_overload("data").call(w_vector, []) arr = space.interp_w(W_ArrayInstance, w_arr, can_be_None=True) if not arr: raise OperationError(space.w_StopIteration, space.w_None) self.data = rffi.cast(rffi.VOIDP, space.uint_w(arr.getbuffer(space))) from pypy.module.cppyy import converter self.converter = converter.get_converter(space, v_type, '') self.len = space.uint_w(vector.cppclass.get_overload("size").call(w_vector, [])) self.stride = v_size
def __init__(self, space, w_vector): W_AbstractSeqIterObject.__init__(self, w_vector) # TODO: this should live in rpythonize.py or something so that the # imports can move to the top w/o getting circles from pypy.module.cppyy import interp_cppyy assert isinstance(w_vector, interp_cppyy.W_CPPInstance) vector = space.interp_w(interp_cppyy.W_CPPInstance, w_vector) self.overload = vector.cppclass.get_overload("__getitem__") from pypy.module.cppyy import capi v_type = capi.c_stdvector_valuetype(space, vector.cppclass.name) v_size = capi.c_stdvector_valuesize(space, vector.cppclass.name) if not v_type or not v_size: raise NotImplementedError # fallback on getitem w_arr = vector.cppclass.get_overload("data").call(w_vector, []) arr = space.interp_w(W_ArrayInstance, w_arr, can_be_None=True) if not arr: raise OperationError(space.w_StopIteration, space.w_None) self.data = rffi.cast(rffi.VOIDP, space.uint_w(arr.getbuffer(space))) from pypy.module.cppyy import converter self.converter = converter.get_converter(space, v_type, '') self.len = space.uint_w( vector.cppclass.get_overload("size").call(w_vector, [])) self.stride = v_size
def pythonize(space, name, w_pycppclass): if name == "string": space.setattr(w_pycppclass, space.wrap("c_str"), _pythonizations["stdstring_c_str"]) _method_alias(space, w_pycppclass, "_cppyy_as_builtin", "c_str") _method_alias(space, w_pycppclass, "__str__", "c_str") if "vector" in name[:11]: # len('std::vector') == 11 from pypy.module.cppyy import capi v_type = capi.c_stdvector_valuetype(space, name) if v_type: space.setattr(w_pycppclass, space.wrap("value_type"), space.wrap(v_type)) v_size = capi.c_stdvector_valuesize(space, name) if v_size: space.setattr(w_pycppclass, space.wrap("value_size"), space.wrap(v_size)) space.setattr(w_pycppclass, space.wrap("__iter__"), _pythonizations["stdvector_iter"])