xo-pyunit: initial commit

This commit is contained in:
Roland Conybeare 2024-05-01 07:12:29 -05:00
commit 7c51ccb7f3
6 changed files with 136 additions and 0 deletions

View file

@ -0,0 +1,9 @@
# xo_pyunit/src/pyunit/CMakeLists.txt
set(SELF_LIB pyunit)
set(SELF_SRCS pyunit.cpp)
# ----------------------------------------------------------------
xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS})
xo_pybind11_dependency(${SELF_LIB} xo_unit)

27
src/pyunit/pyunit.cpp Normal file
View file

@ -0,0 +1,27 @@
/* @file pyunit.cpp */
// note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory
#include "pyunit.hpp"
#include "xo/unit/xquantity.hpp"
#include "xo/pyutil/pyutil.hpp"
//#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
//#include <pybind11/chrono.h>
//#include <pybind11/operators.h>
namespace xo {
namespace py = pybind11;
namespace qty {
PYBIND11_MODULE(PYUNIT_MODULE_NAME(), m) {
py::class_<Quantity>(m, "Quantity")
.def("__repr__",
[](Quantity & x)
{
return tostr(x);
})
py::arg("qty"));
}
}
} /*namespace xo*/

25
src/pyunit/pyunit.hpp.in Normal file
View file

@ -0,0 +1,25 @@
/* @file pyunit.hpp
*
* automatically generated from src/xo_pyunit/pyunit.hpp.in
* see src/xo_pyunit/CMakeLists.txt
*/
/* python requires module name = library name
* example:
* PYBIND11_MODULE(PYUNIT_MODULE_NAME(), m) { ... }
*/
#define PYUNIT_MODULE_NAME() @SELF_LIB@
/* example:
* py::module_::import(PYUNIT_MODULE_NAME_STR)
*/
#define PYUNIT_MODULE_NAME_STR "@SELF_LIB@"
/* example:
* PYUNIT_IMPORT_MODULE()
* replaces
* py::module_::import("pyunit")
*/
#define PYUNIT_IMPORT_MODULE() py::module_::import("@SELF_LIB@")
/* end pyunit.hpp */