+ 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_
|
#ifndef _sk_sniffer_rule_h_
|
||||||
#define _sk_sniffer_rule_h_
|
#define _sk_sniffer_rule_h_
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class BPositionIO;
|
||||||
|
|
||||||
namespace Sniffer {
|
namespace Sniffer {
|
||||||
|
|
||||||
class Expr;
|
class Expr;
|
||||||
typedef std::vector<Expr*> ExprList;
|
|
||||||
|
|
||||||
class Rule {
|
class Rule {
|
||||||
public:
|
public:
|
||||||
Rule();
|
Rule();
|
||||||
~Rule();
|
~Rule();
|
||||||
|
|
||||||
|
status_t InitCheck() const;
|
||||||
|
|
||||||
|
double Priority() const;
|
||||||
|
bool Sniff(BPositionIO *data) const;
|
||||||
private:
|
private:
|
||||||
friend class Parser;
|
friend class Parser;
|
||||||
|
|
||||||
void Unset();
|
void Unset();
|
||||||
void SetTo(double priority, ExprList* list);
|
void SetTo(double priority, std::vector<Expr*>* list);
|
||||||
|
|
||||||
double fPriority;
|
double fPriority;
|
||||||
ExprList *fExprList;
|
std::vector<Expr*> *fExprList;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
MIME sniffer rule implementation
|
MIME sniffer rule implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sniffer/Expr.h>
|
||||||
#include <sniffer/Rule.h>
|
#include <sniffer/Rule.h>
|
||||||
|
#include <DataIO.h>
|
||||||
|
|
||||||
using namespace Sniffer;
|
using namespace Sniffer;
|
||||||
|
|
||||||
@@ -21,6 +23,31 @@ Rule::~Rule() {
|
|||||||
Unset();
|
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
|
void
|
||||||
Rule::Unset() {
|
Rule::Unset() {
|
||||||
if (fExprList){
|
if (fExprList){
|
||||||
@@ -30,7 +57,7 @@ Rule::Unset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Rule::SetTo(double priority, ExprList* list) {
|
Rule::SetTo(double priority, std::vector<Expr*>* list) {
|
||||||
Unset();
|
Unset();
|
||||||
fPriority = priority;
|
fPriority = priority;
|
||||||
fExprList = list;
|
fExprList = list;
|
||||||
|
|||||||
Reference in New Issue
Block a user