libpqxx  7.7.0
transaction_focus.hxx
1 
9 #ifndef PQXX_H_TRANSACTION_FOCUS
10 #define PQXX_H_TRANSACTION_FOCUS
11 
12 #include "pqxx/util.hxx"
13 
14 namespace pqxx
15 {
17 
24 class PQXX_LIBEXPORT transaction_focus
25 {
26 public:
28  transaction_base &t, std::string_view cname, std::string_view oname) :
29  m_trans{t}, m_classname{cname}, m_name{oname}
30  {}
31 
33  transaction_base &t, std::string_view cname, std::string &&oname) :
34  m_trans{t}, m_classname{cname}, m_name{std::move(oname)}
35  {}
36 
37  transaction_focus(transaction_base &t, std::string_view cname) :
38  m_trans{t}, m_classname{cname}
39  {}
40 
41  transaction_focus() = delete;
42  transaction_focus(transaction_focus const &) = delete;
43  transaction_focus &operator=(transaction_focus const &) = delete;
44 
46  [[nodiscard]] std::string_view classname() const noexcept
47  {
48  return m_classname;
49  }
50 
52  [[nodiscard]] std::string_view name() const &noexcept { return m_name; }
53 
54  [[nodiscard]] std::string description() const
55  {
56  return pqxx::internal::describe_object(m_classname, m_name);
57  }
58 
60 
64 
66 
69  transaction_focus &operator=(transaction_focus &&) = delete;
70 
71 protected:
72  void register_me();
73  void unregister_me() noexcept;
74  void reg_pending_error(std::string const &) noexcept;
75  bool registered() const noexcept { return m_registered; }
76 
78 
79 private:
80  bool m_registered = false;
81  std::string_view m_classname;
82  std::string m_name;
83 };
84 } // namespace pqxx
85 #endif
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:72
transaction_focus(transaction_base &t, std::string_view cname)
Definition: transaction_focus.hxx:37
std::string_view name() const &noexcept
Name for this object, if the caller passed one; empty string otherwise.
Definition: transaction_focus.hxx:52
transaction_focus(transaction_base &t, std::string_view cname, std::string_view oname)
Definition: transaction_focus.hxx:27
std::string describe_object(std::string_view class_name, std::string_view name)
Describe an object for humans, based on class name and optional name.
Definition: util.cxx:72
Base class for things that monopolise a transaction's attention.
Definition: transaction_focus.hxx:24
bool registered() const noexcept
Definition: transaction_focus.hxx:75
std::string description() const
Definition: transaction_focus.hxx:54
std::string_view classname() const noexcept
Class name, for human consumption.
Definition: transaction_focus.hxx:46
transaction_base & m_trans
Definition: transaction_focus.hxx:77
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
transaction_focus(transaction_base &t, std::string_view cname, std::string &&oname)
Definition: transaction_focus.hxx:32