Added some documentation

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@648 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2002-08-08 07:20:47 +00:00
parent 8795d3cfc9
commit 10db8711a8
11 changed files with 31 additions and 8 deletions

View File

@ -15,6 +15,15 @@
namespace Sniffer { namespace Sniffer {
//! Exception class used by the MIME Sniffer //! Exception class used by the MIME Sniffer
/*! Each exception contains an error message, and an byte offset into
the original rule that generated the error, for the sake of
providing spiffy error messages of the following sort:
<code>
"1.0 ('abc' & 0xFFAAFFAA)"
^ Sniffer pattern error: pattern and mask lengths do not match
</code>
*/
class Err { class Err {
public: public:
Err(const char *msg, const ssize_t pos); Err(const char *msg, const ssize_t pos);
@ -27,13 +36,13 @@ public:
status_t SetTo(const std::string &msg, const ssize_t pos); status_t SetTo(const std::string &msg, const ssize_t pos);
void Unset(); void Unset();
void SetMsg(const char *msg);
void SetPos(ssize_t pos);
const char* Msg() const; const char* Msg() const;
ssize_t Pos() const; ssize_t Pos() const;
private: private:
friend class Parser; // So it can update the pos of its out of mem object
void SetMsg(const char *msg);
void SetPos(ssize_t pos);
char *fMsg; char *fMsg;
ssize_t fPos; ssize_t fPos;
}; };

View File

@ -13,7 +13,7 @@ class BPositionIO;
namespace Sniffer { namespace Sniffer {
//! Abstract class definining an interface for sniffing BFile objects //! Base expression class
class Expr { class Expr {
public: public:
virtual ~Expr() {} virtual ~Expr() {}

View File

@ -19,7 +19,8 @@ namespace Sniffer {
class Err; class Err;
//! Abstract class definining an interface for sniffing BPositionIO objects //! A byte string and optional mask to be compared against a data stream.
/*! The byte string and mask (if supplied) must be of the same length. */
class Pattern { class Pattern {
public: public:
Pattern(const char *string, const char *mask = NULL); Pattern(const char *string, const char *mask = NULL);

View File

@ -20,6 +20,7 @@ namespace Sniffer {
class Err; class Err;
class Pattern; class Pattern;
//! A list of patterns, all of which are to be searched over the same range.
class PatternList : public Expr { class PatternList : public Expr {
public: public:
PatternList(Range range); PatternList(Range range);

View File

@ -18,7 +18,7 @@ namespace Sniffer {
class Err; class Err;
class Pattern; class Pattern;
//! Abstract class definining an interface for sniffing BFile objects //! A Pattern and a Range, bundled into one.
class RPattern { class RPattern {
public: public:
RPattern(Range range, Pattern *pattern); RPattern(Range range, Pattern *pattern);

View File

@ -19,6 +19,7 @@ namespace Sniffer {
class Err; class Err;
class RPattern; class RPattern;
//! A list of patterns, each of which is to be searched over its own specified range.
class RPatternList : public Expr { class RPatternList : public Expr {
public: public:
RPatternList(); RPatternList();

View File

@ -15,6 +15,7 @@ namespace Sniffer {
class Err; class Err;
//! A range of byte offsets from which to check a pattern against a data stream.
class Range { class Range {
public: public:
Range(int32 start, int32 end); Range(int32 start, int32 end);

View File

@ -36,8 +36,6 @@ Pattern::GetErr() const {
return NULL; return NULL;
else else
return new(nothrow) Err(*fErrorMessage); return new(nothrow) Err(*fErrorMessage);
// return fErrorMessage ? NULL : new Err(*fErrorMessage);
// return new Err("HEY, FIX THIS CRAP!", -1);
} }
status_t status_t
@ -66,6 +64,10 @@ Pattern::SetTo(const char *string, const char *mask) {
} }
} }
/*! \brief Looks for a pattern match in the given data stream, starting from
each offset withing the given range. Returns true is a match is found,
false if not.
*/
bool bool
Pattern::Sniff(Range range, BPositionIO *data) const { Pattern::Sniff(Range range, BPositionIO *data) const {
// If our range contains negative values relative to the end of // If our range contains negative values relative to the end of

View File

@ -37,6 +37,9 @@ PatternList::GetErr() const {
return fRange.GetErr(); return fRange.GetErr();
} }
/*! \brief Sniffs the given data stream, searching for a match with
any of the list's patterns.
*/
bool bool
PatternList::Sniff(BPositionIO *data) const { PatternList::Sniff(BPositionIO *data) const {
if (InitCheck() != B_OK) if (InitCheck() != B_OK)

View File

@ -51,6 +51,7 @@ RPattern::~RPattern() {
delete fPattern; delete fPattern;
} }
//! Sniffs the given data stream over the object's range for the object's pattern
bool bool
RPattern::Sniff(BPositionIO *data) const { RPattern::Sniff(BPositionIO *data) const {
if (!data || InitCheck() != B_OK) if (!data || InitCheck() != B_OK)

View File

@ -36,6 +36,10 @@ RPatternList::GetErr() const {
return NULL; return NULL;
} }
/*! Sniffs the given data stream, searching for a match
with any of the list's patterns. Each pattern is searched
over its own specified range.
*/
bool bool
RPatternList::Sniff(BPositionIO *data) const { RPatternList::Sniff(BPositionIO *data) const {
if (InitCheck() != B_OK) if (InitCheck() != B_OK)