Commits

wlav  committed 5ebbaf3

expose cppyy.Template for end-user use

  • Participants
  • Parent commits 154db83
  • Branches reflex-support

Comments (0)

Files changed (3)

File pypy/module/cppyy/__init__.py

         '_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):

File pypy/module/cppyy/pythonify.py

 # 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:
     return pycppclass
 
 def make_cpptemplatetype(scope, template_name):
-    return CppyyTemplateType(scope, template_name)
+    return CppyyTemplateType(template_name, scope)
 
 
 def get_pycppitem(scope, name):

File pypy/module/cppyy/test/test_stltypes.py

         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