Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:15

0001 /*
0002     pybind11/options.h: global settings that are configurable at runtime.
0003 
0004     Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
0005 
0006     All rights reserved. Use of this source code is governed by a
0007     BSD-style license that can be found in the LICENSE file.
0008 */
0009 
0010 #pragma once
0011 
0012 #include "detail/common.h"
0013 
0014 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
0015 
0016 class options {
0017 public:
0018     // Default RAII constructor, which leaves settings as they currently are.
0019     options() : previous_state(global_state()) {}
0020 
0021     // Class is non-copyable.
0022     options(const options &) = delete;
0023     options &operator=(const options &) = delete;
0024 
0025     // Destructor, which restores settings that were in effect before.
0026     ~options() { global_state() = previous_state; }
0027 
0028     // Setter methods (affect the global state):
0029 
0030     options &disable_user_defined_docstrings() & {
0031         global_state().show_user_defined_docstrings = false;
0032         return *this;
0033     }
0034 
0035     options &enable_user_defined_docstrings() & {
0036         global_state().show_user_defined_docstrings = true;
0037         return *this;
0038     }
0039 
0040     options &disable_function_signatures() & {
0041         global_state().show_function_signatures = false;
0042         return *this;
0043     }
0044 
0045     options &enable_function_signatures() & {
0046         global_state().show_function_signatures = true;
0047         return *this;
0048     }
0049 
0050     options &disable_enum_members_docstring() & {
0051         global_state().show_enum_members_docstring = false;
0052         return *this;
0053     }
0054 
0055     options &enable_enum_members_docstring() & {
0056         global_state().show_enum_members_docstring = true;
0057         return *this;
0058     }
0059 
0060     // Getter methods (return the global state):
0061 
0062     static bool show_user_defined_docstrings() {
0063         return global_state().show_user_defined_docstrings;
0064     }
0065 
0066     static bool show_function_signatures() { return global_state().show_function_signatures; }
0067 
0068     static bool show_enum_members_docstring() {
0069         return global_state().show_enum_members_docstring;
0070     }
0071 
0072     // This type is not meant to be allocated on the heap.
0073     void *operator new(size_t) = delete;
0074 
0075 private:
0076     struct state {
0077         bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings.
0078         bool show_function_signatures = true;     //< Include auto-generated function signatures
0079                                                   //  in docstrings.
0080         bool show_enum_members_docstring = true;  //< Include auto-generated member list in enum
0081                                                   //  docstrings.
0082     };
0083 
0084     static state &global_state() {
0085         static state instance;
0086         return instance;
0087     }
0088 
0089     state previous_state;
0090 };
0091 
0092 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)