refactor: remove XBASE related macros, fixes #8723
This commit is contained in:
@ -44,100 +44,3 @@ protected:
|
||||
private:
|
||||
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"
|
||||
|
||||
//! Generic deskflow exception
|
||||
XBASE_SUBCLASS(XDeskflow, XBase);
|
||||
/**
|
||||
* @brief The XDeskflow class Generic deskflow exception class
|
||||
*/
|
||||
class XDeskflow : public XBase
|
||||
{
|
||||
using XBase::XBase;
|
||||
};
|
||||
|
||||
//! Subscription error
|
||||
/*!
|
||||
Thrown when there is a problem with the subscription.
|
||||
*/
|
||||
XBASE_SUBCLASS(XSubscription, XDeskflow);
|
||||
/**
|
||||
* @brief XSubscription - Thrown when there is a problem with the subscription.
|
||||
*/
|
||||
class XSubscription : public XDeskflow
|
||||
{
|
||||
using XDeskflow::XDeskflow;
|
||||
};
|
||||
|
||||
//! Client error exception
|
||||
/*!
|
||||
Thrown when the client fails to follow the protocol.
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XBadClient, XDeskflow);
|
||||
/**
|
||||
* @brief XBadClient - Thrown when the client fails to follow the protocol.
|
||||
*/
|
||||
class XBadClient : public XDeskflow
|
||||
{
|
||||
using XDeskflow::XDeskflow;
|
||||
|
||||
//! Server protocol error
|
||||
/*!
|
||||
Thrown when the server protocol is unrecognized.
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XInvalidProtocol, XDeskflow);
|
||||
protected:
|
||||
std::string getWhat() const throw() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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
|
||||
/*!
|
||||
|
||||
@ -9,20 +9,35 @@
|
||||
|
||||
#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
|
||||
/*!
|
||||
Thrown when a screen cannot be opened or initialized.
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XScreenOpenFailure, XScreen);
|
||||
/**
|
||||
* @brief XScreenOpenFailure - Thrown when a screen cannot be opened or initialized.
|
||||
*/
|
||||
class XScreenOpenFailure : public XScreen
|
||||
{
|
||||
using XScreen::XScreen;
|
||||
|
||||
//! XInput exception
|
||||
/*!
|
||||
Thrown when an XInput error occurs
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XScreenXInputFailure, XScreen);
|
||||
protected:
|
||||
std::string getWhat() const throw() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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
|
||||
/*!
|
||||
|
||||
@ -9,30 +9,51 @@
|
||||
|
||||
#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
|
||||
/*!
|
||||
Thrown if a stream cannot be closed.
|
||||
*/
|
||||
XBASE_SUBCLASS(XIOClose, XIO);
|
||||
/**
|
||||
* @brief The XIOClose - Thrown if a stream cannot be closed.
|
||||
*/
|
||||
class XIOClose : public XIO
|
||||
{
|
||||
using XIO::XIO;
|
||||
};
|
||||
|
||||
//! I/O already closed exception
|
||||
/*!
|
||||
Thrown when attempting to close or perform I/O on an already closed.
|
||||
stream.
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XIOClosed, XIO);
|
||||
/**
|
||||
* @brief XIOClosed - Thrown when attempting to close or perform I/O on an already closed.
|
||||
*/
|
||||
class XIOClosed : public XIO
|
||||
{
|
||||
using XIO::XIO;
|
||||
|
||||
//! I/O end of stream exception
|
||||
/*!
|
||||
Thrown when attempting to read beyond the end of a stream.
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XIOEndOfStream, XIO);
|
||||
protected:
|
||||
std::string getWhat() const throw() override;
|
||||
};
|
||||
|
||||
//! I/O would block exception
|
||||
/*!
|
||||
Thrown if an operation on a stream would block.
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XIOWouldBlock, XIO);
|
||||
/**
|
||||
* @brief XIOEndOfStream - Thrown when attempting to read beyond the end of a stream.
|
||||
*/
|
||||
class XIOEndOfStream : public 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"
|
||||
|
||||
//! Generic multithreading exception
|
||||
XBASE_SUBCLASS(XMT, XBase);
|
||||
/**
|
||||
* @brief XMT generic multithreading exception
|
||||
*/
|
||||
class XMT : public XBase
|
||||
{
|
||||
using XBase::XBase;
|
||||
};
|
||||
|
||||
//! Thread creation exception
|
||||
/*!
|
||||
Thrown when a thread cannot be created.
|
||||
*/
|
||||
XBASE_SUBCLASS_WHAT(XMTThreadUnavailable, XMT);
|
||||
/**
|
||||
* @brief XMTThreadUnavailable - Thrown when a thread cannot be created.
|
||||
*/
|
||||
class XMTThreadUnavailable : public XMT
|
||||
{
|
||||
using XMT::XMT;
|
||||
|
||||
protected:
|
||||
std::string getWhat() const throw() override;
|
||||
};
|
||||
|
||||
@ -11,8 +11,13 @@
|
||||
#include "common/Common.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
|
||||
/*!
|
||||
@ -56,33 +61,186 @@ private:
|
||||
int m_port;
|
||||
};
|
||||
|
||||
//! I/O closing exception
|
||||
/*!
|
||||
Thrown if a stream cannot be closed.
|
||||
*/
|
||||
XBASE_SUBCLASS_FORMAT(XSocketIOClose, XIOClose);
|
||||
/**
|
||||
* @brief XSocketIOClose - Thrown if a stream cannot be closed.
|
||||
*/
|
||||
class XSocketIOClose : public 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
|
||||
/*!
|
||||
Thrown when a socket cannot be bound to an address.
|
||||
*/
|
||||
XBASE_SUBCLASS_FORMAT(XSocketBind, XSocket);
|
||||
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 XIOClose::what();
|
||||
}
|
||||
}
|
||||
|
||||
//! Socket address in use exception
|
||||
/*!
|
||||
Thrown when a socket cannot be bound to an address because the address
|
||||
is already in use.
|
||||
*/
|
||||
XBASE_SUBCLASS(XSocketAddressInUse, XSocketBind);
|
||||
protected:
|
||||
std::string getWhat() const throw() override;
|
||||
|
||||
//! Cannot connect socket exception
|
||||
/*!
|
||||
Thrown when a socket cannot connect to a remote endpoint.
|
||||
*/
|
||||
XBASE_SUBCLASS_FORMAT(XSocketConnect, XSocket);
|
||||
private:
|
||||
enum EState
|
||||
{
|
||||
kFirst,
|
||||
kFormat,
|
||||
kDone
|
||||
};
|
||||
mutable EState m_state;
|
||||
mutable std::string m_formatted;
|
||||
};
|
||||
|
||||
//! Cannot create socket exception
|
||||
/*!
|
||||
Thrown when a socket cannot be created (by the operating system).
|
||||
*/
|
||||
XBASE_SUBCLASS_FORMAT(XSocketCreate, XSocket);
|
||||
/**
|
||||
* @brief XSocketBind - Thrown when a socket cannot be bound to an address.
|
||||
*/
|
||||
class XSocketBind : public 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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user