Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r70988:5ebbaf3f1099
Date: 2014-04-25 13:56 -0700
http://bitbucket.org/pypy/pypy/changeset/5ebbaf3f1099/
Log: expose cppyy.Template for end-user use
diff --git a/pypy/module/cppyy/__init__.py b/pypy/module/cppyy/__init__.py
--- a/pypy/module/cppyy/__init__.py
+++ b/pypy/module/cppyy/__init__.py
@@ -25,6 +25,7 @@
'_init_pythonify' : 'pythonify._init_pythonify',
'load_reflection_info' : 'pythonify.load_reflection_info',
'add_pythonization' : 'pythonify.add_pythonization',
+ 'Template' : 'pythonify.CppyyTemplateType',
}
def __init__(self, space, *args):
diff --git a/pypy/module/cppyy/pythonify.py b/pypy/module/cppyy/pythonify.py
--- a/pypy/module/cppyy/pythonify.py
+++ b/pypy/module/cppyy/pythonify.py
@@ -25,9 +25,12 @@
# class CppyyClass defined in _init_pythonify()
class CppyyTemplateType(object):
- def __init__(self, scope, name):
- self._scope = scope
+ def __init__(self, name, scope=None):
self._name = name
+ if scope is None:
+ self._scope = gbl
+ else:
+ self._scope = scope
def _arg_to_str(self, arg):
if arg == str:
@@ -206,7 +209,7 @@
return pycppclass
def make_cpptemplatetype(scope, template_name):
- return CppyyTemplateType(scope, template_name)
+ return CppyyTemplateType(template_name, scope)
def get_pycppitem(scope, name):
diff --git a/pypy/module/cppyy/test/test_stltypes.py
b/pypy/module/cppyy/test/test_stltypes.py
--- a/pypy/module/cppyy/test/test_stltypes.py
+++ b/pypy/module/cppyy/test/test_stltypes.py
@@ -477,3 +477,29 @@
assert b1 == e2
assert b1 != b2
assert b1 == e2
+
+
+class AppTestTEMPLATE_UI:
+ spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
+
+ def setup_class(cls):
+ cls.w_test_dct = cls.space.wrap(test_dct)
+ cls.w_stlstring = cls.space.appexec([], """():
+ import cppyy, sys
+ return cppyy.load_reflection_info(%r)""" % (test_dct, ))
+
+ def test01_explicit_templates(self):
+ """Explicit use of Template class"""
+
+ import cppyy
+
+ vector = cppyy.Template('vector', cppyy.gbl.std)
+ assert vector[int] == vector(int)
+
+ v = vector[int]()
+
+ N = 10
+ v += range(N)
+ assert len(v) == N
+ for i in range(N):
+ assert v[i] == i
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit