From 7a2be102aa41820ae62a655bbeef85e00f3c7e70 Mon Sep 17 00:00:00 2001 From: KimLS Date: Sun, 17 Feb 2013 11:27:43 -0800 Subject: [PATCH] Exception classes & required C++11 stuff from GCC(still needs to be fixed) --- CMakeLists.txt | 9 +--- common/CMakeLists.txt | 2 + common/eqemu_exception.cpp | 63 ++++++++++++++++++++++ common/eqemu_exception.h | 108 +++++++++++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 common/eqemu_exception.cpp create mode 100644 common/eqemu_exception.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c5bae22a..c4240f68e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,13 +115,8 @@ OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF) IF(UNIX) #Whether to build cleanipc or not (probably a good idea if you build server) - OPTION(EQEMU_BUILD_CLEANIPC "Build cleanipc." ON) - - #Use C++11 stuff, support for this is still it infancy - OPTION(EQEMU_CPP_ELEVEN "Enable C++11 extentions in g++" OFF) - IF(EQEMU_CPP_ELEVEN) - ADD_DEFINITIONS(-std=c++0x) - ENDIF(EQEMU_CPP_ELEVEN) + OPTION(EQEMU_BUILD_CLEANIPC "Build cleanipc." ON) + ADD_DEFINITIONS(-std=c++0x) ENDIF(UNIX) #Various definitions diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 89e78d893..ad01d8038 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -18,6 +18,7 @@ SET(common_sources EmuTCPServer.cpp EQDB.cpp EQDBRes.cpp + eqemu_exception.cpp EQEmuConfig.cpp EQEMuError.cpp EQPacket.cpp @@ -112,6 +113,7 @@ SET(common_headers eq_packet_structs.h EQDB.h EQDBRes.h + eqemu_exception.h EQEmuConfig.h EQEmuConfig_elements.h EQEMuError.h diff --git a/common/eqemu_exception.cpp b/common/eqemu_exception.cpp new file mode 100644 index 000000000..8d6a7c7a3 --- /dev/null +++ b/common/eqemu_exception.cpp @@ -0,0 +1,63 @@ +/* EQEmu: Everquest Server Emulator + Copyright (C) 2001-2013 EQEmu Development Team (http://www.eqemulator.net) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "eqemu_exception.h" + +namespace EQEmu +{ + Exception::Exception(const char* name, const std::string& description, const char* file, long line) + : line_(line), + file_(file), + desc_(description), + name_(name) + { + } + + Exception::Exception(const Exception& e) + : line_(e.line_), + file_(e.file_), + desc_(e.desc_), + name_(e.name_) + { + } + + Exception::Exception(const Exception&& e) + : line_(e.line_), + file_(e.file_), + desc_(e.desc_), + name_(e.name_) + { + } + + void Exception::operator=(const Exception& e) { + line_ = e.line_; + file_ = e.file_; + desc_ = e.desc_; + name_ = e.name_; + } + + const std::string& Exception::full_description() const { + if(full_desc_.empty()) { + std::stringstream ss; + ss << "EQEmu Exception (" << name_ << ") in " << file_; + ss << " at line (" << line_ << "): " << desc_; + full_desc_ = ss.str(); + } + return full_desc_; + } +} // EQEmu diff --git a/common/eqemu_exception.h b/common/eqemu_exception.h new file mode 100644 index 000000000..7c14645c7 --- /dev/null +++ b/common/eqemu_exception.h @@ -0,0 +1,108 @@ +/* EQEMu: Everquest Server Emulator + Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _EQEMU_EQEMUEXCEPTION_H +#define _EQEMU_EQEMUEXCEPTION_H + +#include +#include + +namespace EQEmu +{ + //! EQEmu Exception Class + /*! + A custom exception class for things EQEmu throws. + */ + class Exception : public std::exception { + public: + + //! Detailed Constructor + /*! + \param name The name given for this exception. + \param description The description for this exception. + \param file The file name for this exception. + \param line The line number for this exception. + */ + Exception(const char* name, const std::string& description, const char* file, long line); + + //! Copy Constructor + Exception(const Exception& e); + + //! Move Constructor + Exception(const Exception&& e); + + //! Destructor + ~Exception() throw() { } + + //! Assignment Operator + void operator=(const Exception& e); + + //! Get Name + /*! + Gets the name of the exception as it was when it was created. + These are typically descriptive categories that the exception would fall under. + */ + virtual const std::string& name() const { return name_; } + + //! Get Basic Description + /*! + Gets the description of the exception as it was when it was created. + This tends to explain the circumstances of why the exception was thrown. + */ + virtual const std::string& description() const { return desc_; } + + //! Get Full Description + /*! + Gets a full description for this exception. + This is a string containing the name, description, file and line number in a custom format. + This string is created the first time the full_description is accessed. + */ + virtual const std::string& full_description() const; + + //! Get File Name + /*! + Gets the name of the file this exception was thrown from. + */ + virtual const std::string& file() const { return file_; } + + //! Get File Line + /*! + Gets the file line this exception was thrown from. + */ + virtual const long& line() const { return line_; } + + //! std::exception overload + /*! + Overload from std::exception + Allows it to be caught as a std::exception without casting which is nice, returns the full description. + */ + const char* what() const throw() { return full_description().c_str(); } + protected: + std::string name_; //!< Exception name + std::string desc_; //!< Exception Description + mutable std::string full_desc_; //!< Full Exception Description + std::string file_; //!< File Name + long line_; //