2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-26 18:52:26 +00:00

Mapping of std::complex<T> <-> Python complex.

[SVN r9305]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2001-02-21 08:01:54 +00:00
parent f1d4a38121
commit 3eb98f54a1
4 changed files with 77 additions and 3 deletions

42
example/cmplx.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include <iostream>
#include <complex>
namespace { // Avoid cluttering the global namespace.
std::complex<double> dpolar(double rho, double theta) {
return std::polar(rho, theta);
}
double dreal(const std::complex<double>& c) { return c.real(); }
double dimag(std::complex<double> c) { return c.imag(); }
std::complex<float> fpolar(float rho, float theta) {
return std::polar(rho, theta);
}
double freal(const std::complex<float>& c) { return c.real(); }
double fimag(std::complex<float> c) { return c.imag(); }
}
#include <boost/python/class_builder.hpp>
namespace python = boost::python;
extern "C"
DL_EXPORT(void)
initcmplx()
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("cmplx");
this_module.def(dpolar, "dpolar");
this_module.def(dreal, "dreal");
this_module.def(dimag, "dimag");
this_module.def(fpolar, "fpolar");
this_module.def(freal, "freal");
this_module.def(fimag, "fimag");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}