MySQL++ Reference Manual

Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members

# 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 by Educational Technology Resources, Inc.
    00017  Others may also hold copyrights on code in this file.  See the CREDITS
    00018  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 namespace mysqlpp {
    00042
    00043 class NoExceptions;
    00044
    00050
    00051 class OptionalExceptions
    00052 {
    00053 public:
    00057         OptionalExceptions(bool e = true) :
    00058         exceptions_(e)
    00059         {
    00060         }
    00061
    00063         virtual ~OptionalExceptions() { }
    00064
    00066         void enable_exceptions() { exceptions_ = true; }
    00067
    00069         void disable_exceptions() { exceptions_ = false; }
    00070
    00072         bool throw_exceptions() const { return exceptions_; }
    00073
    00074 protected:
    00079         void set_exceptions(bool e) { exceptions_ = e; }
    00080
    00083         friend class NoExceptions;
    00084
    00085 private:
    00086         bool exceptions_;
    00087 };
    00088
    00089
    00098
    00099 class NoExceptions
    00100 {
    00101 public:
    00107         NoExceptions(OptionalExceptions& a) :
    00108         assoc_(a),
    00109         exceptions_were_enabled_(a.throw_exceptions())
    00110         {
    00111                 assoc_.disable_exceptions();
    00112         }
    00113
    00117         ~NoExceptions()
    00118         {
    00119                 assoc_.set_exceptions(exceptions_were_enabled_);
    00120         }
    00121
    00122 private:
    00123         OptionalExceptions& assoc_;
    00124         bool exceptions_were_enabled_;
    00125
    00126         // Hidden assignment operator and copy ctor, because we should not
    00127         // be copied.
    00128         NoExceptions(const NoExceptions&);
    00129         NoExceptions& operator=(const NoExceptions&);
    00130 };
    00131
    00132 } // end namespace mysqlpp
    00133
    00134 #endif // MYSQLPP_NOEXCEPTIONS_H
    00135