move around exceptions, ProFUSE -> Common

git-svn-id: https://profuse.googlecode.com/svn/branches/v2@388 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
ksherlock 2011-03-14 22:17:49 +00:00
parent ad6fd87c3e
commit 02e3c4c532
14 changed files with 195 additions and 107 deletions

44
Common/Exception.cpp Normal file
View File

@ -0,0 +1,44 @@
#include "Exception.h"
#include <cstdio>
#include <cstring>
Exception::Exception(const char *cp):
_error(0),
_string(cp)
{
}
Exception::Exception(const std::string& string):
_error(0),
_string(string)
{
}
Exception::Exception(const char *cp, int error):
_error(error),
_string(cp)
{
}
Exception::Exception(const std::string& string, int error):
_error(error),
_string(string)
{
}
Exception::~Exception() throw()
{
}
const char *Exception::what()
{
return _string.c_str();
}
const char *Exception::errorString()
{
return "";
}

36
Common/Exception.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef __COMMON_EXCEPTION_H__
#define __COMMON_EXCEPTION_H__
#include <string>
#include <exception>
class Exception : public std::exception
{
public:
Exception(const char *cp);
Exception(const std::string &str);
virtual ~Exception() throw ();
virtual const char *what();
virtual const char *errorString();
int error() const { return _error; }
protected:
Exception(const char *cp, int error);
Exception(const std::string& string, int error);
private:
int _error;
std::string _string;
};
#endif

View File

@ -1,6 +1,5 @@
#include <ProFUSE/Lock.h>
#include "Lock.h"
using namespace ProFUSE;
Lock::Lock()
{

View File

@ -3,7 +3,6 @@
#include <pthread.h>
namespace ProFUSE {
class Lock {
public:
@ -28,6 +27,4 @@ private:
};
}
#endif

View File

@ -3,7 +3,6 @@
#include <cstddef>
namespace ProFUSE {
template <class T>
class auto_array
@ -98,7 +97,6 @@ private:
};
#endif
}
#endif

View File

@ -1,6 +1,6 @@
#ifndef __PROFUSE_SMART_POINTERS_H__
#define __PROFUSE_SMART_POINTERS_H__
#ifndef __COMMON_SMART_POINTERS_H__
#define __COMMON_SMART_POINTERS_H__
#ifdef CPP0X
//C++0x

10
NuFX/Exception.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "Exception.h"
namespace NuFX {
const char *NuFX::Exception::errorString()
{
return ::NuStrError((NuError)error());
}
}

35
NuFX/Exception.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef __NUFX_EXCEPTION_H__
#define __NUFX_EXCEPTION_H__
#include <Common/Exception.h>
#include <NufxLib.h>
namespace NuFX {
class Exception : public ::Exception
{
public:
Exception(const char *cp, NuError error);
Exception(const std::string& string, NuError error);
virtual const char *errorString();
private:
typedef ::Exception super;
};
inline Exception::Exception(const char *cp, NuError error) :
super(cp, error)
{
}
inline Exception::Exception(const std::string& string, NuError error) :
super(string, error)
{
}
}
#endif

13
POSIX/Exception.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "Exception.h"
#include <cstdio>
#include <cstring>
namespace POSIX {
const char *Exception::errorString()
{
return strerror(error());
}
}

34
POSIX/Exception.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef __POSIX_EXCEPTION_H__
#define __POSIX_EXCEPTION_H__
#include <Common/Exception.h>
namespace POSIX {
class Exception : public ::Exception {
public:
Exception(const char *cp, int error);
Exception(const std::string& string, int error);
virtual const char *errorString();
private:
typedef ::Exception super;
};
inline Exception::Exception(const char *cp, int error) :
super(cp, error)
{
}
inline Exception::Exception(const std::string& string, int error) :
super(string, error)
{
}
}
#endif

View File

@ -1,33 +1,14 @@
#include <ProFUSE/Exception.h>
#include "Exception.h"
#include <cstdio>
#include <cstring>
using namespace ProFUSE;
namespace ProDOS {
Exception::~Exception() throw()
{
}
const char *Exception::what()
{
return _string.c_str();
}
const char *Exception::errorString()
{
return "";
}
const char *POSIXException::errorString()
{
return strerror(error());
}
const char *ProDOSException::errorString()
{
switch (error())
{
@ -147,3 +128,5 @@ const char *ProDOSException::errorString()
}
return "";
}
}

View File

@ -1,10 +1,9 @@
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
#ifndef __PRODOS_EXCEPTION_H__
#define __PRODOS_EXCEPTION_H__
#include <string>
#include <exception>
#include <Common/Exception.h>
namespace ProFUSE {
namespace ProDOS {
// ProDOS Errors
@ -67,87 +66,27 @@ enum
resAddErr = 0x71
};
class Exception : public std::exception
{
class Exception : public ::Exception {
public:
Exception(const char *cp);
Exception(const std::string &str);
virtual ~Exception() throw ();
virtual const char *what();
virtual const char *errorString();
int error() const { return _error; }
protected:
Exception(const char *cp, int error);
Exception(const std::string& string, int error);
private:
int _error;
std::string _string;
};
class POSIXException : public Exception {
public:
POSIXException(const char *cp, int error);
POSIXException(const std::string& string, int error);
virtual const char *errorString();
};
class ProDOSException : public Exception {
public:
ProDOSException(const char *cp, int error);
ProDOSException(const std::string& string, int error);
virtual const char *errorString();
private:
typedef ::Exception super;
};
inline Exception::Exception(const char *cp):
_error(0),
_string(cp)
inline Exception::Exception(const char *cp, int error) :
super(cp, error)
{
}
inline Exception::Exception(const std::string& string):
_error(0),
_string(string)
{
}
inline Exception::Exception(const char *cp, int error):
_error(error),
_string(cp)
{
}
inline Exception::Exception(const std::string& string, int error):
_error(error),
_string(string)
{
}
inline POSIXException::POSIXException(const char *cp, int error) :
Exception(cp, error)
{
}
inline POSIXException::POSIXException(const std::string& string, int error) :
Exception(string, error)
{
}
inline ProDOSException::ProDOSException(const char *cp, int error) :
Exception(cp, error)
{
}
inline ProDOSException::ProDOSException(const std::string& string, int error) :
Exception(string, error)
inline Exception::Exception(const std::string& string, int error) :
super(string, error)
{
}
@ -155,4 +94,4 @@ inline ProDOSException::ProDOSException(const std::string& string, int error) :
}
#endif
#endif

BIN
libNuFX.a Normal file

Binary file not shown.