mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
Exception classes & required C++11 stuff from GCC(still needs to be fixed)
This commit is contained in:
parent
07979ce2de
commit
7a2be102aa
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
63
common/eqemu_exception.cpp
Normal file
63
common/eqemu_exception.cpp
Normal file
@ -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
|
||||
108
common/eqemu_exception.h
Normal file
108
common/eqemu_exception.h
Normal file
@ -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 <sstream>
|
||||
#include <exception>
|
||||
|
||||
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_; //<! File Line
|
||||
};
|
||||
} // EQEmu
|
||||
|
||||
#ifndef EQ_EXCEPT
|
||||
#define EQ_EXCEPT(n, d) throw EQEmu::Exception(n, d, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user