Scanner.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Scanner Class Prototypes
  8. --------------------------------------------------------------------------- */
  9. #ifndef __SCANNER_H
  10. #define __SCANNER_H
  11. #include <vector>
  12. #include "record.h"
  13. #include "Table.h"
  14. #include "index.h"
  15. #include <vector>
  16. #include <set>
  17. #ifdef __APPLE__
  18. #include <CoreFoundation/CoreFoundation.h>
  19. #endif
  20. class Table;
  21. class Index;
  22. #pragma warning( disable: 4251 )
  23. class Scanner;
  24. class Record;
  25. class Scanner : public LinkedListEntry
  26. {
  27. public:
  28. Record *GetRecord(int Idx);
  29. Scanner(Table *parentTable);
  30. void IndexModified(void);
  31. Index *GetIndex() { return index; }
  32. Index *index; // TODO: make protected
  33. protected:
  34. ~Scanner();
  35. Table *pTable;
  36. BOOL iModified;
  37. typedef std::vector<StringField *> SearchStrings;
  38. SearchStrings search_strings;
  39. typedef std::set<unsigned char> SearchFields;
  40. SearchFields search_fields;
  41. bool search_any;
  42. void GetCurrentRecord(void);
  43. bool MatchFilters(void);
  44. bool MatchSearches();
  45. bool MatchSearch(const SearchFields &fields, StringField *search_field);
  46. //BOOL MatchJoins(void);
  47. int CheckFilters(void);
  48. void CacheLastLocate(int Id, int From, Field *field, Index *i, int j);
  49. static int Query_LookupToken(const wchar_t *token);
  50. void Query_CleanUp(void);
  51. void Query_SyntaxError(int c);
  52. public:
  53. static int Query_GetNextToken(const wchar_t *p, int *size, wchar_t **token, int tokentable=0);
  54. static const wchar_t *Query_EatSpace(const wchar_t *p);
  55. static wchar_t *Query_ProbeSpace(wchar_t *p);
  56. static const wchar_t *Query_ProbeNonAlphaNum(const wchar_t *p);
  57. static wchar_t *Query_ProbeAlphaNum(wchar_t *p);
  58. static int Query_isControlChar(wchar_t p);
  59. BOOL Query(const wchar_t *query);
  60. BOOL Query_Parse(const wchar_t *query);
  61. const wchar_t *GetLastQuery();
  62. public://fucko: protected
  63. LinkedList pstack;
  64. wchar_t *token;
  65. wchar_t *last_query;
  66. int last_query_failed;
  67. protected:
  68. Record *CurrentRecord;
  69. int CurrentRecordIdx;
  70. LinkedList FilterList;
  71. Index *lastLocateIndex;
  72. int lastLocateIdx;
  73. Field *lastLocateFieldClone;
  74. int lastLocateFrom;
  75. int lastLocateId;
  76. BOOL Edition;
  77. int ResultPtr;
  78. BOOL FiltersOK;
  79. public:
  80. bool MatchFilter(Filter *filter);
  81. typedef bool (*FilterWalker)(Scanner *scanner, Filter *filter, void *context);
  82. void WalkFilters(FilterWalker walker, void *context);
  83. ColumnField *GetColumnByName(const wchar_t *FieldName);
  84. ColumnField *GetColumnById(unsigned char id);
  85. Field *NewFieldByName(const wchar_t *fieldName, unsigned char Perm);
  86. Field *NewFieldByType(unsigned char Type, unsigned char Id, unsigned char Perm);
  87. Field *NewFieldById(unsigned char Id, unsigned char Perm);
  88. void DeleteField(Field *field);
  89. void DeleteFieldByName(const wchar_t *name);
  90. void DeleteFieldById(unsigned char Id);
  91. void Cancel(void);
  92. void Insert(void);
  93. void Edit(void);
  94. void Post(void);
  95. void Delete(void);
  96. Field *GetFieldByName(const wchar_t *FieldName);
  97. Field *GetFieldById(unsigned char Id);
  98. void First(int *killswitch=0);
  99. void Last(int *killswitch=0);
  100. int Next(int *killswitch=0);
  101. int Previous(int *killswitch=0);
  102. BOOL Eof(void);
  103. BOOL Bof(void);
  104. void New(void);
  105. int GetRecordsCount(void);
  106. void GetRecordById(int Id, BOOL checkFilters=TRUE);
  107. int GetRecordId(void);
  108. void Sync(void);
  109. BOOL LocateByName(const wchar_t *column, int From, Field *field, int *nskip=NULL);
  110. BOOL LocateById(int Id, int From, Field *field, int *nskip=NULL);
  111. BOOL LocateByIdEx(int Id, int From, Field *field, int *nskip, int comp_mode);
  112. // Filters
  113. int AddFilterByName(const wchar_t *name, Field *Data, unsigned char Op);
  114. int AddFilterById(unsigned char Id, Field *Data, unsigned char Op);
  115. int AddFilterOp(unsigned char Op);
  116. void RemoveFilters(void);
  117. Filter *GetLastFilter(void);
  118. BOOL SetWorkingIndexByName(const wchar_t *desc);
  119. BOOL SetWorkingIndexById(unsigned char Id);
  120. void Search(const wchar_t *search_string);
  121. BOOL HasIndexChanged(void) { return iModified; }
  122. void ClearDirtyBit(void);
  123. float FragmentationLevel(void);
  124. void WalkFields(Record::FieldsWalker callback, void *context);
  125. Table *GetTable();
  126. int in_query_parser;
  127. int disable_date_resolution;
  128. };
  129. #endif