- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

scopedconnection.h
Go to the documentation of this file.
1
9 /***********************************************************************
10 Copyright (c) 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
65 ~ScopedConnection();
66
68 Connection* operator->() const { return connection_; }
69
71 Connection& operator*() const { return *connection_; }
72
74 operator void*() const { return connection_; }
75
76 private:
77 // ScopedConnection objects cannot be copied. We want them to be
78 // tightly scoped to their use point, not put in containers or
79 // passed around promiscuously.
80 ScopedConnection(const ScopedConnection& no_copies);
81 const ScopedConnection& operator=(const ScopedConnection& no_copies);
82
83 ConnectionPool& pool_;
84 Connection* const connection_;
85 };
86
87 } // end namespace mysqlpp
88
89 #endif // !defined(MYSQLPP_SCOPEDCONNECTION_H)
90
mysqlpp::ScopedConnection
Grabs a Connection from a ConnectionPool on construction and releases it back to the pool on destruct...
Definition: scopedconnection.h:48
mysqlpp::Connection
Manages the connection to the database server.
Definition: connection.h:59
mysqlpp::ConnectionPool
Manages a pool of connections for programs that need more than one Connection object at a time...
Definition: cpool.h:68
mysqlpp::ScopedConnection::operator*
Connection & operator*() const
Dereference.
Definition: scopedconnection.h:71
mysqlpp::ScopedConnection::operator->
Connection * operator->() const
Access the Connection pointer.
Definition: scopedconnection.h:68
common.h
This file includes top-level definitions for use both internal to the library, and outside it...