Library of Assembled Shared Sources
|
Definition of an enum.IntFlag
-derived enum type in Python.
More...
#include <enum_definition.h>
Public Member Functions | |
IntFlagDefinition (const char *name, const char *doc, FlagBoundary boundary, std::initializer_list< Enumerator > enumerators) | |
Construct with name, documentation, boundary behavior, and enumerators. | |
void | addEnumerator (std::string name, TEnum value) |
Add an enumerator member to the definition. | |
PyObject * | build (TEnum value) const |
Creates a Python enum instance from a C++ enum value. | |
int | get (PyObject *obj, TEnum &value) const |
Extracts a C++ enum value from a Python object. | |
const char * | name () const |
The name of the Python enum type. | |
const char * | doc () const |
Optional docstring for the Python enum type. | |
PyObject * | type () const |
The Python enum type object, after freezeDefinition() has been called. | |
PyObject * | freezeDefinition (const char *moduleName, const char *scopeName) |
Freeze the enum definition and create the Python enum type. | |
Protected Member Functions | |
TPyObjPtr | doMakeEnumType (TPyObjPtr &&enumerators, TPyObjPtr &&kwargs) override |
Creates an enum.IntFlag -derived type with boundary behavior. | |
TPyObjPtr | doFreezeDefinition (TPyObjPtr &&kwargs) override |
Creates an enum.IntEnum -derived type. | |
TPyObjPtr | doValueObject (PyObject *obj) const override |
Extracts integer values from enum instances or integer objects. | |
TPyObjPtr | valueObject (PyObject *obj) const |
Returns the value of an enum instances as a Python object. | |
Definition of an enum.IntFlag
-derived enum type in Python.
C++ enums exported using IntFlagDefinition will generate a new enum type derived from enum.IntFlag
. The values of the Python enum will map directly on the C++ enum values, but then names need to be defined at export.
As enum.IntFlag
is used, the Python enum instances will also be valid int instances, and int instances are accepted when converting from Python to C++. Additionally, bitwise operations are supported.
Because this defines a new type, it must be added to a module or other class.
This class is typically not used directly. Use PY_SHADOW_INT_FLAG and PY_DECLARE_INT_FLAG_* macros instead.
Definition at line 508 of file enum_definition.h.
|
inline |
Construct with name, documentation, boundary behavior, and enumerators.
name | Python class name for the flag enum type (must have static storage duration) |
doc | Optional docstring for the Python enum type (must have static storage duration, or nullptr) |
boundary | Flag boundary behavior controlling how invalid flag combinations are handled |
enumerators | List of name-value pairs defining the flag members |
Keep
is supported (which is the default if this constructor is not used). Definition at line 527 of file enum_definition.h.
References lass::python::EnumDefinitionBase::doc(), lass::python::IntEnumDefinition< EnumType >::IntEnumDefinition(), and lass::python::EnumDefinitionBase::name().
|
inlineoverrideprotectedvirtual |
Creates an enum.IntFlag
-derived type with boundary behavior.
Overrides the base class to create a flag enum with bitwise operations support.
Reimplemented from lass::python::IntEnumDefinition< EnumType >.
Definition at line 537 of file enum_definition.h.
References lass::python::impl::makeIntFlagType(), and lass::python::EnumDefinitionBase::name().
|
inlineinherited |
Add an enumerator member to the definition.
name | Python name for the enumerator member |
value | C++ enum value |
Definition at line 367 of file enum_definition.h.
References lass::python::EnumDefinitionBase::name().
|
inlineinherited |
Creates a Python enum instance from a C++ enum value.
Converts the C++ enum to its corresponding Python enum instance.
Definition at line 375 of file enum_definition.h.
References lass::python::EnumDefinitionBase::type().
|
inlineinherited |
Extracts a C++ enum value from a Python object.
Accepts both enum instances and raw integers. Returns 0 on success, 1 on failure.
Definition at line 385 of file enum_definition.h.
References lass::python::EnumDefinitionBase::valueObject().
|
inlineoverrideprotectedvirtualinherited |
Creates an enum.IntEnum
-derived type.
Converts enumerators to Python tuple format and creates the integer enum type.
Implements lass::python::EnumDefinitionBase.
Definition at line 407 of file enum_definition.h.
References doMakeEnumType(), lass::python::IntEnumDefinition< EnumType >::Enumerator::enumerator, lass::python::fromSharedPtrToNakedCast(), and lass::python::IntEnumDefinition< EnumType >::Enumerator::name.
|
inlineoverrideprotectedvirtualinherited |
Extracts integer values from enum instances or integer objects.
Handles both integer enum instances and raw Python integers.
Reimplemented from lass::python::EnumDefinitionBase.
Definition at line 431 of file enum_definition.h.
References lass::python::EnumDefinitionBase::type().
|
inherited |
Freeze the enum definition and create the Python enum type.
PY_MODULE_ENUM()
or PY_CLASS_ENUM()
to add the enum to a module or class, which will call this method at the appropriate time. Definition at line 247 of file enum_definition.cpp.
|
protectedinherited |
Returns the value of an enum instances as a Python object.
If the object is not an instance of this enum type, a Python exception will be set and a null pointer will be returned.
Definition at line 230 of file enum_definition.cpp.
Referenced by lass::python::EnumDefinition< EnumType, ValueType >::get(), and lass::python::IntEnumDefinition< EnumType >::get().