00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
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
00147
00148 NoExceptions(const NoExceptions&);
00149 NoExceptions& operator=(const NoExceptions&);
00150 };
00151
00152 }
00153
00154 #endif // MYSQLPP_NOEXCEPTIONS_H
00155