2 pybind11/options.h: global settings that are configurable at runtime.
4 Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
6 All rights reserved. Use of this source code is governed by a
7 BSD-style license that can be found in the LICENSE file.
12 #include "detail/common.h"
14 NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
19 // Default RAII constructor, which leaves settings as they currently are.
20 options() : previous_state(global_state()) {}
22 // Class is non-copyable.
23 options(const options&) = delete;
24 options& operator=(const options&) = delete;
26 // Destructor, which restores settings that were in effect before.
28 global_state() = previous_state;
31 // Setter methods (affect the global state):
33 options& disable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = false; return *this; }
35 options& enable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = true; return *this; }
37 options& disable_function_signatures() & { global_state().show_function_signatures = false; return *this; }
39 options& enable_function_signatures() & { global_state().show_function_signatures = true; return *this; }
41 // Getter methods (return the global state):
43 static bool show_user_defined_docstrings() { return global_state().show_user_defined_docstrings; }
45 static bool show_function_signatures() { return global_state().show_function_signatures; }
47 // This type is not meant to be allocated on the heap.
48 void* operator new(size_t) = delete;
53 bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings.
54 bool show_function_signatures = true; //< Include auto-generated function signatures in docstrings.
57 static state &global_state() {
58 static state instance;
65 NAMESPACE_END(PYBIND11_NAMESPACE)