Added InitCheck() and GetErr()

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@606 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-08-06 08:30:44 +00:00
parent c4dc6c7c5a
commit 9d97f52d8d
2 changed files with 30 additions and 7 deletions
+6
View File
@@ -13,9 +13,14 @@
namespace Sniffer {
class Err;
class Range {
public:
Range(int32 start, int32 end);
status_t InitCheck() const;
Err* GetErr() const;
int32 Start() const;
int32 End() const;
@@ -24,6 +29,7 @@ public:
private:
int32 fStart;
int32 fEnd;
status_t fCStatus;
};
}
+24 -7
View File
@@ -7,6 +7,7 @@
MIME sniffer range implementation
*/
#include <sniffer/Err.h>
#include <sniffer/Range.h>
#include <sniffer/Parser.h>
#include <stdio.h>
@@ -16,10 +17,29 @@ using namespace Sniffer;
Range::Range(int32 start, int32 end)
: fStart(-1)
, fEnd(-1)
, fCStatus(B_NO_INIT)
{
SetTo(start, end);
}
status_t
Range::InitCheck() const {
return fCStatus;
}
Err*
Range::GetErr() const {
if (fCStatus == B_OK)
return NULL;
else {
char start_str[32];
char end_str[32];
sprintf(start_str, "%ld", fStart);
sprintf(end_str, "%ld", fEnd);
return new Err(std::string("Sniffer Parser Error -- Invalid range: [") + start_str + ":" + end_str + "]", -1);
}
}
int32
Range::Start() const {
return fStart;
@@ -32,14 +52,11 @@ Range::End() const {
void
Range::SetTo(int32 start, int32 end) {
if (start > end) {
char start_str[32];
char end_str[32];
sprintf(start_str, "%ld", start);
sprintf(end_str, "%ld", end);
throw new Err(std::string("Sniffer Parser Error -- Invalid range: [") + start_str + ":" + end_str + "]", -1);
} else {
fStart = start;
fEnd = end;
if (start > end) {
fCStatus = B_BAD_VALUE;
} else {
fCStatus = B_OK;
}
}