Author: wyoung
Date: Tue Dec 11 02:03:19 2007
New Revision: 1989
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1989&view=rev
Log:
OptionalExceptions interface is now completely const (and its internal
flag is mutable, consequently) so you can disable exceptions on const
subclass instances. This is a slight strain on the definition of
"const", but it changes the behavior of the subclass only in exceptional
circumstances, literally.
Modified:
trunk/lib/noexceptions.h
Modified: trunk/lib/noexceptions.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/noexceptions.h?rev=1989&r1=1988&r2=1989&view=diff
==============================================================================
--- trunk/lib/noexceptions.h (original)
+++ trunk/lib/noexceptions.h Tue Dec 11 02:03:19 2007
@@ -52,6 +52,21 @@
/// A class derives from this one to acquire a standard interface for
/// disabling exceptions, possibly only temporarily. By default,
/// exceptions are enabled.
+///
+/// Note that all methods are const even though some of them change our
+/// internal flag indicating whether exceptions should be thrown. This
+/// is justifiable because this is just an interface class, and it
+/// changes the behavior of our subclass literally only in exceptional
+/// conditions. This Jesuitical interpretation of "const" is required
+/// because you may want to disable exceptions on const subclass
+/// instances.
+///
+/// If it makes you feel better about this, consider that the real
+/// change isn't within the const OptionalExceptions subclass instance.
+/// What changes is the code wrapping the method call on that instance
+/// that can optionally throw an exception. This outside code is in
+/// a better position to say what "const" means than the subclass
+/// instance.
class MYSQLPP_EXPORT OptionalExceptions
{
@@ -68,10 +83,10 @@
virtual ~OptionalExceptions() { }
/// \brief Enable exceptions from the object
- void enable_exceptions() { exceptions_ = true; }
+ void enable_exceptions() const { exceptions_ = true; }
/// \brief Disable exceptions from the object
- void disable_exceptions() { exceptions_ = false; }
+ void disable_exceptions() const { exceptions_ = false; }
/// \brief Returns true if exceptions are enabled
bool throw_exceptions() const { return exceptions_; }
@@ -81,14 +96,14 @@
///
/// This method is protected because it is only intended for use by
/// subclasses' copy constructors and the like.
- void set_exceptions(bool e) { exceptions_ = e; }
+ void set_exceptions(bool e) const { exceptions_ = e; }
/// \brief Declare NoExceptions to be our friend so it can access
/// our protected functions.
friend class NoExceptions;
private:
- bool exceptions_;
+ mutable bool exceptions_;
};
@@ -109,7 +124,7 @@
/// Takes a reference to an OptionalExceptions derivative,
/// saves that object's current exception state, and disables
/// exceptions.
- NoExceptions(OptionalExceptions& a) :
+ NoExceptions(const OptionalExceptions& a) :
assoc_(a),
exceptions_were_enabled_(a.throw_exceptions())
{
@@ -125,7 +140,7 @@
}
private:
- OptionalExceptions& assoc_;
+ const OptionalExceptions& assoc_;
bool exceptions_were_enabled_;
// Hidden assignment operator and copy ctor, because we should not
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits