1 #ifndef AFW_TABLE_PYBIND11_SORTEDCATALOG_H_INCLUDED
2 #define AFW_TABLE_PYBIND11_SORTEDCATALOG_H_INCLUDED
26 #include "pybind11/pybind11.h"
38 template <
typename Record>
56 template <
typename Record>
60 using namespace pybind11::literals;
63 using Table =
typename Record::Table;
65 auto clsBase = declareCatalog<Record>(wrappers,
name,
true);
69 fullName =
"_" +
name +
"SortedCatalogBase";
71 fullName =
name +
"Catalog";
78 [clsBase](
auto &mod,
auto &
cls) {
80 cls.def(pybind11::init<Schema const &>());
81 cls.def(pybind11::init<std::shared_ptr<Table> const &>(),
82 "table"_a = std::shared_ptr<Table>());
83 cls.def(pybind11::init<Catalog const &>());
86 cls.def_static(
"readFits", (Catalog(*)(std::string const &, int, int)) & Catalog::readFits,
87 "filename"_a,
"hdu"_a = fits::DEFAULT_HDU,
"flags"_a = 0);
88 cls.def_static(
"readFits", (Catalog(*)(fits::MemFileManager &, int, int)) & Catalog::readFits,
89 "manager"_a,
"hdu"_a = fits::DEFAULT_HDU,
"flags"_a = 0);
93 (Catalog(Catalog::*)(ndarray::Array<bool const, 1> const &) const) & Catalog::subset);
95 (Catalog(Catalog::*)(std::ptrdiff_t, std::ptrdiff_t, std::ptrdiff_t) const) &
103 [clsBase](py::object const &self, py::object key) -> py::object {
104 if (key.is(py::none())) {
105 key = self.attr(
"table").attr(
"getIdKey")();
107 return clsBase.attr(
"isSorted")(self, key);
109 "key"_a = py::none());
111 [clsBase](py::object
const &
self, py::object
key) -> py::object {
112 if (
key.is(py::none())) {
113 key = self.attr(
"table").attr(
"getIdKey")();
115 return clsBase.attr(
"sort")(
self,
key);
117 "key"_a = py::none());
119 [clsBase](py::object
const &
self, py::object
const &value,
120 py::object
key) -> py::object {
121 if (
key.is(py::none())) {
122 key =
self.attr(
"table").attr(
"getIdKey")();
124 return clsBase.attr(
"find")(
self, value,
key);
126 "value"_a,
"key"_a = py::none());
136 #endif // !AFW_TABLE_PYBIND11_CATALOG_H_INCLUDED