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 
16 class options {
17 public:
18 
19  // Default RAII constructor, which leaves settings as they currently are.
20  options() : previous_state(global_state()) {}
21 
22  // Class is non-copyable.
23  options(const options&) = delete;
24  options& operator=(const options&) = delete;
25 
26  // Destructor, which restores settings that were in effect before.
28  global_state() = previous_state;
29  }
30 
31  // Setter methods (affect the global state):
32 
33  options& disable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = false; return *this; }
34 
35  options& enable_user_defined_docstrings() & { global_state().show_user_defined_docstrings = true; return *this; }
36 
37  options& disable_function_signatures() & { global_state().show_function_signatures = false; return *this; }
38 
39  options& enable_function_signatures() & { global_state().show_function_signatures = true; return *this; }
40 
41  // Getter methods (return the global state):
42 
43  static bool show_user_defined_docstrings() { return global_state().show_user_defined_docstrings; }
44 
45  static bool show_function_signatures() { return global_state().show_function_signatures; }
46 
47  // This type is not meant to be allocated on the heap.
48  void* operator new(size_t) = delete;
49 
50 private:
51 
52  struct state {
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.
55  };
56 
57  static state &global_state() {
58  static state instance;
59  return instance;
60  }
61 
63 };
64 
options & enable_function_signatures()&
Definition: options.h:39
options & disable_function_signatures()&
Definition: options.h:37
options & enable_user_defined_docstrings()&
Definition: options.h:35
state previous_state
Definition: options.h:62
The &#39;instance&#39; type which needs to be standard layout (need to be able to use &#39;offsetof&#39;) ...
options & disable_user_defined_docstrings()&
Definition: options.h:33
options()
Definition: options.h:20
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t real_t idx_t * options
static bool show_function_signatures()
Definition: options.h:45
static state & global_state()
Definition: options.h:57
static bool show_user_defined_docstrings()
Definition: options.h:43
~options()
Definition: options.h:27
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:06