Library of Assembled Shared Sources
enum_definition.h File Reference
#include "python_common.h"
#include "pyobject_ptr.h"
#include "py_tuple.h"
#include "../num/num_traits.h"
#include "../stde/vector_map.h"
#include <unordered_map>
#include <optional>
Include dependency graph for enum_definition.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

class  lass::python::EnumDefinitionBase
 Base class of all enum definitions. More...
 
class  lass::python::IntEnumDefinition< EnumType >
 Definition of an enum.IntEnum-derived enum type in Python. More...
 
struct  lass::python::IntEnumDefinition< EnumType >::Enumerator
 Represents a single enumerator member with name and C++ enum value. More...
 
class  lass::python::IntFlagDefinition< EnumType >
 Definition of an enum.IntFlag-derived enum type in Python. More...
 
class  lass::python::EnumDefinition< EnumType, ValueType >
 Definition of a general enum.Enum-derived enum type in Python. More...
 
struct  lass::python::EnumDefinition< EnumType, ValueType >::Enumerator
 Represents a single enumerator with name, C++ enum value, and Python value. More...
 
class  lass::python::StrEnumDefinition< EnumType, ValueType >
 Definition of an enum.StrEnum-derived enum type in Python. More...
 

Namespaces

namespace  lass
 Library for Assembled Shared Sources.
 
namespace  lass::python
 Comprehensive C++ to Python binding library.
 

Macros

Integer Enum Support

Macros for exporting C++ integer enums as Python enum.IntEnum types.

#define PY_SHADOW_INT_ENUM(dllInterface, t_cppEnum)
 Specializes PyExportTraits for a C++ enum using enum.IntEnum.
 
#define PY_DECLARE_INT_ENUM_NAME(t_cppEnum, s_name)
 Defines the enumDefinition with name only for enum.IntEnum.
 
#define PY_DECLARE_INT_ENUM_NAME_DOC(t_cppEnum, s_name, s_doc)
 Defines the enumDefinition with name and docstring for enum.IntEnum.
 
#define PY_DECLARE_INT_ENUM_EX(t_cppEnum)
 Defines the enumDefinition for initialization with constructor arguments for enum.IntEnum.
 
Integer Flag Support

Macros for exporting C++ flag enums as Python enum.IntFlag types with bitwise operations.

#define PY_SHADOW_INT_FLAG(dllInterface, t_cppEnum)
 Specializes PyExportTraits for a C++ enum using enum.IntFlag.
 
#define PY_DECLARE_INT_FLAG_NAME(t_cppEnum, s_name)
 Defines the enumDefinition with name only for enum.IntFlag.
 
#define PY_DECLARE_INT_FLAG_NAME_DOC(t_cppEnum, s_name, s_doc)
 Defines the enumDefinition with name and docstring for enum.IntFlag.
 
#define PY_DECLARE_INT_FLAG_EX(t_cppEnum)
 Defines the enumDefinition for initialization with constructor arguments for enum.IntFlag.
 
Generic Enum Support

Macros for exporting C++ enums as Python enum.Enum types with custom value types.

#define PY_SHADOW_ENUM(dllInterface, t_cppEnum, t_valueType)
 Specializes PyExportTraits for a C++ enum using generic enum.Enum.
 
#define PY_DECLARE_ENUM_NAME(t_cppEnum, t_valueType, s_name)
 Defines the enumDefinition with name only for generic enum.Enum.
 
#define PY_DECLARE_ENUM_NAME_DOC(t_cppEnum, t_valueType, s_name, s_doc)
 Defines the enumDefinition with name and docstring for generic enum.Enum.
 
#define PY_DECLARE_ENUM_EX(t_cppEnum, t_valueType)
 Defines the enumDefinition for initialization with constructor arguments for generic enum.Enum.
 
String Enum Support

Macros for exporting C++ enums as Python enum.StrEnum types with string values.

#define PY_SHADOW_STR_ENUM(dllInterface, t_cppEnum)
 Specializes PyExportTraits for a C++ enum using enum.StrEnum.
 
#define PY_DECLARE_STR_ENUM_NAME(t_cppEnum, s_name)
 Defines the enumDefinition with name only for enum.StrEnum.
 
#define PY_DECLARE_STR_ENUM_NAME_DOC(t_cppEnum, s_name, s_doc)
 Defines the enumDefinition with name and docstring for enum.StrEnum.
 
#define PY_DECLARE_STR_ENUM_EX(t_cppEnum)
 Defines the enumDefinition for initialization with constructor arguments for enum.StrEnum.
 
Common Enum Utilities

Utility macros for adding enum definitions to modules and classes.

#define PY_MODULE_ENUM(i_module, t_cppEnum)
 Adds an enum definition to a Python module.
 
#define PY_CLASS_ENUM(i_cppClass, t_cppEnum)
 Adds an enum definition as a nested enum to a Python class.
 

Enumerations

enum class  lass::python::FlagBoundary { lass::python::FlagBoundary::Keep , lass::python::FlagBoundary::Strict , lass::python::FlagBoundary::Conform }
 Defines the boundary behavior for enum.IntFlag-derived enums. More...
 

Functions

TPyObjPtr lass::python::impl::makeEnumType (const char *name, TPyObjPtr &&enumerators, TPyObjPtr &&kwargs)
 Creates a basic enum.Enum type.
 
TPyObjPtr lass::python::impl::makeIntEnumType (const char *name, TPyObjPtr &&enumerators, TPyObjPtr &&kwargs)
 Creates an enum.IntEnum type.
 
TPyObjPtr lass::python::impl::makeIntFlagType (const char *name, TPyObjPtr &&enumerators, TPyObjPtr &&kwargs, FlagBoundary boundary=FlagBoundary::Keep)
 Creates an enum.IntFlag type.
 
TPyObjPtr lass::python::impl::makeStrEnumType (const char *name, TPyObjPtr &&enumerators, TPyObjPtr &&kwargs)
 Creates an enum.StrEnum type (or equivalent for Python < 3.11).
 

Detailed Description

Author
Bram de Greve (bram@.nosp@m.coca.nosp@m.mware.nosp@m..com)
Tom De Muer (tom@c.nosp@m.ocam.nosp@m.ware..nosp@m.com)

*** BEGIN LICENSE INFORMATION ***

The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://lass.sourceforge.net/cpal-license. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

The Original Code is LASS - Library of Assembled Shared Sources.

The Initial Developer of the Original Code is Bram de Greve and Tom De Muer. The Original Developer is the Initial Developer.

All portions of the code written by the Initial Developer are: Copyright (C) 2022-2025 the Initial Developer. All Rights Reserved.

Contributor(s):

Alternatively, the contents of this file may be used under the terms of the GNU General Public License Version 2 or later (the GPL), in which case the provisions of GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL and not to allow others to use your version of this file under the CPAL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL License. If you do not delete the provisions above, a recipient may use your version of this file under either the CPAL or the GPL.

*** END LICENSE INFORMATION ***

Definition in file enum_definition.h.