libpqxx  7.7.1
transaction_focus.hxx
1 
9 #ifndef PQXX_H_TRANSACTION_FOCUS
10 #define PQXX_H_TRANSACTION_FOCUS
11 
12 #if !defined(PQXX_HEADER_PRE)
13 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
14 #endif
15 
16 #include "pqxx/util.hxx"
17 
18 namespace pqxx
19 {
21 
28 class PQXX_LIBEXPORT transaction_focus
29 {
30 public:
32  transaction_base &t, std::string_view cname, std::string_view oname) :
33  m_trans{t}, m_classname{cname}, m_name{oname}
34  {}
35 
37  transaction_base &t, std::string_view cname, std::string &&oname) :
38  m_trans{t}, m_classname{cname}, m_name{std::move(oname)}
39  {}
40 
41  transaction_focus(transaction_base &t, std::string_view cname) :
42  m_trans{t}, m_classname{cname}
43  {}
44 
45  transaction_focus() = delete;
46  transaction_focus(transaction_focus const &) = delete;
47  transaction_focus &operator=(transaction_focus const &) = delete;
48 
50  [[nodiscard]] constexpr std::string_view classname() const noexcept
51  {
52  return m_classname;
53  }
54 
56  [[nodiscard]] std::string_view name() const &noexcept { return m_name; }
57 
58  [[nodiscard]] std::string description() const
59  {
60  return pqxx::internal::describe_object(m_classname, m_name);
61  }
62 
64 
68 
70 
73  transaction_focus &operator=(transaction_focus &&) = delete;
74 
75 protected:
76  void register_me();
77  void unregister_me() noexcept;
78  void reg_pending_error(std::string const &) noexcept;
79  bool registered() const noexcept { return m_registered; }
80 
82 
83 private:
84  bool m_registered = false;
85  std::string_view m_classname;
86  std::string m_name;
87 };
88 } // namespace pqxx
89 #endif
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:51
transaction_focus(transaction_base &t, std::string_view cname, std::string_view oname)
Definition: transaction_focus.hxx:31
Base class for things that monopolise a transaction&#39;s attention.
Definition: transaction_focus.hxx:28
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
transaction_focus(transaction_base &t, std::string_view cname)
Definition: transaction_focus.hxx:41
std::string_view name() const &noexcept
Name for this object, if the caller passed one; empty string otherwise.
Definition: transaction_focus.hxx:56
bool registered() const noexcept
Definition: transaction_focus.hxx:79
std::string description() const
Definition: transaction_focus.hxx:58
constexpr std::string_view classname() const noexcept
Class name, for human consumption.
Definition: transaction_focus.hxx:50
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:76
transaction_focus(transaction_base &t, std::string_view cname, std::string &&oname)
Definition: transaction_focus.hxx:36
transaction_base & m_trans
Definition: transaction_focus.hxx:81