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  // 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 
51  global_state().show_enum_members_docstring = false;
52  return *this;
53  }
54 
56  global_state().show_enum_members_docstring = true;
57  return *this;
58  }
59 
60  // Getter methods (return the global state):
61 
63  return global_state().show_user_defined_docstrings;
64  }
65 
66  static bool show_function_signatures() { return global_state().show_function_signatures; }
67 
69  return global_state().show_enum_members_docstring;
70  }
71 
72  // This type is not meant to be allocated on the heap.
73  void *operator new(size_t) = delete;
74 
75 private:
76  struct state {
77  bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings.
78  bool show_function_signatures = true; //< Include auto-generated function signatures
79  // in docstrings.
80  bool show_enum_members_docstring = true; //< Include auto-generated member list in enum
81  // docstrings.
82  };
83 
84  static state &global_state() {
85  static state instance;
86  return instance;
87  }
88 
90 };
91 
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
options::show_enum_members_docstring
static bool show_enum_members_docstring()
Definition: options.h:68
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
options::options
options()
Definition: options.h:19
options::disable_function_signatures
options & disable_function_signatures() &
Definition: options.h:40
instance
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition: wrap/pybind11/include/pybind11/detail/common.h:583
options::enable_function_signatures
options & enable_function_signatures() &
Definition: options.h:45
PYBIND11_NAMESPACE
Definition: test_custom_type_casters.cpp:24
common.h
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
options::disable_user_defined_docstrings
options & disable_user_defined_docstrings() &
Definition: options.h:30
options
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t real_t idx_t * options
Definition: include/metis.h:199
options::enable_user_defined_docstrings
options & enable_user_defined_docstrings() &
Definition: options.h:35
options::enable_enum_members_docstring
options & enable_enum_members_docstring() &
Definition: options.h:55
options::show_function_signatures
static bool show_function_signatures()
Definition: options.h:66
options::state
Definition: options.h:76
options::show_user_defined_docstrings
static bool show_user_defined_docstrings()
Definition: options.h:62
options::global_state
static state & global_state()
Definition: options.h:84
options::previous_state
state previous_state
Definition: options.h:89
options::disable_enum_members_docstring
options & disable_enum_members_docstring() &
Definition: options.h:50
options
Definition: options.h:16
options::~options
~options()
Definition: options.h:26


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:12:24