refactor: remove XBASE related macros, fixes #8723
This commit is contained in:
parent
7116ddac86
commit
958e14cb13
6 changed files with 308 additions and 184 deletions
|
|
@ -44,100 +44,3 @@ protected:
|
||||||
private:
|
private:
|
||||||
mutable std::string m_what;
|
mutable std::string m_what;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
|
||||||
\def XBASE_SUBCLASS
|
|
||||||
Convenience macro to subclass from XBase (or a subclass of it),
|
|
||||||
providing the c'tor taking a const std::string&. getWhat() is not
|
|
||||||
declared.
|
|
||||||
*/
|
|
||||||
#define XBASE_SUBCLASS(name_, super_) \
|
|
||||||
class name_ : public super_ \
|
|
||||||
{ \
|
|
||||||
public: \
|
|
||||||
name_() : super_() \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
name_(const std::string &msg) : super_(msg) \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
virtual ~name_() throw() \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\def XBASE_SUBCLASS
|
|
||||||
Convenience macro to subclass from XBase (or a subclass of it),
|
|
||||||
providing the c'tor taking a const std::string&. getWhat() must be
|
|
||||||
implemented.
|
|
||||||
*/
|
|
||||||
#define XBASE_SUBCLASS_WHAT(name_, super_) \
|
|
||||||
class name_ : public super_ \
|
|
||||||
{ \
|
|
||||||
public: \
|
|
||||||
name_() : super_() \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
name_(const std::string &msg) : super_(msg) \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
virtual ~name_() throw() \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
protected: \
|
|
||||||
virtual std::string getWhat() const throw(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\def XBASE_SUBCLASS_FORMAT
|
|
||||||
Convenience macro to subclass from XBase (or a subclass of it),
|
|
||||||
providing the c'tor taking a const std::string&. what() is overridden
|
|
||||||
to call getWhat() when first called; getWhat() can format the
|
|
||||||
error message and can call what() to get the message passed to the
|
|
||||||
c'tor.
|
|
||||||
*/
|
|
||||||
#define XBASE_SUBCLASS_FORMAT(name_, super_) \
|
|
||||||
class name_ : public super_ \
|
|
||||||
{ \
|
|
||||||
private: \
|
|
||||||
enum EState \
|
|
||||||
{ \
|
|
||||||
kFirst, \
|
|
||||||
kFormat, \
|
|
||||||
kDone \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
public: \
|
|
||||||
name_() : super_(), m_state(kDone) \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
name_(const std::string &msg) : super_(msg), m_state(kFirst) \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
virtual ~name_() throw() \
|
|
||||||
{ \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
virtual const char *what() const throw() \
|
|
||||||
{ \
|
|
||||||
if (m_state == kFirst) { \
|
|
||||||
m_state = kFormat; \
|
|
||||||
m_formatted = getWhat(); \
|
|
||||||
m_state = kDone; \
|
|
||||||
} \
|
|
||||||
if (m_state == kDone) { \
|
|
||||||
return m_formatted.c_str(); \
|
|
||||||
} else { \
|
|
||||||
return super_::what(); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
protected: \
|
|
||||||
virtual std::string getWhat() const throw(); \
|
|
||||||
\
|
|
||||||
private: \
|
|
||||||
mutable EState m_state; \
|
|
||||||
mutable std::string m_formatted; \
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -9,26 +9,43 @@
|
||||||
|
|
||||||
#include "base/XBase.h"
|
#include "base/XBase.h"
|
||||||
|
|
||||||
//! Generic deskflow exception
|
/**
|
||||||
XBASE_SUBCLASS(XDeskflow, XBase);
|
* @brief The XDeskflow class Generic deskflow exception class
|
||||||
|
*/
|
||||||
|
class XDeskflow : public XBase
|
||||||
|
{
|
||||||
|
using XBase::XBase;
|
||||||
|
};
|
||||||
|
|
||||||
//! Subscription error
|
/**
|
||||||
/*!
|
* @brief XSubscription - Thrown when there is a problem with the subscription.
|
||||||
Thrown when there is a problem with the subscription.
|
*/
|
||||||
*/
|
class XSubscription : public XDeskflow
|
||||||
XBASE_SUBCLASS(XSubscription, XDeskflow);
|
{
|
||||||
|
using XDeskflow::XDeskflow;
|
||||||
|
};
|
||||||
|
|
||||||
//! Client error exception
|
/**
|
||||||
/*!
|
* @brief XBadClient - Thrown when the client fails to follow the protocol.
|
||||||
Thrown when the client fails to follow the protocol.
|
*/
|
||||||
*/
|
class XBadClient : public XDeskflow
|
||||||
XBASE_SUBCLASS_WHAT(XBadClient, XDeskflow);
|
{
|
||||||
|
using XDeskflow::XDeskflow;
|
||||||
|
|
||||||
//! Server protocol error
|
protected:
|
||||||
/*!
|
std::string getWhat() const throw() override;
|
||||||
Thrown when the server protocol is unrecognized.
|
};
|
||||||
*/
|
|
||||||
XBASE_SUBCLASS_WHAT(XInvalidProtocol, XDeskflow);
|
/**
|
||||||
|
* @brief XInvalidProtocol - Thrown when the server protocol is unreconized.
|
||||||
|
*/
|
||||||
|
class XInvalidProtocol : public XDeskflow
|
||||||
|
{
|
||||||
|
using XDeskflow::XDeskflow;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
};
|
||||||
|
|
||||||
//! Incompatible client exception
|
//! Incompatible client exception
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,35 @@
|
||||||
|
|
||||||
#include "base/XBase.h"
|
#include "base/XBase.h"
|
||||||
|
|
||||||
//! Generic screen exception
|
/**
|
||||||
XBASE_SUBCLASS(XScreen, XBase);
|
* @brief The XScreen class, generic screen exception
|
||||||
|
*/
|
||||||
|
class XScreen : public XBase
|
||||||
|
{
|
||||||
|
using XBase::XBase;
|
||||||
|
};
|
||||||
|
|
||||||
//! Cannot open screen exception
|
/**
|
||||||
/*!
|
* @brief XScreenOpenFailure - Thrown when a screen cannot be opened or initialized.
|
||||||
Thrown when a screen cannot be opened or initialized.
|
*/
|
||||||
*/
|
class XScreenOpenFailure : public XScreen
|
||||||
XBASE_SUBCLASS_WHAT(XScreenOpenFailure, XScreen);
|
{
|
||||||
|
using XScreen::XScreen;
|
||||||
|
|
||||||
//! XInput exception
|
protected:
|
||||||
/*!
|
std::string getWhat() const throw() override;
|
||||||
Thrown when an XInput error occurs
|
};
|
||||||
*/
|
|
||||||
XBASE_SUBCLASS_WHAT(XScreenXInputFailure, XScreen);
|
/**
|
||||||
|
* @brief XScreenXInputFailure - Thrown when an XInput error occurs
|
||||||
|
*/
|
||||||
|
class XScreenXInputFailure : public XScreen
|
||||||
|
{
|
||||||
|
using XScreen::XScreen;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
};
|
||||||
|
|
||||||
//! Screen unavailable exception
|
//! Screen unavailable exception
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -9,30 +9,51 @@
|
||||||
|
|
||||||
#include "base/XBase.h"
|
#include "base/XBase.h"
|
||||||
|
|
||||||
//! Generic I/O exception
|
/**
|
||||||
XBASE_SUBCLASS(XIO, XBase);
|
* @brief The XIO class Generic i/o exception class
|
||||||
|
*/
|
||||||
|
class XIO : public XBase
|
||||||
|
{
|
||||||
|
using XBase::XBase;
|
||||||
|
};
|
||||||
|
|
||||||
//! I/O closing exception
|
/**
|
||||||
/*!
|
* @brief The XIOClose - Thrown if a stream cannot be closed.
|
||||||
Thrown if a stream cannot be closed.
|
*/
|
||||||
*/
|
class XIOClose : public XIO
|
||||||
XBASE_SUBCLASS(XIOClose, XIO);
|
{
|
||||||
|
using XIO::XIO;
|
||||||
|
};
|
||||||
|
|
||||||
//! I/O already closed exception
|
/**
|
||||||
/*!
|
* @brief XIOClosed - Thrown when attempting to close or perform I/O on an already closed.
|
||||||
Thrown when attempting to close or perform I/O on an already closed.
|
*/
|
||||||
stream.
|
class XIOClosed : public XIO
|
||||||
*/
|
{
|
||||||
XBASE_SUBCLASS_WHAT(XIOClosed, XIO);
|
using XIO::XIO;
|
||||||
|
|
||||||
//! I/O end of stream exception
|
protected:
|
||||||
/*!
|
std::string getWhat() const throw() override;
|
||||||
Thrown when attempting to read beyond the end of a stream.
|
};
|
||||||
*/
|
|
||||||
XBASE_SUBCLASS_WHAT(XIOEndOfStream, XIO);
|
|
||||||
|
|
||||||
//! I/O would block exception
|
/**
|
||||||
/*!
|
* @brief XIOEndOfStream - Thrown when attempting to read beyond the end of a stream.
|
||||||
Thrown if an operation on a stream would block.
|
*/
|
||||||
*/
|
class XIOEndOfStream : public XIO
|
||||||
XBASE_SUBCLASS_WHAT(XIOWouldBlock, XIO);
|
{
|
||||||
|
using XIO::XIO;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief XIOWouldBlock - Thrown if an operation on a stream would block.
|
||||||
|
*/
|
||||||
|
class XIOWouldBlock : public XIO
|
||||||
|
{
|
||||||
|
using XIO::XIO;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,21 @@
|
||||||
|
|
||||||
#include "base/XBase.h"
|
#include "base/XBase.h"
|
||||||
|
|
||||||
//! Generic multithreading exception
|
/**
|
||||||
XBASE_SUBCLASS(XMT, XBase);
|
* @brief XMT generic multithreading exception
|
||||||
|
*/
|
||||||
|
class XMT : public XBase
|
||||||
|
{
|
||||||
|
using XBase::XBase;
|
||||||
|
};
|
||||||
|
|
||||||
//! Thread creation exception
|
/**
|
||||||
/*!
|
* @brief XMTThreadUnavailable - Thrown when a thread cannot be created.
|
||||||
Thrown when a thread cannot be created.
|
*/
|
||||||
*/
|
class XMTThreadUnavailable : public XMT
|
||||||
XBASE_SUBCLASS_WHAT(XMTThreadUnavailable, XMT);
|
{
|
||||||
|
using XMT::XMT;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,13 @@
|
||||||
#include "common/Common.h"
|
#include "common/Common.h"
|
||||||
#include "io/XIO.h"
|
#include "io/XIO.h"
|
||||||
|
|
||||||
//! Generic socket exception
|
/**
|
||||||
XBASE_SUBCLASS(XSocket, XBase);
|
* @brief XSocket generic socket exception
|
||||||
|
*/
|
||||||
|
class XSocket : public XBase
|
||||||
|
{
|
||||||
|
using XBase::XBase;
|
||||||
|
};
|
||||||
|
|
||||||
//! Socket bad address exception
|
//! Socket bad address exception
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -56,33 +61,186 @@ private:
|
||||||
int m_port;
|
int m_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! I/O closing exception
|
/**
|
||||||
/*!
|
* @brief XSocketIOClose - Thrown if a stream cannot be closed.
|
||||||
Thrown if a stream cannot be closed.
|
*/
|
||||||
*/
|
class XSocketIOClose : public XIOClose
|
||||||
XBASE_SUBCLASS_FORMAT(XSocketIOClose, XIOClose);
|
{
|
||||||
|
public:
|
||||||
|
XSocketIOClose() : XIOClose(), m_state(kDone)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
explicit XSocketIOClose(const std::string &msg) : XIOClose(msg), m_state(kFirst)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
~XSocketIOClose() throw() override = default;
|
||||||
|
|
||||||
//! Socket cannot bind address exception
|
const char *what() const throw() override
|
||||||
/*!
|
{
|
||||||
Thrown when a socket cannot be bound to an address.
|
if (m_state == kFirst) {
|
||||||
*/
|
m_state = kFormat;
|
||||||
XBASE_SUBCLASS_FORMAT(XSocketBind, XSocket);
|
m_formatted = getWhat();
|
||||||
|
m_state = kDone;
|
||||||
|
}
|
||||||
|
if (m_state == kDone) {
|
||||||
|
return m_formatted.c_str();
|
||||||
|
} else {
|
||||||
|
return XIOClose::what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//! Socket address in use exception
|
protected:
|
||||||
/*!
|
std::string getWhat() const throw() override;
|
||||||
Thrown when a socket cannot be bound to an address because the address
|
|
||||||
is already in use.
|
|
||||||
*/
|
|
||||||
XBASE_SUBCLASS(XSocketAddressInUse, XSocketBind);
|
|
||||||
|
|
||||||
//! Cannot connect socket exception
|
private:
|
||||||
/*!
|
enum EState
|
||||||
Thrown when a socket cannot connect to a remote endpoint.
|
{
|
||||||
*/
|
kFirst,
|
||||||
XBASE_SUBCLASS_FORMAT(XSocketConnect, XSocket);
|
kFormat,
|
||||||
|
kDone
|
||||||
|
};
|
||||||
|
mutable EState m_state;
|
||||||
|
mutable std::string m_formatted;
|
||||||
|
};
|
||||||
|
|
||||||
//! Cannot create socket exception
|
/**
|
||||||
/*!
|
* @brief XSocketBind - Thrown when a socket cannot be bound to an address.
|
||||||
Thrown when a socket cannot be created (by the operating system).
|
*/
|
||||||
*/
|
class XSocketBind : public XSocket
|
||||||
XBASE_SUBCLASS_FORMAT(XSocketCreate, XSocket);
|
{
|
||||||
|
public:
|
||||||
|
XSocketBind() : XSocket(), m_state(kDone)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
explicit XSocketBind(const std::string &msg) : XSocket(msg), m_state(kFirst)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
~XSocketBind() throw() override = default;
|
||||||
|
|
||||||
|
const char *what() const throw() override
|
||||||
|
{
|
||||||
|
if (m_state == kFirst) {
|
||||||
|
m_state = kFormat;
|
||||||
|
m_formatted = getWhat();
|
||||||
|
m_state = kDone;
|
||||||
|
}
|
||||||
|
if (m_state == kDone) {
|
||||||
|
return m_formatted.c_str();
|
||||||
|
} else {
|
||||||
|
return XSocket::what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum EState
|
||||||
|
{
|
||||||
|
kFirst,
|
||||||
|
kFormat,
|
||||||
|
kDone
|
||||||
|
};
|
||||||
|
mutable EState m_state;
|
||||||
|
mutable std::string m_formatted;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief XSocketAddressInUse
|
||||||
|
* Thrown when a socket cannot be bound to an address because the address is already in use.
|
||||||
|
*/
|
||||||
|
class XSocketAddressInUse : public XSocketBind
|
||||||
|
{
|
||||||
|
using XSocketBind::XSocketBind;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief XSocketConnect - Thrown when a socket cannot connect to a remote endpoint.
|
||||||
|
*/
|
||||||
|
class XSocketConnect : public XSocket
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
XSocketConnect() : XSocket(), m_state(kDone)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
explicit XSocketConnect(const std::string &msg) : XSocket(msg), m_state(kFirst)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
~XSocketConnect() throw() override = default;
|
||||||
|
|
||||||
|
const char *what() const throw() override
|
||||||
|
{
|
||||||
|
if (m_state == kFirst) {
|
||||||
|
m_state = kFormat;
|
||||||
|
m_formatted = getWhat();
|
||||||
|
m_state = kDone;
|
||||||
|
}
|
||||||
|
if (m_state == kDone) {
|
||||||
|
return m_formatted.c_str();
|
||||||
|
} else {
|
||||||
|
return XSocket::what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum EState
|
||||||
|
{
|
||||||
|
kFirst,
|
||||||
|
kFormat,
|
||||||
|
kDone
|
||||||
|
};
|
||||||
|
mutable EState m_state;
|
||||||
|
mutable std::string m_formatted;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief XSocketConnect - Thrown when a socket cannot be created (by the operating system).
|
||||||
|
*/
|
||||||
|
class XSocketCreate : public XSocket
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
XSocketCreate() : XSocket(), m_state(kDone)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
explicit XSocketCreate(const std::string &msg) : XSocket(msg), m_state(kFirst)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
~XSocketCreate() throw() override = default;
|
||||||
|
|
||||||
|
const char *what() const throw() override
|
||||||
|
{
|
||||||
|
if (m_state == kFirst) {
|
||||||
|
m_state = kFormat;
|
||||||
|
m_formatted = getWhat();
|
||||||
|
m_state = kDone;
|
||||||
|
}
|
||||||
|
if (m_state == kDone) {
|
||||||
|
return m_formatted.c_str();
|
||||||
|
} else {
|
||||||
|
return XSocket::what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getWhat() const throw() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum EState
|
||||||
|
{
|
||||||
|
kFirst,
|
||||||
|
kFormat,
|
||||||
|
kDone
|
||||||
|
};
|
||||||
|
mutable EState m_state;
|
||||||
|
mutable std::string m_formatted;
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue