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 
test_bind_virtual.ImplClass
Definition: test_bind_virtual.py:4
test_bind_virtual.ImplData
Definition: test_bind_virtual.py:28
print
void print(const Eigen::SparseMatrix< Scalar, Options > &mat)
Definition: sparse_matrix.cpp:50
test_bind_virtual.test_iden_fns
def test_iden_fns()
Definition: test_bind_virtual.py:56
test_bind_virtual.ImplClass.createData
def createData(self)
Definition: test_bind_virtual.py:9
test_bind_virtual.ImplClass.val
val
Definition: test_bind_virtual.py:6
test_bind_virtual.ImplData.value
value
Definition: test_bind_virtual.py:32
test_bind_virtual.ImplClass.doSomethingPtr
def doSomethingPtr(self, data)
Definition: test_bind_virtual.py:13
test_bind_virtual.ImplClass.doSomethingRef
def doSomethingRef(self, data)
Definition: test_bind_virtual.py:20
test_bind_virtual.test_instantiate_child
def test_instantiate_child()
Definition: test_bind_virtual.py:35
test_bind_virtual.test_call_do_something_ref
def test_call_do_something_ref()
Definition: test_bind_virtual.py:48
test_bind_virtual.ImplClass.__init__
def __init__(self)
Definition: test_bind_virtual.py:5
test_bind_virtual.ImplData.__init__
def __init__(self, c)
Definition: test_bind_virtual.py:29
test_bind_virtual.test_call_do_something_ptr
def test_call_do_something_ptr()
Definition: test_bind_virtual.py:41


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45