Aligned Query.h/cpp with the BFS (Haiku) versions r20186. Updated Stack.h
to <util/Stack.h>. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20187 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,27 +1,23 @@
|
|||||||
/* Query - query parsing and evaluation
|
/* Query - query parsing and evaluation
|
||||||
**
|
*
|
||||||
** Initial version by Axel Dörfler, [email protected]
|
* The pattern matching is roughly based on code originally written
|
||||||
** The pattern matching is roughly based on code originally written
|
* by J. Kercheval, and on code written by Kenneth Almquist, though
|
||||||
** by J. Kercheval, and on code written by Kenneth Almquist, though
|
* it shares no code.
|
||||||
** it shares no code.
|
*
|
||||||
**
|
* Copyright 2001-2006, Axel Dörfler, [email protected].
|
||||||
** This file may be used under the terms of the OpenBeOS License.
|
* This file may be used under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Adjusted by Ingo Weinhold <[email protected]> for usage in RAM FS.
|
// Adjusted by Ingo Weinhold <[email protected]> for usage in RAM FS.
|
||||||
|
|
||||||
|
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
//#include "bfs.h"
|
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
#include "Directory.h"
|
#include "Directory.h"
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
#include "Stack.h"
|
|
||||||
#include "Volume.h"
|
#include "Volume.h"
|
||||||
//#include "Inode.h"
|
|
||||||
//#include "BPlusTree.h"
|
|
||||||
#include "Index.h"
|
#include "Index.h"
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
@@ -34,12 +30,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// IndexWrapper
|
// IndexWrapper
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@@ -1196,15 +1186,7 @@ Equation::GetNextMatching(Volume *volume, IndexIterator *iterator,
|
|||||||
// TODO: Check the buffer size.
|
// TODO: Check the buffer size.
|
||||||
strncpy(dirent->d_name, entry->GetName(), B_FILE_NAME_LENGTH);
|
strncpy(dirent->d_name, entry->GetName(), B_FILE_NAME_LENGTH);
|
||||||
dirent->d_name[B_FILE_NAME_LENGTH - 1] = '\0';
|
dirent->d_name[B_FILE_NAME_LENGTH - 1] = '\0';
|
||||||
|
|
||||||
#ifdef KEEP_WRONG_DIRENT_RECLEN
|
|
||||||
// ToDo: The available file systems in BeOS apparently don't set the
|
|
||||||
// correct d_reclen - we are copying that behaviour if requested, but
|
|
||||||
// if it doesn't break compatibility, we will remove it.
|
|
||||||
dirent->d_reclen = strlen(dirent->d_name);
|
|
||||||
#else
|
|
||||||
dirent->d_reclen = sizeof(struct dirent) + strlen(dirent->d_name);
|
dirent->d_reclen = sizeof(struct dirent) + strlen(dirent->d_name);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == MATCH_OK)
|
if (status == MATCH_OK)
|
||||||
@@ -1559,6 +1541,33 @@ Query::Query(Volume *volume, Expression *expression, uint32 flags)
|
|||||||
fExpression->Root()->CalculateScore(fIndex);
|
fExpression->Root()->CalculateScore(fIndex);
|
||||||
fIndex.Unset();
|
fIndex.Unset();
|
||||||
|
|
||||||
|
Rewind();
|
||||||
|
|
||||||
|
if (fFlags & B_LIVE_QUERY)
|
||||||
|
volume->AddQuery(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Query::~Query()
|
||||||
|
{
|
||||||
|
if (fFlags & B_LIVE_QUERY)
|
||||||
|
fVolume->RemoveQuery(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Query::Rewind()
|
||||||
|
{
|
||||||
|
// free previous stuff
|
||||||
|
|
||||||
|
fStack.MakeEmpty();
|
||||||
|
|
||||||
|
delete fIterator;
|
||||||
|
fIterator = NULL;
|
||||||
|
fCurrent = NULL;
|
||||||
|
|
||||||
|
// put the whole expression on the stack
|
||||||
|
|
||||||
Stack<Term *> stack;
|
Stack<Term *> stack;
|
||||||
stack.Push(fExpression->Root());
|
stack.Push(fExpression->Root());
|
||||||
|
|
||||||
@@ -1581,15 +1590,7 @@ Query::Query(Volume *volume, Expression *expression, uint32 flags)
|
|||||||
FATAL(("Unknown term on stack or stack error"));
|
FATAL(("Unknown term on stack or stack error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fFlags & B_LIVE_QUERY)
|
return B_OK;
|
||||||
volume->AddQuery(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Query::~Query()
|
|
||||||
{
|
|
||||||
if (fFlags & B_LIVE_QUERY)
|
|
||||||
fVolume->RemoveQuery(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1648,6 +1649,7 @@ Query::LiveUpdate(Entry *entry, const char *attribute, int32 type, const uint8 *
|
|||||||
|
|
||||||
status_t oldStatus = fExpression->Root()->Match(entry, attribute, type, oldKey, oldLength);
|
status_t oldStatus = fExpression->Root()->Match(entry, attribute, type, oldKey, oldLength);
|
||||||
status_t newStatus = fExpression->Root()->Match(entry, attribute, type, newKey, newLength);
|
status_t newStatus = fExpression->Root()->Match(entry, attribute, type, newKey, newLength);
|
||||||
|
|
||||||
int32 op;
|
int32 op;
|
||||||
if (oldStatus == MATCH_OK && newStatus == MATCH_OK) {
|
if (oldStatus == MATCH_OK && newStatus == MATCH_OK) {
|
||||||
// only send out a notification if the name was changed
|
// only send out a notification if the name was changed
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
|
/* Query - query parsing and evaluation
|
||||||
|
*
|
||||||
|
* Copyright 2001-2004, Axel Dörfler, [email protected].
|
||||||
|
* This file may be used under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Adjusted by Ingo Weinhold <[email protected]> for usage in RAM FS.
|
||||||
|
*/
|
||||||
#ifndef QUERY_H
|
#ifndef QUERY_H
|
||||||
#define QUERY_H
|
#define QUERY_H
|
||||||
/* Query - query parsing and evaluation
|
|
||||||
**
|
|
||||||
** Initial version by Axel Dörfler, [email protected]
|
|
||||||
** This file may be used under the terms of the OpenBeOS License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Adjusted by Ingo Weinhold <[email protected]> for usage in RAM FS.
|
|
||||||
|
|
||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
#include "Index.h"
|
#include "Index.h"
|
||||||
#include "Stack.h"
|
#include "Stack.h"
|
||||||
//#include "Chain.h"
|
|
||||||
#include "ramfs.h"
|
#include "ramfs.h"
|
||||||
|
|
||||||
class Entry;
|
class Entry;
|
||||||
@@ -25,9 +24,6 @@ class Term;
|
|||||||
class Volume;
|
class Volume;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define B_QUERY_NON_INDEXED 0x00000002
|
#define B_QUERY_NON_INDEXED 0x00000002
|
||||||
|
|
||||||
|
|
||||||
@@ -69,11 +65,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Expression {
|
class Expression {
|
||||||
public:
|
public:
|
||||||
Expression(char *expr);
|
Expression(char *expr);
|
||||||
@@ -104,10 +95,12 @@ class Query {
|
|||||||
Query(Volume *volume, Expression *expression, uint32 flags);
|
Query(Volume *volume, Expression *expression, uint32 flags);
|
||||||
~Query();
|
~Query();
|
||||||
|
|
||||||
status_t GetNextEntry(struct dirent *,size_t size);
|
status_t Rewind();
|
||||||
|
status_t GetNextEntry(struct dirent *, size_t size);
|
||||||
|
|
||||||
void SetLiveMode(port_id port,int32 token);
|
void SetLiveMode(port_id port, int32 token);
|
||||||
void LiveUpdate(Entry *entry,const char *attribute,int32 type,const uint8 *oldKey,size_t oldLength,const uint8 *newKey,size_t newLength);
|
void LiveUpdate(Entry *entry, const char *attribute, int32 type,
|
||||||
|
const uint8 *oldKey, size_t oldLength, const uint8 *newKey, size_t newLength);
|
||||||
|
|
||||||
Expression *GetExpression() const { return fExpression; }
|
Expression *GetExpression() const { return fExpression; }
|
||||||
|
|
||||||
@@ -122,10 +115,6 @@ class Query {
|
|||||||
uint32 fFlags;
|
uint32 fFlags;
|
||||||
port_id fPort;
|
port_id fPort;
|
||||||
int32 fToken;
|
int32 fToken;
|
||||||
|
|
||||||
private:
|
|
||||||
// friend Chain<Query>;
|
|
||||||
// Query *fNext;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* QUERY_H */
|
#endif /* QUERY_H */
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef STACK_H
|
/* Stack - a template stack class (plus some handy methods)
|
||||||
#define STACK_H
|
*
|
||||||
/* Stack - a template stack class
|
* Copyright 2001-2005, Axel Dörfler, [email protected].
|
||||||
**
|
* This file may be used under the terms of the MIT License.
|
||||||
** Copyright 2001 pinc Software. All Rights Reserved.
|
*/
|
||||||
** This file may be used under the terms of the OpenBeOS License.
|
#ifndef KERNEL_UTIL_STACK_H
|
||||||
*/
|
#define KERNEL_UTIL_STACK_H
|
||||||
|
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
@@ -19,18 +19,28 @@ template<class T> class Stack {
|
|||||||
fMax(0)
|
fMax(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~Stack()
|
~Stack()
|
||||||
{
|
{
|
||||||
if (fArray)
|
free(fArray);
|
||||||
free(fArray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsEmpty() const
|
||||||
|
{
|
||||||
|
return fUsed == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MakeEmpty()
|
||||||
|
{
|
||||||
|
// could also free the memory
|
||||||
|
fUsed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
status_t Push(T value)
|
status_t Push(T value)
|
||||||
{
|
{
|
||||||
if (fUsed >= fMax) {
|
if (fUsed >= fMax) {
|
||||||
fMax += 16;
|
fMax += 16;
|
||||||
T *newArray = (T *)realloc(fArray,fMax * sizeof(T));
|
T *newArray = (T *)realloc(fArray, fMax * sizeof(T));
|
||||||
if (newArray == NULL)
|
if (newArray == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -39,7 +49,7 @@ template<class T> class Stack {
|
|||||||
fArray[fUsed++] = value;
|
fArray[fUsed++] = value;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Pop(T *value)
|
bool Pop(T *value)
|
||||||
{
|
{
|
||||||
if (fUsed == 0)
|
if (fUsed == 0)
|
||||||
@@ -48,11 +58,21 @@ template<class T> class Stack {
|
|||||||
*value = fArray[--fUsed];
|
*value = fArray[--fUsed];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T *Array()
|
||||||
|
{
|
||||||
|
return fArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 CountItems() const
|
||||||
|
{
|
||||||
|
return fUsed;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T *fArray;
|
T *fArray;
|
||||||
int32 fUsed;
|
int32 fUsed;
|
||||||
int32 fMax;
|
int32 fMax;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* STACK_H */
|
#endif /* KERNEL_UTIL_STACK_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user