Exemple #1
0
 def _pointize(self, obj):
     """Given object checks whether it is C++ type (perhaps better to
     refactor it) and if not make a Points out of it. Use case -- turning
     numpy array into points.
     """
     try:
         # check if we are in modern PyROOT
         cppyy.typeid(obj)
     except KeyError:
         # not C++ object, trying convert to Points
         obj = C.Points(obj)
     except AttributeError:
         # we are in legacy PyROOT
         if not isinstance(type(obj), ROOT.PyRootType):
             obj = C.Points(obj)
     return obj
Exemple #2
0
    def test02_any_usage(self):
        """boost::any assignment and casting"""

        if self.disable:
            import warnings
            warnings.warn("no boost/any.hpp found, skipping test02_any_usage")
            return

        import cppyy
        assert cppyy.gbl.boost

        from cppyy.gbl import std, boost

        val = boost.any()
        # test both by-ref and by rvalue
        v = std.vector[int]()
        val.__assign__(v)
        val.__assign__(std.move(std.vector[int](range(100))))
        assert val.type() == cppyy.typeid(std.vector[int])

        extract = boost.any_cast[std.vector[int]](val)
        assert type(extract) is std.vector[int]
        assert len(extract) == 100
        extract += range(100)
        assert len(extract) == 200

        val.__assign__(std.move(extract))  # move forced
        #assert len(extract) == 0      # not guaranteed by the standard

        # TODO: we hit boost::any_cast<int>(boost::any* operand) instead
        # of the reference version which raises
        boost.any_cast.__useffi__ = False
        try:
            # raises(Exception, boost.any_cast[int], val)
            assert not boost.any_cast[int](val)
        except Exception:
            # getting here is good, too ...
            pass

        extract = boost.any_cast[std.vector[int]](val)
        assert len(extract) == 200
Exemple #3
0
    def test02_any_usage(self):
        """boost::any assignment and casting"""

        import cppyy
        assert cppyy.gbl.boost

        from cppyy.gbl import std, boost

        val = boost.any()
        val.__assign__(std.vector[int]())
        assert val.type() == cppyy.typeid(std.vector[int])

        extract = boost.any_cast[std.vector[int]](std.move(val))
        assert type(extract) is std.vector[int]
        extract += range(100)

        val.__assign__(std.move(extract))
        assert len(extract) == 0

        raises(Exception, boost.any_cast[int], std.move(val))

        extract = boost.any_cast[std.vector[int]](std.move(val))
        assert len(extract) == 100
Exemple #4
0
    def test02_any_usage(self):
        """boost::any assignment and casting"""

        import cppyy
        assert cppyy.gbl.boost

        from cppyy.gbl import std, boost

        val = boost.any()
        # test both by-ref and by rvalue
        v = std.vector[int]()
        val.__assign__(v)
        val.__assign__(std.move(std.vector[int](range(100))))
        assert val.type() == cppyy.typeid(std.vector[int])

        extract = boost.any_cast[std.vector[int]](val)
        assert type(extract) is std.vector[int]
        assert len(extract) == 100
        extract += range(100)
        assert len(extract) == 200

        val.__assign__(std.move(extract))   # move forced
        #assert len(extract) == 0      # not guaranteed by the standard

        # TODO: we hit boost::any_cast<int>(boost::any* operand) instead
        # of the reference version which raises
        boost.any_cast.__useffi__ = False
        try:
          # raises(Exception, boost.any_cast[int], val)
            assert not boost.any_cast[int](val)
        except Exception:
          # getting here is good, too ...
            pass

        extract = boost.any_cast[std.vector[int]](val)
        assert len(extract) == 200