barrier/lib/base/XBase.h

85 lines
2.0 KiB
C
Raw Normal View History

2002-08-02 23:57:46 +04:00
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
2001-10-06 18:13:28 +04:00
#ifndef XBASE_H
#define XBASE_H
#include "CString.h"
#include "stdpre.h"
2001-10-06 18:13:28 +04:00
#include <exception>
#include "stdpost.h"
2001-10-06 18:13:28 +04:00
//! Exception base class
/*!
This is the base class of most exception types.
*/
class XBase /*: public std::exception*/ {
2002-04-29 18:40:01 +04:00
public:
//! Use getWhat() as the result of what()
2001-10-06 18:13:28 +04:00
XBase();
//! Use \c msg as the result of what()
2001-10-06 18:13:28 +04:00
XBase(const CString& msg);
virtual ~XBase();
// std::exception overrides
virtual const char* what() const;
2002-04-29 18:40:01 +04:00
protected:
//! Get a human readable string describing the exception
2001-10-06 18:13:28 +04:00
virtual CString getWhat() const throw() = 0;
//! Format a string
/*!
Looks up a message format using \c id, using \c defaultFormat if
no format can be found, then replaces positional parameters in
the format string and returns the result.
*/
2001-10-06 18:13:28 +04:00
virtual CString format(const char* id,
const char* defaultFormat, ...) const throw();
2001-10-06 18:13:28 +04:00
2002-04-29 18:40:01 +04:00
private:
2001-10-06 18:13:28 +04:00
mutable CString m_what;
};
//! Mix-in for handling \c errno
/*!
This mix-in class for exception classes provides storage and query of
\c errno. On Windows, it uses GetLastError() instead of errno.
*/
2001-10-06 18:13:28 +04:00
class MXErrno {
2002-04-29 18:40:01 +04:00
public:
//! Save \c errno as the error code
2001-10-06 18:13:28 +04:00
MXErrno();
//! Save \c err as the error code
MXErrno(int err);
virtual ~MXErrno();
2001-10-06 18:13:28 +04:00
//! @name accessors
//@{
2001-10-06 18:13:28 +04:00
//! Get the error code
2001-10-06 18:13:28 +04:00
int getErrno() const;
//! Get the human readable string for the error code
virtual const char* getErrstr() const;
2001-10-06 18:13:28 +04:00
//@}
2002-04-29 18:40:01 +04:00
private:
2001-10-06 18:13:28 +04:00
int m_errno;
mutable char* m_string;
2001-10-06 18:13:28 +04:00
};
#endif