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" 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);
47 [](Class &
self, Key
const&
key,
std::function<Value(Key
const& key)> func) {
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
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
void declareCache(py::module &mod, std::string const &name)
A base class for image defects.
Cache of most recently used values.