+ Added InitCheck()
+ Added Priority() + Added Sniff() + Replaced ExprList typedef with plain old std::vector<Expr*> so I wouldn't forget what the hell kind of list I was working with. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@607 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,25 +9,32 @@
|
||||
#ifndef _sk_sniffer_rule_h_
|
||||
#define _sk_sniffer_rule_h_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <vector>
|
||||
|
||||
class BPositionIO;
|
||||
|
||||
namespace Sniffer {
|
||||
|
||||
class Expr;
|
||||
typedef std::vector<Expr*> ExprList;
|
||||
|
||||
class Rule {
|
||||
public:
|
||||
Rule();
|
||||
~Rule();
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
double Priority() const;
|
||||
bool Sniff(BPositionIO *data) const;
|
||||
private:
|
||||
friend class Parser;
|
||||
|
||||
void Unset();
|
||||
void SetTo(double priority, ExprList* list);
|
||||
void SetTo(double priority, std::vector<Expr*>* list);
|
||||
|
||||
double fPriority;
|
||||
ExprList *fExprList;
|
||||
std::vector<Expr*> *fExprList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
MIME sniffer rule implementation
|
||||
*/
|
||||
|
||||
#include <sniffer/Expr.h>
|
||||
#include <sniffer/Rule.h>
|
||||
#include <DataIO.h>
|
||||
|
||||
using namespace Sniffer;
|
||||
|
||||
@@ -21,6 +23,31 @@ Rule::~Rule() {
|
||||
Unset();
|
||||
}
|
||||
|
||||
status_t
|
||||
Rule::InitCheck() const {
|
||||
return fExprList ? B_OK : B_NO_INIT;
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
Rule::Priority() const {
|
||||
return fPriority;
|
||||
}
|
||||
|
||||
bool
|
||||
Rule::Sniff(BPositionIO *data) const {
|
||||
if (InitCheck() != B_OK)
|
||||
return false;
|
||||
else {
|
||||
bool result = true;
|
||||
std::vector<Expr*>::const_iterator i;
|
||||
for (i = fExprList->begin(); i != fExprList->end(); i++) {
|
||||
if (*i)
|
||||
result &= (*i)->Sniff(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Rule::Unset() {
|
||||
if (fExprList){
|
||||
@@ -30,7 +57,7 @@ Rule::Unset() {
|
||||
}
|
||||
|
||||
void
|
||||
Rule::SetTo(double priority, ExprList* list) {
|
||||
Rule::SetTo(double priority, std::vector<Expr*>* list) {
|
||||
Unset();
|
||||
fPriority = priority;
|
||||
fExprList = list;
|
||||
|
||||
Reference in New Issue
Block a user