MCPcopy Create free account
hub / github.com/pybind/pybind11 / enum_

Method enum_

include/pybind11/pybind11.h:3183–3211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3181
3182 template <typename... Extra>
3183 enum_(const handle &scope, const char *name, const Extra &...extra)
3184 : class_<Type>(scope, name, extra...), m_base(*this, scope) {
3185 {
3186 if (detail::global_internals_native_enum_type_map_contains(
3187 std::type_index(typeid(Type)))) {
3188 pybind11_fail("pybind11::enum_ \"" + std::string(name)
3189 + "\" is already registered as a pybind11::native_enum!");
3190 }
3191 }
3192
3193 constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
3194 constexpr bool is_convertible = std::is_convertible<Type, Underlying>::value;
3195 m_base.init(is_arithmetic, is_convertible);
3196
3197 def(init([](Scalar i) { return static_cast<Type>(i); }), arg("value"));
3198 def_property_readonly("value", [](Type value) { return (Scalar) value; }, pos_only());
3199 def("__int__", [](Type value) { return (Scalar) value; }, pos_only());
3200 def("__index__", [](Type value) { return (Scalar) value; }, pos_only());
3201 attr("__setstate__") = cpp_function(
3202 [](detail::value_and_holder &v_h, Scalar arg) {
3203 detail::initimpl::setstate<Base>(
3204 v_h, static_cast<Type>(arg), Py_TYPE(v_h.inst) != v_h.type->type);
3205 },
3206 detail::is_new_style_constructor(),
3207 pybind11::name("__setstate__"),
3208 is_method(*this),
3209 arg("state"),
3210 pos_only());
3211 }
3212
3213 /// Export enumeration entries into the parent scope
3214 enum_ &export_values() {

Callers

nothing calls this directly

Calls 9

initFunction · 0.85
pos_onlyClass · 0.85
cpp_functionClass · 0.85
is_methodClass · 0.85
argClass · 0.70
nameClass · 0.70
initMethod · 0.45

Tested by

no test coverage detected