Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class 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 #if !defined(DOXYGEN_IGNORE)
00044 // Make Doxygen ignore this
00045 class MYSQLPP_EXPORT NoExceptions;
00046 #endif
00047 
00053 
00054 class MYSQLPP_EXPORT OptionalExceptions
00055 {
00056 public:
00060         OptionalExceptions(bool e = true) :
00061         exceptions_(e)
00062         {
00063         }
00064 
00066         virtual ~OptionalExceptions() { }
00067 
00069         void enable_exceptions() { exceptions_ = true; }
00070 
00072         void disable_exceptions() { exceptions_ = false; }
00073 
00075         bool throw_exceptions() const { return exceptions_; }
00076 
00077 protected:
00082         void set_exceptions(bool e) { exceptions_ = e; }
00083 
00086         friend class NoExceptions;
00087 
00088 private:
00089         bool exceptions_;
00090 };
00091 
00092 
00101 
00102 class MYSQLPP_EXPORT NoExceptions
00103 {
00104 public:
00110         NoExceptions(OptionalExceptions& a) :
00111         assoc_(a),
00112         exceptions_were_enabled_(a.throw_exceptions())
00113         {
00114                 assoc_.disable_exceptions();
00115         }
00116 
00120         ~NoExceptions()
00121         {
00122                 assoc_.set_exceptions(exceptions_were_enabled_);
00123         }
00124         
00125 private:
00126         OptionalExceptions& assoc_;
00127         bool exceptions_were_enabled_;
00128 
00129         // Hidden assignment operator and copy ctor, because we should not
00130         // be copied.
00131         NoExceptions(const NoExceptions&);
00132         NoExceptions& operator=(const NoExceptions&);
00133 };
00134 
00135 } // end namespace mysqlpp
00136 
00137 #endif // MYSQLPP_NOEXCEPTIONS_H
00138 

Generated on Wed Jul 11 15:34:34 2007 for MySQL++ by doxygen 1.3.5