MySQL++  3.2.5
noexceptions.h
Go to the documentation of this file.
1 
15 /***********************************************************************
16  Copyright (c) 2005-2007 by Educational Technology Resources, Inc.
17  Others may also hold copyrights on code in this file. See the
18  CREDITS.txt file in the top directory of the distribution for details.
19 
20  This file is part of MySQL++.
21 
22  MySQL++ is free software; you can redistribute it and/or modify it
23  under the terms of the GNU Lesser General Public License as published
24  by the Free Software Foundation; either version 2.1 of the License, or
25  (at your option) any later version.
26 
27  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
28  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
30  License for more details.
31 
32  You should have received a copy of the GNU Lesser General Public
33  License along with MySQL++; if not, write to the Free Software
34  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
35  USA
36 ***********************************************************************/
37 
38 #ifndef MYSQLPP_NOEXCEPTIONS_H
39 #define MYSQLPP_NOEXCEPTIONS_H
40 
41 #include "common.h"
42 
43 namespace mysqlpp {
44 
45 #if !defined(DOXYGEN_IGNORE)
46 // Make Doxygen ignore this
47 class MYSQLPP_EXPORT NoExceptions;
48 #endif
49 
70 
71 class MYSQLPP_EXPORT OptionalExceptions
72 {
73 public:
77  OptionalExceptions(bool e = true) :
78  exceptions_(e)
79  {
80  }
81 
83  virtual ~OptionalExceptions() { }
84 
86  void enable_exceptions() const { exceptions_ = true; }
87 
89  void disable_exceptions() const { exceptions_ = false; }
90 
92  bool throw_exceptions() const { return exceptions_; }
93 
94 protected:
99  void set_exceptions(bool e) const { exceptions_ = e; }
100 
103  friend class NoExceptions;
104 
105 private:
106  mutable bool exceptions_;
107 };
108 
109 
118 
119 class MYSQLPP_EXPORT NoExceptions
120 {
121 public:
128  assoc_(a),
129  exceptions_were_enabled_(a.throw_exceptions())
130  {
131  assoc_.disable_exceptions();
132  }
133 
138  {
139  assoc_.set_exceptions(exceptions_were_enabled_);
140  }
141 
142 private:
143  const OptionalExceptions& assoc_;
144  bool exceptions_were_enabled_;
145 
146  // Hidden assignment operator and copy ctor, because we should not
147  // be copied.
148  NoExceptions(const NoExceptions&);
149  NoExceptions& operator=(const NoExceptions&);
150 };
151 
152 } // end namespace mysqlpp
153 
154 #endif // MYSQLPP_NOEXCEPTIONS_H
155 
void disable_exceptions() const
Disable exceptions from the object.
Definition: noexceptions.h:89
bool throw_exceptions() const
Returns true if exceptions are enabled.
Definition: noexceptions.h:92
Disable exceptions in an object derived from OptionalExceptions.
Definition: noexceptions.h:119
OptionalExceptions(bool e=true)
Default constructor.
Definition: noexceptions.h:77
Interface allowing a class to have optional exceptions.
Definition: noexceptions.h:71
~NoExceptions()
Destructor.
Definition: noexceptions.h:137
virtual ~OptionalExceptions()
Destroy object.
Definition: noexceptions.h:83
This file includes top-level definitions for use both internal to the library, and outside it....
NoExceptions(const OptionalExceptions &a)
Constructor.
Definition: noexceptions.h:127
void set_exceptions(bool e) const
Sets the exception state to a particular value.
Definition: noexceptions.h:99
void enable_exceptions() const
Enable exceptions from the object.
Definition: noexceptions.h:86