I am facing some problems with calling the class from an address given by the pointer. I need to call c++ in python. Here is my cpp code
extern "C" {
Pancreas* SeedAndGrowToStartVolume(double p0, double psc, int dmax, int gage, int page, double startVolume)
{
Params* parameters = new Params(p0, psc, dmax, gage, page);
vector<Cell*> empty;
Pancreas* pancreas = new Pancreas(empty, parameters);
pancreas->CreateInitialTumour();
double volume = 0;
int days = 0;
while (volume < startVolume && days < 200)
volume = pancreas->SimulateOneDay(days++);
fprintf(stdout,"%x\n",days);
fprintf(stdout,"%x, %u,%d\n",pancreas,pancreas,pancreas);
return pancreas;
}
}
when I use python to call SeedAndGrowToStartVolume, it returns an integer, which is the address of pancreas. Here is the python code
from ctypes import *
import os.path
file_path = os.path.abspath('Model.so')
testdll = cdll.LoadLibrary(file_path)
testdll.SeedAndGrowToStartVolume.argtypes = [c_double, c_double, c_int, c_int, c_int, c_double]
testdll.SeedAndGrowToStartVolume.restypes = py_object
## pf is an address
pf = testdll.SeedAndGrowToStartVolume(0.5,1e-5,50,150,2,100)
I want to call a function in pancreas class. But I only have an integer. Here is .h file that contains pancreas class. The function I want to call is double SimulateOneDay(int day)
extern "C" {
class Pancreas
{
public:
double SimulateOneDay(int day)
{
DetermineNeighbours();
for (int hour = 1; hour <= Params::tinterval; hour++)
{
//parameters->created = parameters->opportunities = 0;
SimulateOneHour();
//printf("day %d, hour %d, %d of %d created\n", day, hour, parameters->created, parameters->opportunities);
}
return TumourVolume();
}
void UpdateParameters(Params* parameters)
{
this->parameters = parameters;
}
};
}