#include <DataIO.h>
#include <stdio.h>
#include "Err.h"
#include "RPattern.h"
#include "RPatternList.h"
using namespace BPrivate::Storage::Sniffer;
RPatternList::RPatternList()
:
DisjList()
{
}
RPatternList::~RPatternList()
{
std::vector<RPattern*>::iterator i;
for (i = fList.begin(); i != fList.end(); i++)
delete *i;
}
status_t
RPatternList::InitCheck() const
{
return B_OK;
}
Err*
RPatternList::GetErr() const
{
return NULL;
}
bool
RPatternList::Sniff(const Data& data) const
{
if (InitCheck() != B_OK) {
return false;
} else {
bool result = false;
std::vector<RPattern*>::const_iterator i;
for (i = fList.begin(); i != fList.end(); i++) {
if (*i)
result |= (*i)->Sniff(data, fCaseInsensitive);
}
return result;
}
}
ssize_t
RPatternList::BytesNeeded() const
{
ssize_t result = InitCheck();
if (result == B_OK) {
result = 0;
std::vector<RPattern*>::const_iterator i;
for (i = fList.begin(); i != fList.end(); i++) {
if (*i) {
ssize_t bytes = (*i)->BytesNeeded();
if (bytes >= 0) {
if (bytes > result)
result = bytes;
} else {
result = bytes;
break;
}
}
}
}
return result;
}
void
RPatternList::Add(RPattern* rpattern)
{
if (rpattern)
fList.push_back(rpattern);
}