MySQL++: noexceptions.h Source File
noexceptions.h
Go to the documentation of this file.
/***********************************************************************
Copyright (c) 2005-2007 by Educational Technology Resources, Inc.
Others may also hold copyrights on code in this file. See the
CREDITS.txt file in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#ifndef MYSQLPP_NOEXCEPTIONS_H
#define MYSQLPP_NOEXCEPTIONS_H
#include "common.h"
namespace mysqlpp {
#if !defined(DOXYGEN_IGNORE)
// Make Doxygen ignore this
class MYSQLPP_EXPORT NoExceptions;
#endif
class MYSQLPP_EXPORT OptionalExceptions
{
public:
OptionalExceptions(bool e = true) :
exceptions_(e)
{
}
virtual ~OptionalExceptions() { }
void enable_exceptions() const { exceptions_ = true; }
void disable_exceptions() const { exceptions_ = false; }
bool throw_exceptions() const { return exceptions_; }
protected:
void set_exceptions(bool e) const { exceptions_ = e; }
friend class NoExceptions;
private:
mutable bool exceptions_;
};
class MYSQLPP_EXPORT NoExceptions
{
public:
NoExceptions(const OptionalExceptions& a) :
assoc_(a),
exceptions_were_enabled_(a.throw_exceptions())
{
assoc_.disable_exceptions();
}
~NoExceptions()
{
assoc_.set_exceptions(exceptions_were_enabled_);
}
private:
const OptionalExceptions& assoc_;
bool exceptions_were_enabled_;
// Hidden assignment operator and copy ctor, because we should not
// be copied.
NoExceptions(const NoExceptions&);
NoExceptions& operator=(const NoExceptions&);
};
} // end namespace mysqlpp
#endif // MYSQLPP_NOEXCEPTIONS_H
mysqlpp::OptionalExceptions::disable_exceptions
void disable_exceptions() const
Disable exceptions from the object.
Definition: noexceptions.h:89
mysqlpp::OptionalExceptions::throw_exceptions
bool throw_exceptions() const
Returns true if exceptions are enabled.
Definition: noexceptions.h:92
mysqlpp::NoExceptions
Disable exceptions in an object derived from OptionalExceptions.
Definition: noexceptions.h:119
mysqlpp::OptionalExceptions::OptionalExceptions
OptionalExceptions(bool e=true)
Default constructor.
Definition: noexceptions.h:77
mysqlpp::OptionalExceptions
Interface allowing a class to have optional exceptions.
Definition: noexceptions.h:71
mysqlpp::NoExceptions::~NoExceptions
~NoExceptions()
Destructor.
Definition: noexceptions.h:137
mysqlpp::OptionalExceptions::~OptionalExceptions
virtual ~OptionalExceptions()
Destroy object.
Definition: noexceptions.h:83
common.h
This file includes top-level definitions for use both internal to the library, and outside it....
mysqlpp::NoExceptions::NoExceptions
NoExceptions(const OptionalExceptions &a)
Constructor.
Definition: noexceptions.h:127
mysqlpp::OptionalExceptions::set_exceptions
void set_exceptions(bool e) const
Sets the exception state to a particular value.
Definition: noexceptions.h:99
mysqlpp::OptionalExceptions::enable_exceptions
void enable_exceptions() const
Enable exceptions from the object.
Definition: noexceptions.h:86