Files
haiku-beta6/src/kits/storage/sniffer/Err.cpp
T
Tyler Dauwalder 09d84e61b6 + Changed StorageKit namespace to BPrivate::Storage
+ Changed Sniffer namespace to BPrivate::Storage::Sniffer


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@714 a95241bf-73f2-0310-859d-f6bbb57e9c96
2002-08-12 08:42:01 +00:00

98 lines
1.5 KiB
C++

//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
/*!
\file Err.cpp
MIME sniffer Error class implementation
*/
#include <sniffer/Err.h>
#include <new.h>
using namespace BPrivate::Storage::Sniffer;
//------------------------------------------------------------------------------
// Err
//------------------------------------------------------------------------------
Err::Err(const char *msg, const ssize_t pos)
: fMsg(NULL)
, fPos(-1)
{
SetTo(msg, pos);
}
Err::Err(const std::string &msg, const ssize_t pos)
: fMsg(NULL)
, fPos(-1)
{
SetTo(msg, pos);
}
Err::Err(const Err &ref)
: fMsg(NULL)
, fPos(-1)
{
*this = ref;
}
Err::~Err() {
Unset();
}
Err&
Err::operator=(const Err &ref) {
SetTo(ref.Msg(), ref.Pos());
return *this;
}
status_t
Err::SetTo(const char *msg, const ssize_t pos) {
SetMsg(msg);
SetPos(pos);
}
status_t
Err::SetTo(const std::string &msg, const ssize_t pos) {
SetTo(msg.c_str(), pos);
}
void
Err::Unset() {
delete fMsg;
fMsg = NULL;
fPos = -1;
}
const char*
Err::Msg() const {
return fMsg;
}
ssize_t
Err::Pos() const {
return fPos;
}
void
Err::SetMsg(const char *msg) {
if (fMsg) {
delete fMsg;
fMsg = NULL;
}
if (msg) {
fMsg = new(nothrow) char[strlen(msg)+1];
if (fMsg)
strcpy(fMsg, msg);
}
}
void
Err::SetPos(ssize_t pos) {
fPos = pos;
}