test_bind_virtual.py
Go to the documentation of this file.
1 import bind_virtual_factory as bvf
2 
3 
4 class ImplClass(bvf.MyVirtualClass):
5  def __init__(self):
6  self.val = 42
7  bvf.MyVirtualClass.__init__(self)
8 
9  def createData(self):
10  return ImplData(self)
11 
12  # override MyVirtualClass::doSomethingPtr(shared_ptr data)
13  def doSomethingPtr(self, data):
14  print("Hello from doSomething!")
15  assert isinstance(data, ImplData)
16  print("Data value:", data.value)
17  data.value += 1
18 
19  # override MyVirtualClass::doSomethingPtr(data&)
20  def doSomethingRef(self, data):
21  print("Hello from doSomethingRef!")
22  print(type(data))
23  assert isinstance(data, ImplData)
24  print("Data value:", data.value)
25  data.value += 1
26 
27 
28 class ImplData(bvf.MyVirtualData):
29  def __init__(self, c):
30  # parent virtual class requires arg
31  bvf.MyVirtualData.__init__(self, c)
32  self.value = c.val
33 
34 
36  obj = ImplClass()
37  data = obj.createData()
38  print(data)
39 
40 
42  obj = ImplClass()
43  print("Calling doSomething (by ptr)")
44  d1 = bvf.callDoSomethingPtr(obj)
45  print("Output data.value:", d1.value)
46 
47 
49  obj = ImplClass()
50  print("Ref variant:")
51  d2 = bvf.callDoSomethingRef(obj)
52  print(d2.value)
53  print("-----")
54 
55 
57  obj = ImplClass()
58  d = obj.createData()
59  print(d, type(d))
60 
61  # take and return const T&
62  d1 = bvf.iden_ref(d)
63  print(d1, type(d1))
64  assert isinstance(d1, ImplData)
65 
66  # take a shared_ptr, return const T&
67  d2 = bvf.iden_shared(d)
68  assert isinstance(d2, ImplData)
69  print(d2, type(d2))
70 
71  print("copy shared ptr -> py -> cpp")
72  d3 = bvf.copy_shared(d)
73  assert isinstance(d3, ImplData)
74  print(d3, type(d3))
75 
76 
void print(const Tensor &tensor)
Definition: tensor.cpp:35


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 2 2023 02:10:26