libpqxx  5.0
errorhandler.hxx
1 /*-------------------------------------------------------------------------
2  *
3  * FILE
4  * pqxx/errorhandler.hxx
5  *
6  * DESCRIPTION
7  * definition of the pqxx::errorhandler class.
8  * pqxx::errorhandler handlers errors and warnings in a database session.
9  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/connection_base instead.
10  *
11  * Copyright (c) 2012-2015, Jeroen T. Vermeulen <jtv@xs4all.nl>
12  *
13  * See COPYING for copyright license. If you did not receive a file called
14  * COPYING with this source code, please notify the distributor of this mistake,
15  * or contact the author.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PQXX_H_ERRORHANDLER
20 #define PQXX_H_ERRORHANDLER
21 
22 #include "pqxx/compiler-public.hxx"
23 #include "pqxx/compiler-internal-pre.hxx"
24 
25 #include <functional>
26 
27 
28 namespace pqxx
29 {
30 class connection_base;
31 
32 namespace internal
33 {
34 namespace gate
35 {
36 class errorhandler_connection_base;
37 }
38 }
39 
45 
57 class PQXX_LIBEXPORT errorhandler :
58  public std::unary_function<const char[], bool>
59 {
60 public:
61  explicit errorhandler(connection_base &);
62  virtual ~errorhandler();
63 
65 
69  virtual bool operator()(const char msg[]) PQXX_NOEXCEPT =0;
70 
71 private:
72  connection_base *m_home;
73 
74  friend class internal::gate::errorhandler_connection_base;
75  void unregister() PQXX_NOEXCEPT;
76 
77  // Not allowed:
78  errorhandler() PQXX_DELETED_OP;
79  errorhandler(const errorhandler &) PQXX_DELETED_OP;
80  errorhandler &operator=(const errorhandler &) PQXX_DELETED_OP;
81 };
82 
83 
86 {
87 public:
88  quiet_errorhandler(connection_base &conn) : errorhandler(conn) {}
89 
90  virtual bool operator()(const char[]) PQXX_NOEXCEPT PQXX_OVERRIDE
91  { return false; }
92 };
93 
98 } // namespace pqxx
99 
100 #include "pqxx/compiler-internal-post.hxx"
101 
102 #endif
connection_base abstract base class; represents a connection to a database.
Definition: connection_base.hxx:149
virtual bool operator()(const char[]) PQXX_NOEXCEPT PQXX_OVERRIDE
Define in subclass: receive an error or warning message from the database.
Definition: errorhandler.hxx:90
quiet_errorhandler(connection_base &conn)
Definition: errorhandler.hxx:88
Base class for error-handler callbacks.
Definition: errorhandler.hxx:57
An error handler that suppresses any previously registered error handlers.
Definition: errorhandler.hxx:85