2010-02-27 17:13:34 -07:00
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2010-02-27 17:13:34 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
|
|
|
#include "Pragma.h"
|
2010-02-27 17:13:34 -07:00
|
|
|
#include <string>
|
2010-02-27 19:34:54 -07:00
|
|
|
#include <sstream>
|
2010-02-27 17:13:34 -07:00
|
|
|
#include <exception>
|
|
|
|
|
|
|
|
namespace DFHack
|
|
|
|
{
|
|
|
|
namespace Error
|
|
|
|
{
|
2010-09-01 10:03:52 -06:00
|
|
|
/*
|
|
|
|
* our wrapper for the C++ exception. used to differentiate
|
|
|
|
* the whole array of DFHack exceptions from the rest
|
|
|
|
*/
|
2016-07-11 17:54:03 -06:00
|
|
|
#ifdef _MSC_VER
|
2016-06-28 07:34:11 -06:00
|
|
|
#pragma push
|
|
|
|
/**
|
2016-07-11 17:54:03 -06:00
|
|
|
* C4275 is - The warning officially is non dll-interface class 'std::exception' used as base for
|
|
|
|
* dll-interface class
|
2016-06-28 07:34:11 -06:00
|
|
|
*
|
|
|
|
* Basically, its saying that you might have an ABI problem if you mismatch compilers. We don't
|
|
|
|
* care since we build all of DFhack at once against whatever Toady is using
|
|
|
|
*/
|
2016-07-11 17:54:03 -06:00
|
|
|
#pragma warning(disable: 4275)
|
2016-06-28 08:39:46 -06:00
|
|
|
#endif
|
2016-06-28 07:34:11 -06:00
|
|
|
class DFHACK_EXPORT All : public std::exception{};
|
2016-07-11 17:54:03 -06:00
|
|
|
#ifdef _MSC_VER
|
2016-06-28 08:39:46 -06:00
|
|
|
#pragma pop
|
2016-06-28 07:34:11 -06:00
|
|
|
#endif
|
2012-04-05 09:55:59 -06:00
|
|
|
class DFHACK_EXPORT NullPointer : public All {
|
|
|
|
const char *varname_;
|
|
|
|
public:
|
|
|
|
NullPointer(const char *varname_ = NULL) : varname_(varname_) {}
|
|
|
|
const char *varname() const { return varname_; }
|
|
|
|
virtual const char *what() const throw();
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CHECK_NULL_POINTER(var) \
|
|
|
|
{ if (var == NULL) throw DFHack::Error::NullPointer(#var); }
|
|
|
|
|
2012-04-29 11:07:39 -06:00
|
|
|
class DFHACK_EXPORT InvalidArgument : public All {
|
|
|
|
const char *expr_;
|
|
|
|
public:
|
|
|
|
InvalidArgument(const char *expr_ = NULL) : expr_(expr_) {}
|
|
|
|
const char *expr() const { return expr_; }
|
|
|
|
virtual const char *what() const throw();
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CHECK_INVALID_ARGUMENT(expr) \
|
|
|
|
{ if (!(expr)) throw DFHack::Error::InvalidArgument(#expr); }
|
|
|
|
|
2017-12-25 18:13:15 -07:00
|
|
|
class DFHACK_EXPORT VTableMissing : public All {
|
|
|
|
const char *name_;
|
|
|
|
public:
|
|
|
|
VTableMissing(const char *name_ = NULL) : name_(name_) {}
|
|
|
|
const char *name() const { return name_; }
|
|
|
|
virtual const char *what() const throw();
|
|
|
|
};
|
|
|
|
|
2012-04-29 11:07:39 -06:00
|
|
|
|
2012-03-24 05:13:51 -06:00
|
|
|
class DFHACK_EXPORT AllSymbols : public All{};
|
2010-11-07 16:10:59 -07:00
|
|
|
// Syntax errors and whatnot, the xml can't be read
|
2012-03-24 05:13:51 -06:00
|
|
|
class DFHACK_EXPORT SymbolsXmlParse : public AllSymbols
|
2010-02-28 13:44:14 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-03-24 05:13:51 -06:00
|
|
|
SymbolsXmlParse(const char* _desc, int _id, int _row, int _col)
|
2010-04-23 10:51:54 -06:00
|
|
|
:desc(_desc), id(_id), row(_row), col(_col)
|
|
|
|
{
|
|
|
|
std::stringstream s;
|
|
|
|
s << "error " << id << ": " << desc << ", at row " << row << " col " << col;
|
|
|
|
full = s.str();
|
|
|
|
}
|
|
|
|
std::string full;
|
2010-02-28 13:44:14 -07:00
|
|
|
const std::string desc;
|
|
|
|
const int id;
|
|
|
|
const int row;
|
|
|
|
const int col;
|
2012-03-24 05:13:51 -06:00
|
|
|
virtual ~SymbolsXmlParse() throw(){};
|
2010-02-28 13:44:14 -07:00
|
|
|
virtual const char* what() const throw()
|
|
|
|
{
|
2010-04-23 10:51:54 -06:00
|
|
|
return full.c_str();
|
2010-02-28 13:44:14 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-24 05:13:51 -06:00
|
|
|
class DFHACK_EXPORT SymbolsXmlBadAttribute : public All
|
2010-02-28 13:44:14 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-03-24 05:13:51 -06:00
|
|
|
SymbolsXmlBadAttribute(const char* _attr) : attr(_attr)
|
2010-04-23 10:51:54 -06:00
|
|
|
{
|
|
|
|
std::stringstream s;
|
|
|
|
s << "attribute is either missing or invalid: " << attr;
|
|
|
|
full = s.str();
|
|
|
|
}
|
|
|
|
std::string full;
|
2010-02-28 13:44:14 -07:00
|
|
|
std::string attr;
|
2012-03-24 05:13:51 -06:00
|
|
|
virtual ~SymbolsXmlBadAttribute() throw(){};
|
2010-02-28 13:44:14 -07:00
|
|
|
virtual const char* what() const throw()
|
|
|
|
{
|
2010-04-23 10:51:54 -06:00
|
|
|
return full.c_str();
|
2010-02-28 13:44:14 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-24 05:13:51 -06:00
|
|
|
class DFHACK_EXPORT SymbolsXmlNoRoot : public All
|
2010-02-28 13:44:14 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-03-24 05:13:51 -06:00
|
|
|
SymbolsXmlNoRoot() {}
|
|
|
|
virtual ~SymbolsXmlNoRoot() throw(){};
|
2010-02-28 13:44:14 -07:00
|
|
|
virtual const char* what() const throw()
|
|
|
|
{
|
2012-03-24 05:13:51 -06:00
|
|
|
return "Symbol file is missing root element.";
|
2010-02-28 13:44:14 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-24 05:13:51 -06:00
|
|
|
class DFHACK_EXPORT SymbolsXmlUnderspecifiedEntry : public All
|
2010-02-28 13:44:14 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-03-24 05:13:51 -06:00
|
|
|
SymbolsXmlUnderspecifiedEntry(const char * _where) : where(_where)
|
2010-04-23 10:51:54 -06:00
|
|
|
{
|
|
|
|
std::stringstream s;
|
2012-03-24 05:13:51 -06:00
|
|
|
s << "Underspecified symbol file entry, each entry needs to set both the name attribute and have a value. parent: " << where;
|
2010-04-23 10:51:54 -06:00
|
|
|
full = s.str();
|
|
|
|
}
|
2012-03-24 05:13:51 -06:00
|
|
|
virtual ~SymbolsXmlUnderspecifiedEntry() throw(){};
|
2010-03-06 13:21:01 -07:00
|
|
|
std::string where;
|
2010-04-23 10:51:54 -06:00
|
|
|
std::string full;
|
2010-02-28 13:44:14 -07:00
|
|
|
virtual const char* what() const throw()
|
|
|
|
{
|
2010-04-23 10:51:54 -06:00
|
|
|
return full.c_str();
|
2010-02-28 13:44:14 -07:00
|
|
|
}
|
|
|
|
};
|
2010-02-27 17:13:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|