Library of Assembled Shared Sources
lass::python::impl::NoNone< T > Class Template Reference

Wrapper to prevent None values being passed to and from Python. More...

#include <no_none.h>

Inheritance diagram for lass::python::impl::NoNone< T >:

Public Member Functions

T & reference ()
 Return reference to wrapped value.
 
const T & reference () const
 Return reference to wrapped value.
 

Detailed Description

template<typename T>
class lass::python::impl::NoNone< T >

Wrapper to prevent None values being passed to and from Python.

Use this class to wrap a value of type T that could be None in Python (for example, a pointer type), but you want to ensure that the value is always valid and not None.

using ShaderPtr = std::shared_ptr<Shader>;
NoNone<ShaderPtr> subtract(const NoNone<ShaderPtr>& a, const NoNone<ShaderPtr>& b)
{
return ShaderPtr(new SubtractShaders(a, b));
}
PY_MODULE_FUNCTION_DOC(shader_graph, subtract, "Subtract two shaders")
#define PY_MODULE_FUNCTION_DOC(i_module, f_cppFunction, s_doc)
Export a C++ free function to Python using the C++ function name with documentation.

Works in both directions: from and to Python. In case a None value is passed or returned, it will raise a Python TypeError instead.

Note
This class does ONLY prevents None values from crossing the Python/C++ boundary. It does NOT provide any other runtime or compile-time checks. You can happily put a nullptr in a NoNone<T> as long as you don't pass it to Python.

Built-in support for NoNone is provided for raw pointers T*, util::SharedPtr<T>, and std::shared_ptr<T>. To support your own types, you must specialize PyExportTraits: see PyExportTraitsNoNone for more information.

See also
PyExportTraitsNoNone
PyExportTraits<NoNone<T*>>
PyExportTraits<NoNone<util::SharedPtr<T,S,C>>>
PyExportTraits<NoNone<std::shared_ptr<T>>>
MaybeNone

Definition at line 83 of file no_none.h.


The documentation for this class was generated from the following file: