added QSE::Exception

This commit is contained in:
hyung-hwan 2015-01-18 13:43:12 +00:00
parent 48536f73c9
commit 36829a55d7
6 changed files with 99 additions and 11 deletions

View File

@ -0,0 +1,88 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_EXCEPTION_CLASS_
#define _QSE_EXCEPTION_CLASS_
#include <qse/types.h>
#include <qse/macros.h>
/////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE)
/////////////////////////////////
class Exception
{
public:
Exception (
const qse_char_t* name, const qse_char_t* msg,
const qse_char_t* file, int line):
name(name), msg(msg)
#if !defined(QSE_NO_LOCATION_IN_EXCEPTION)
, file(file), line(line)
#endif
{
}
const qse_char_t* name;
const qse_char_t* msg;
#if !defined(QSE_NO_LOCATION_IN_EXCEPTION)
const qse_char_t* file;
int line;
#endif
};
#define QSE_THROW(ex_name) \
throw ex_name(QSE_Q(ex_name),QSE_Q(ex_name), QSE_T(__FILE__), __LINE__)
#define QSE_THROW_WITH_MSG(ex_name,msg) \
throw ex_name(QSE_Q(ex_name),msg, QSE_T(__FILE__), __LINE__)
#define QSE_EXCEPTION(ex_name) \
class ex_name: public QSE::Exception \
{ \
public: \
ex_name (const qse_char_t* name, const qse_char_t* msg, \
const qse_char_t* file, int line): \
QSE::Exception (name, msg, file, line) {} \
}
#define QSE_EXCEPTION_NAME(exception_object) ((exception_object).name)
#define QSE_EXCEPTION_MSG(exception_object) ((exception_object).msg)
#if !defined(QSE_NO_LOCATION_IN_EXCEPTION)
# define QSE_EXCEPTION_FILE(exception_object) ((exception_object).file)
# define QSE_EXCEPTION_LINE(exception_object) ((exception_object).line)
#else
# define QSE_EXCEPTION_FILE(exception_object) (QSE_T(""))
# define QSE_EXCEPTION_LINE(exception_object) (0)
#endif
/////////////////////////////////
QSE_END_NAMESPACE(QSE)
/////////////////////////////////
#endif

View File

@ -9,7 +9,7 @@ pkginclude_HEADERS = \
if ENABLE_CXX
pkginclude_HEADERS += \
Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
ScopedPtr.hpp
ScopedPtr.hpp Exception.hpp
endif
install-data-hook:

View File

@ -52,7 +52,7 @@ build_triplet = @build@
host_triplet = @host@
@ENABLE_CXX_TRUE@am__append_1 = \
@ENABLE_CXX_TRUE@ Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
@ENABLE_CXX_TRUE@ ScopedPtr.hpp
@ENABLE_CXX_TRUE@ ScopedPtr.hpp Exception.hpp
subdir = include/qse
DIST_COMMON = $(am__pkginclude_HEADERS_DIST) $(srcdir)/Makefile.am \
@ -95,7 +95,7 @@ am__can_run_installinfo = \
am__pkginclude_HEADERS_DIST = conf-msw.h conf-os2.h conf-dos.h \
conf-vms.h conf-mac.h conf-inf.h types.h macros.h pack1.h \
unpack.h Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \
ScopedPtr.hpp
ScopedPtr.hpp Exception.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \

View File

@ -24,10 +24,11 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_STDMMGR_HPP_
#define _QSE_CMN_STDMMGR_HPP_
#ifndef _QSE_CMN_EXCMMGR_HPP_
#define _QSE_CMN_EXCMMGR_HPP_
#include <qse/cmn/Mmgr.hpp>
#include <qse/Exception.hpp>
/////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE)
@ -45,6 +46,8 @@ public:
void freeMem (void* ptr);
static ExcMmgr* getDFL();
QSE_EXCEPTION (Error);
};
/////////////////////////////////

View File

@ -48,9 +48,6 @@ public:
///
Mmgr* getMmgr () const { return this->mmgr; }
protected:
Mmgr* mmgr;
};

View File

@ -36,14 +36,14 @@ QSE_BEGIN_NAMESPACE(QSE)
void* ExcMmgr::allocMem (qse_size_t n)
{
void* ptr = ::malloc (n);
if (!ptr) throw 1; // TODO: change 1 to a proper exception object
if (!ptr) QSE_THROW (Error);
return ptr;
}
void* ExcMmgr::reallocMem (void* ptr, qse_size_t n)
{
void* xptr = ::realloc (ptr, n);
if (!xptr) throw 1;
if (!xptr) QSE_THROW (Error);
return xptr;
}