MySQL++  3.3.0
scopedconnection.h
Go to the documentation of this file.
1 
9 /***********************************************************************
10  Copyright © 2010 by Joel Fielder. Others may also hold copyrights
11  on code in this file. See the CREDITS.txt file in the top directory
12  of the distribution for details.
13 
14  This file is part of MySQL++.
15 
16  MySQL++ is free software; you can redistribute it and/or modify it
17  under the terms of the GNU Lesser General Public License as published
18  by the Free Software Foundation; either version 2.1 of the License, or
19  (at your option) any later version.
20 
21  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public
27  License along with MySQL++; if not, write to the Free Software
28  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
29  USA
30 ***********************************************************************/
31 
32 #if !defined(MYSQLPP_SCOPEDCONNECTION_H)
33 #define MYSQLPP_SCOPEDCONNECTION_H
34 
35 #include "common.h"
36 
37 namespace mysqlpp {
38 
39 #if !defined(DOXYGEN_IGNORE)
40 // Make Doxygen ignore this
41 class MYSQLPP_EXPORT Connection;
42 class MYSQLPP_EXPORT ConnectionPool;
43 #endif
44 
48 class MYSQLPP_EXPORT ScopedConnection
49 {
50 public:
60  explicit ScopedConnection(ConnectionPool& pool, bool safe = false);
61 
62 #if __cplusplus >= 201103L
63  // ScopedConnection objects cannot be copied. We want them to be
64  // tightly scoped to their use point, not put in containers or
65  // passed around promiscuously.
67  ScopedConnection(const ScopedConnection& no_copies) = delete;
68  const ScopedConnection& operator=(const ScopedConnection& no_copies) = delete;
69 #endif
70 
75 
77  Connection* operator->() const { return connection_; }
78 
80  Connection& operator*() const { return *connection_; }
81 
83  operator void*() const { return connection_; }
84 
85 private:
86 #if __cplusplus < 201103L
87  // Pre C++11 alternative to no-copies ctors above.
88  ScopedConnection(const ScopedConnection& no_copies);
89  const ScopedConnection& operator=(const ScopedConnection& no_copies);
90 #endif
91 
92  ConnectionPool& pool_;
93  Connection* const connection_;
94 };
95 
96 } // end namespace mysqlpp
97 
98 #endif // !defined(MYSQLPP_SCOPEDCONNECTION_H)
99 
Manages a pool of connections for programs that need more than one Connection object at a time,...
Definition: cpool.h:69
Manages the connection to the database server.
Definition: connection.h:60
Grabs a Connection from a ConnectionPool on construction and releases it back to the pool on destruct...
Definition: scopedconnection.h:49
Connection & operator*() const
Dereference.
Definition: scopedconnection.h:80
Connection * operator->() const
Access the Connection pointer.
Definition: scopedconnection.h:77
This file includes top-level definitions for use both internal to the library, and outside it....