- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# scopedconnection.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008
    00009 /***********************************************************************
    00010  Copyright (c) 2010 by Joel Fielder.  Others may also hold copyrights
    00011  on code in this file.  See the CREDITS.txt file in the top directory
    00012  of the distribution for details.
    00013
    00014  This file is part of MySQL++.
    00015
    00016  MySQL++ is free software; you can redistribute it and/or modify it
    00017  under the terms of the GNU Lesser General Public License as published
    00018  by the Free Software Foundation; either version 2.1 of the License, or
    00019  (at your option) any later version.
    00020
    00021  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00022  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00023  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00024  License for more details.
    00025
    00026  You should have received a copy of the GNU Lesser General Public
    00027  License along with MySQL++; if not, write to the Free Software
    00028  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00029  USA
    00030 ***********************************************************************/
    00031
    00032 #if !defined(MYSQLPP_SCOPEDCONNECTION_H)
    00033 #define MYSQLPP_SCOPEDCONNECTION_H
    00034
    00035 #include "common.h"
    00036
    00037 namespace mysqlpp {
    00038
    00039 #if !defined(DOXYGEN_IGNORE)
    00040 // Make Doxygen ignore this
    00041 class MYSQLPP_EXPORT Connection;
    00042 class MYSQLPP_EXPORT ConnectionPool;
    00043 #endif
    00044
    00048 class MYSQLPP_EXPORT ScopedConnection
    00049 {
    00050 public:
    00060         explicit ScopedConnection(ConnectionPool& pool, bool safe = false);
    00061
    00065         ~ScopedConnection();
    00066
    00068         Connection* operator->() const { return connection_; }
    00069
    00071         Connection& operator*() const { return *connection_; }
    00072
    00074         operator void*() const { return connection_; }
    00075
    00076 private:
    00077         // ScopedConnection objects cannot be copied.  We want them to be
    00078         // tightly scoped to their use point, not put in containers or
    00079         // passed around promiscuously.
    00080         ScopedConnection(const ScopedConnection& no_copies);
    00081         const ScopedConnection& operator=(const ScopedConnection& no_copies);
    00082
    00083         ConnectionPool& pool_;
    00084         Connection* const connection_;
    00085 };
    00086
    00087 } // end namespace mysqlpp
    00088
    00089 #endif // !defined(MYSQLPP_SCOPEDCONNECTION_H)
    00090