# noexceptions.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008
    00009
    00010
    00011
    00012
    00013
    00014
    00015 /***********************************************************************
    00016  Copyright (c) 2005-2007 by Educational Technology Resources, Inc.
    00017  Others may also hold copyrights on code in this file.  See the
    00018  CREDITS.txt file in the top directory of the distribution for details.
    00019
    00020  This file is part of MySQL++.
    00021
    00022  MySQL++ is free software; you can redistribute it and/or modify it
    00023  under the terms of the GNU Lesser General Public License as published
    00024  by the Free Software Foundation; either version 2.1 of the License, or
    00025  (at your option) any later version.
    00026
    00027  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00028  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00029  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00030  License for more details.
    00031
    00032  You should have received a copy of the GNU Lesser General Public
    00033  License along with MySQL++; if not, write to the Free Software
    00034  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00035  USA
    00036 ***********************************************************************/
    00037
    00038 #ifndef MYSQLPP_NOEXCEPTIONS_H
    00039 #define MYSQLPP_NOEXCEPTIONS_H
    00040
    00041 #include "common.h"
    00042
    00043 namespace mysqlpp {
    00044
    00045 #if !defined(DOXYGEN_IGNORE)
    00046 // Make Doxygen ignore this
    00047 class MYSQLPP_EXPORT NoExceptions;
    00048 #endif
    00049
    00070
    00071 class MYSQLPP_EXPORT OptionalExceptions
    00072 {
    00073 public:
    00077         OptionalExceptions(bool e = true) :
    00078         exceptions_(e)
    00079         {
    00080         }
    00081
    00083         virtual ~OptionalExceptions() { }
    00084
    00086         void enable_exceptions() const { exceptions_ = true; }
    00087
    00089         void disable_exceptions() const { exceptions_ = false; }
    00090
    00092         bool throw_exceptions() const { return exceptions_; }
    00093
    00094 protected:
    00099         void set_exceptions(bool e) const { exceptions_ = e; }
    00100
    00103         friend class NoExceptions;
    00104
    00105 private:
    00106         mutable bool exceptions_;
    00107 };
    00108
    00109
    00118
    00119 class MYSQLPP_EXPORT NoExceptions
    00120 {
    00121 public:
    00127         NoExceptions(const OptionalExceptions& a) :
    00128         assoc_(a),
    00129         exceptions_were_enabled_(a.throw_exceptions())
    00130         {
    00131                 assoc_.disable_exceptions();
    00132         }
    00133
    00137         ~NoExceptions()
    00138         {
    00139                 assoc_.set_exceptions(exceptions_were_enabled_);
    00140         }
    00141
    00142 private:
    00143         const OptionalExceptions& assoc_;
    00144         bool exceptions_were_enabled_;
    00145
    00146         // Hidden assignment operator and copy ctor, because we should not
    00147         // be copied.
    00148         NoExceptions(const NoExceptions&);
    00149         NoExceptions& operator=(const NoExceptions&);
    00150 };
    00151
    00152 } // end namespace mysqlpp
    00153
    00154 #endif // MYSQLPP_NOEXCEPTIONS_H
    00155