μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
options.h
Go to the documentation of this file.
1/*
2 pybind11/options.h: global settings that are configurable at runtime.
3
4 Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
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.
8*/
9
10#pragma once
11
12#include "detail/common.h"
13
15
16class options {
17public:
18 // Default RAII constructor, which leaves settings as they currently are.
19 options() : previous_state(global_state()) {}
20
21 // Class is non-copyable.
22 options(const options &) = delete;
23 options &operator=(const options &) = delete;
24
25 // Destructor, which restores settings that were in effect before.
26 ~options() { global_state() = previous_state; }
27
28 // Setter methods (affect the global state):
29
31 global_state().show_user_defined_docstrings = false;
32 return *this;
33 }
34
36 global_state().show_user_defined_docstrings = true;
37 return *this;
38 }
39
41 global_state().show_function_signatures = false;
42 return *this;
43 }
44
46 global_state().show_function_signatures = true;
47 return *this;
48 }
49
50 // Getter methods (return the global state):
51
53 return global_state().show_user_defined_docstrings;
54 }
55
56 static bool show_function_signatures() { return global_state().show_function_signatures; }
57
58 // This type is not meant to be allocated on the heap.
59 void *operator new(size_t) = delete;
60
61private:
62 struct state {
63 bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings.
64 bool show_function_signatures = true; //< Include auto-generated function signatures
65 // in docstrings.
66 };
67
68 static state &global_state() {
69 static state instance;
70 return instance;
71 }
72
74};
75
options(const options &)=delete
options & disable_function_signatures() &
Definition: options.h:40
options & enable_function_signatures() &
Definition: options.h:45
options()
Definition: options.h:19
options & operator=(const options &)=delete
state previous_state
Definition: options.h:73
options & disable_user_defined_docstrings() &
Definition: options.h:30
static state & global_state()
Definition: options.h:68
~options()
Definition: options.h:26
static bool show_function_signatures()
Definition: options.h:56
static bool show_user_defined_docstrings()
Definition: options.h:52
options & enable_user_defined_docstrings() &
Definition: options.h:35
std::size_t size_t
Definition: common.h:461
#define PYBIND11_NAMESPACE_END(name)
Definition: common.h:21
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: common.h:20
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition: common.h:554