cppyabm
1.0.17
An agent-based library to integrate C++ and Python
examples
Cpp
build
_deps
cppyabm-src
examples
Cppy
binds.cpp
Go to the documentation of this file.
1
2
#include <iostream>
3
#include "../Cpp/cpp_example.h"
4
#include <
pybind11/stl.h
>
5
#include <
pybind11/stl_bind.h
>
6
#include <
pybind11/complex.h
>
7
#include <
pybind11/functional.h
>
8
#include "cppyabm/bind_tools.h"
9
10
//! Defining a trampoline to allow the extension of the functionality of Cell::step
11
using
tramAgent
=
bind_tools::tramAgent<Domain,Cell,Tissue>
;
12
struct
tramCell
:
public
tramAgent
{
13
using
tramAgent::tramAgent
;
// using constructor of the parent class
14
void
setup
()
override
{
15
PYBIND11_OVERLOAD
(
16
void
,
17
Cell
,
18
setup
19
);
20
}
21
};
22
/** Expose agent container**/
23
EXPOSE_AGENT_CONTAINER
(
Cell
);
24
//! Binding function.
25
/*!
26
The name provided as module, i.e. myBinds, must be the same name given in CmakeLists.txt as argument to
27
pybind11_add_module.
28
*/
29
PYBIND11_MODULE
(myBinds,
m
) {
30
// expose defaults
31
bind_tools::expose_defaults<Domain,Cell,Tissue>(
m
);
32
// expose env and add new members
33
auto
env_obj = bind_tools::expose_env<Domain,Cell,Tissue,bind_tools::tramEnv<Domain,Cell,Tissue>>(
m
,
"Domain"
);
34
env_obj.def(py::init<bool>());
35
env_obj.def(
"setup"
,&
Domain::setup
);
36
env_obj.def(
"episode"
,&
Domain::episode
);
37
// expose agent and add new member
38
auto
agent_obj = bind_tools::expose_agent<Domain,Cell,Tissue,tramCell>(
m
,
"Cell"
)
39
.def_readwrite(
"cycle_t"
,&
Cell::cycle_t
);
40
}
41
Domain::setup
void setup()
Definition:
cpp_example.h:70
setup
Definition:
setup.py:1
tramCell::setup
void setup() override
Definition:
binds.cpp:14
Cell::cycle_t
int cycle_t
Definition:
cpp_example.h:57
EXPOSE_AGENT_CONTAINER
EXPOSE_AGENT_CONTAINER(expAgent)
stl.h
Domain::episode
void episode()
Definition:
cpp_example.h:130
PYBIND11_MODULE
PYBIND11_MODULE(binds, m)
Definition:
binds.cpp:23
complex.h
bind_tools::tramAgent
Template trampoline for Agent-based classes.
Definition:
bind_tools.h:61
Cell
Definition:
cpp_example.h:46
PYBIND11_OVERLOAD
#define PYBIND11_OVERLOAD(ret_type, cname, fn,...)
Definition:
pybind11.h:2443
tramCell
Definition:
binds.cpp:12
functional.h
tramAgent
bind_tools::tramAgent< Domain, Cell, Tissue > tramAgent
Defining a trampoline to allow the extension of the functionality of Cell::step.
Definition:
binds.cpp:11
test_async.m
m
Definition:
test_async.py:5
stl_bind.h
Generated by
1.8.19