value_and_holder.h
Go to the documentation of this file.
1 // Copyright (c) 2016-2024 The Pybind Development Team.
2 // All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 
5 #pragma once
6 
7 #include "common.h"
8 
9 #include <cstddef>
10 #include <typeinfo>
11 
14 
16  instance *inst = nullptr;
17  size_t index = 0u;
18  const detail::type_info *type = nullptr;
19  void **vh = nullptr;
20 
21  // Main constructor for a found value/holder:
22  value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
23  : inst{i}, index{index}, type{type},
24  vh{inst->simple_layout ? inst->simple_value_holder
25  : &inst->nonsimple.values_and_holders[vpos]} {}
26 
27  // Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
28  value_and_holder() = default;
29 
30  // Used for past-the-end iterator
31  explicit value_and_holder(size_t index) : index{index} {}
32 
33  template <typename V = void>
34  V *&value_ptr() const {
35  return reinterpret_cast<V *&>(vh[0]);
36  }
37  // True if this `value_and_holder` has a non-null value pointer
38  explicit operator bool() const { return value_ptr() != nullptr; }
39 
40  template <typename H>
41  H &holder() const {
42  return reinterpret_cast<H &>(vh[1]);
43  }
44  bool holder_constructed() const {
45  return inst->simple_layout
46  ? inst->simple_holder_constructed
47  : (inst->nonsimple.status[index] & instance::status_holder_constructed) != 0u;
48  }
49  // NOLINTNEXTLINE(readability-make-member-function-const)
50  void set_holder_constructed(bool v = true) {
51  if (inst->simple_layout) {
52  inst->simple_holder_constructed = v;
53  } else if (v) {
54  inst->nonsimple.status[index] |= instance::status_holder_constructed;
55  } else {
56  inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
57  }
58  }
59  bool instance_registered() const {
60  return inst->simple_layout
61  ? inst->simple_instance_registered
62  : ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
63  }
64  // NOLINTNEXTLINE(readability-make-member-function-const)
65  void set_instance_registered(bool v = true) {
66  if (inst->simple_layout) {
67  inst->simple_instance_registered = v;
68  } else if (v) {
69  inst->nonsimple.status[index] |= instance::status_instance_registered;
70  } else {
71  inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_instance_registered;
72  }
73  }
74 };
75 
H
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Definition: gnuplot_common_settings.hh:74
value_and_holder::value_and_holder
value_and_holder(size_t index)
Definition: value_and_holder.h:31
instance::status_instance_registered
static constexpr uint8_t status_instance_registered
Definition: wrap/pybind11/include/pybind11/detail/common.h:659
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
type
Definition: pytypes.h:1527
value_and_holder
Definition: value_and_holder.h:15
detail
Definition: testSerializationNonlinear.cpp:69
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
uint8_t
unsigned char uint8_t
Definition: ms_stdint.h:83
instance
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition: wrap/pybind11/include/pybind11/detail/common.h:602
value_and_holder::set_instance_registered
void set_instance_registered(bool v=true)
Definition: value_and_holder.h:65
value_and_holder::set_holder_constructed
void set_holder_constructed(bool v=true)
Definition: value_and_holder.h:50
value_and_holder::value_and_holder
value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
Definition: value_and_holder.h:22
PYBIND11_NAMESPACE
Definition: test_custom_type_casters.cpp:24
common.h
instance::status_holder_constructed
static constexpr uint8_t status_holder_constructed
Bit values for the non-simple status flags.
Definition: wrap/pybind11/include/pybind11/detail/common.h:658
value_and_holder::value_ptr
V *& value_ptr() const
Definition: value_and_holder.h:34
value_and_holder::instance_registered
bool instance_registered() const
Definition: value_and_holder.h:59
value_and_holder::holder
H & holder() const
Definition: value_and_holder.h:41
value_and_holder::holder_constructed
bool holder_constructed() const
Definition: value_and_holder.h:44
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
V
MatrixXcd V
Definition: EigenSolver_EigenSolver_MatrixType.cpp:15
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.inst
inst
Definition: pybind_wrapper_test_script.py:49


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:09:00