![]() |
BoB robotics
The Brains on Board robotics library
|
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') More...
#include <common.h>
Public Member Functions | |
| void | allocate_layout () |
| Initializes all of the above type/values/holders data (but not the instance values themselves) | |
| void | deallocate_layout () |
| Destroys/deallocates all of the above. | |
| value_and_holder | get_value_and_holder (const type_info *find_type=nullptr, bool throw_if_missing=true) |
Public Attributes | |
| union { | |
| void * simple_value_holder [1+instance_simple_holder_in_ptrs()] | |
| nonsimple_values_and_holders nonsimple | |
| }; | |
| Storage for pointers and holder; see simple_layout, below, for a description. | |
| PyObject * | weakrefs |
| Weak references. | |
| bool | owned: 1 |
| If true, the pointer is owned which means we're free to manage it with a holder. | |
| bool | simple_layout: 1 |
| bool | simple_holder_constructed: 1 |
| For simple layout, tracks whether the holder has been constructed. | |
| bool | simple_instance_registered: 1 |
For simple layout, tracks whether the instance is registered in registered_instances | |
| bool | has_patients: 1 |
| If true, get_internals().patients has an entry for this object. | |
Static Public Attributes | |
| static constexpr uint8_t | status_holder_constructed = 1 |
| Bit values for the non-simple status flags. | |
| static constexpr uint8_t | status_instance_registered = 2 |
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
| value_and_holder pybind11::detail::instance::get_value_and_holder | ( | const type_info * | find_type = nullptr, |
| bool | throw_if_missing = true |
||
| ) |
Returns the value_and_holder wrapper for the given type (or the first, if find_type omitted). Returns a default-constructed (with .inst = nullptr) object on failure if throw_if_missing is false.
| bool pybind11::detail::instance::simple_layout |
An instance has two possible value/holder layouts.
Simple layout (when this flag is true), means the simple_value_holder is set with a pointer and the holder object governing that pointer, i.e. [val1*][holder]. This layout is applied whenever there is no python-side multiple inheritance of bound C++ types and the type's holder will fit in the default space (which is large enough to hold either a std::unique_ptr or std::shared_ptr).
Non-simple layout applies when using custom holders that require more space than shared_ptr (which is typically the size of two pointers), or when multiple inheritance is used on the python side. Non-simple layout allocates the required amount of memory to have multiple bound C++ classes as parents. Under this layout, nonsimple.values_and_holders is set to a pointer to allocated space of the required space to hold a sequence of value pointers and holders followed status, a set of bit flags (1 byte each), i.e. [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple of sizeof(void *). nonsimple.status is, for convenience, a pointer to the beginning of the [bb...] block (but not independently allocated).
Status bits indicate whether the associated holder is constructed (& status_holder_constructed) and whether the value pointer is registered (& status_instance_registered) in registered_instances.