File indexing completed on 2025-01-30 10:17:30
0001
0002
0003
0004
0005 #pragma once
0006
0007 #include "common.h"
0008
0009 #include <cstddef>
0010 #include <typeinfo>
0011
0012 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
0013 PYBIND11_NAMESPACE_BEGIN(detail)
0014
0015 struct value_and_holder {
0016 instance *inst = nullptr;
0017 size_t index = 0u;
0018 const detail::type_info *type = nullptr;
0019 void **vh = nullptr;
0020
0021
0022 value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
0023 : inst{i}, index{index}, type{type},
0024 vh{inst->simple_layout ? inst->simple_value_holder
0025 : &inst->nonsimple.values_and_holders[vpos]} {}
0026
0027
0028 value_and_holder() = default;
0029
0030
0031 explicit value_and_holder(size_t index) : index{index} {}
0032
0033 template <typename V = void>
0034 V *&value_ptr() const {
0035 return reinterpret_cast<V *&>(vh[0]);
0036 }
0037
0038 explicit operator bool() const { return value_ptr() != nullptr; }
0039
0040 template <typename H>
0041 H &holder() const {
0042 return reinterpret_cast<H &>(vh[1]);
0043 }
0044 bool holder_constructed() const {
0045 return inst->simple_layout
0046 ? inst->simple_holder_constructed
0047 : (inst->nonsimple.status[index] & instance::status_holder_constructed) != 0u;
0048 }
0049
0050 void set_holder_constructed(bool v = true) {
0051 if (inst->simple_layout) {
0052 inst->simple_holder_constructed = v;
0053 } else if (v) {
0054 inst->nonsimple.status[index] |= instance::status_holder_constructed;
0055 } else {
0056 inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
0057 }
0058 }
0059 bool instance_registered() const {
0060 return inst->simple_layout
0061 ? inst->simple_instance_registered
0062 : ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
0063 }
0064
0065 void set_instance_registered(bool v = true) {
0066 if (inst->simple_layout) {
0067 inst->simple_instance_registered = v;
0068 } else if (v) {
0069 inst->nonsimple.status[index] |= instance::status_instance_registered;
0070 } else {
0071 inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_instance_registered;
0072 }
0073 }
0074 };
0075
0076 PYBIND11_NAMESPACE_END(detail)
0077 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)