cppyabm
1.0.17
An agent-based library to integrate C++ and Python
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
(
Cell
);
23
EXPOSE_PATCH_CONTAINER
(
Tissue
);
24
25
//! Binding function.
26
/*!
27
The name provided as module, i.e. myBinds, must be the same name given in CmakeLists.txt as argument to
28
pybind11_add_module.
29
*/
30
PYBIND11_MODULE
(myBinds,
m
) {
31
32
using
tramEnv =
bind_tools::tramEnv<Domain,Cell,Tissue>
;
33
using
tramPatch =
bind_tools::tramPatch<Domain,Cell,Tissue>
;
34
//
35
auto
bind_obj =
bind_tools::Bind<Domain,Cell,Tissue,tramEnv,tramCell,tramPatch>
(
m
,
"Domain"
,
"Cell"
,
"Tissue"
);
36
auto
env_obj = bind_obj.get_env();
37
env_obj.def(py::init<bool>());
38
env_obj.def(
"setup"
,&
Domain::setup
);
39
env_obj.def(
"episode"
,&
Domain::episode
);
40
auto
agent_obj = bind_obj.get_agent();
41
agent_obj.def_readwrite(
"cycle_t"
,&
Cell::cycle_t
);
42
}
43
44
Domain::setup
void setup()
Definition:
cpp_example.h:70
setup
Definition:
setup.py:1
Tissue
Definition:
cpp_example.h:36
tramCell::setup
void setup() override
Definition:
binds.cpp:14
bind_tools::Bind
Definition:
bind_tools.h:261
Cell::cycle_t
int cycle_t
Definition:
cpp_example.h:57
EXPOSE_AGENT_CONTAINER
EXPOSE_AGENT_CONTAINER(expAgent)
Domain::episode
void episode()
Definition:
cpp_example.h:130
PYBIND11_MODULE
PYBIND11_MODULE(binds, m)
Definition:
binds.cpp:23
EXPOSE_PATCH_CONTAINER
EXPOSE_PATCH_CONTAINER(expPatch)
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
bind_tools::tramPatch
Template trampoline for Patch-based classes.
Definition:
bind_tools.h:82
bind_tools::tramEnv
Template trampoline for Env-based classes.
Definition:
bind_tools.h:23
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
Generated by
1.8.19