1 #ifndef LSST_UTILS_PYTHON_CACHE_H
2 #define LSST_UTILS_PYTHON_CACHE_H
26 #include "pybind11/pybind11.h"
27 #include "pybind11/stl.h"
28 #include "pybind11/functional.h"
33 using namespace pybind11::literals;
39 template <
typename Key,
typename Value,
typename KeyHash=boost::hash<Key>,
40 typename KeyPred=std::equal_to<Key>>
43 py::class_<Class>
cls(mod,
name.c_str());
45 cls.def(py::init<std::size_t>(),
"maxElements"_a=0);
48 py::gil_scoped_release release;
49 return self(
key, func);
50 },
"key"_a,
"func"_a);
51 cls.def(
"__getitem__", &Class::operator[]);
52 cls.def(
"add", &Class::add,
"key"_a,
"value"_a);
53 cls.def(
"size", &Class::size);
54 cls.def(
"__len__", &Class::size);
58 cls.def(
"capacity", &Class::capacity);
59 cls.def(
"reserve", &Class::reserve);
60 cls.def(
"flush", &Class::flush);
65 #endif // ifndef LSST_UTILS_PYTHON_CACHE_H