Scanner.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 "record.h"
  12. #include "Table.h"
  13. #include "index.h"
  14. #include "../nu/Vector.h"
  15. #include "../nu/ValueSet.h"
  16. #ifdef __APPLE__
  17. #include <CoreFoundation/CoreFoundation.h>
  18. #endif
  19. class Table;
  20. class Index;
  21. #pragma warning( disable: 4251 )
  22. class Scanner;
  23. class Record;
  24. class Scanner : public LinkedListEntry
  25. {
  26. public:
  27. Record *GetRecord(int Idx);
  28. Scanner(Table *parentTable);
  29. void IndexModified(void);
  30. Index *GetIndex() { return index; }
  31. Index *index; // TODO: make protected
  32. protected:
  33. ~Scanner();
  34. Table *pTable;
  35. BOOL iModified;
  36. typedef Vector<StringField *> SearchStrings;
  37. SearchStrings search_strings;
  38. typedef ValueSet<unsigned char> SearchFields;
  39. SearchFields search_fields;
  40. bool search_any;
  41. void GetCurrentRecord(void);
  42. bool MatchFilters(void);
  43. bool MatchSearches();
  44. bool MatchSearch(const SearchFields &fields, StringField *search_field);
  45. //BOOL MatchJoins(void);
  46. int CheckFilters(void);
  47. void CacheLastLocate(int Id, int From, Field *field, Index *i, int j);
  48. #ifdef _WIN32
  49. static int Query_LookupToken(const wchar_t *token);
  50. #else
  51. static int Query_LookupToken(CFStringRef token);
  52. #endif
  53. void Query_CleanUp(void);
  54. void Query_SyntaxError(int c);
  55. public:
  56. #ifdef _WIN32
  57. static int Query_GetNextToken(const wchar_t *p, int *size, wchar_t **token, int tokentable=0);
  58. static const wchar_t *Query_EatSpace(const wchar_t *p);
  59. static wchar_t *Query_ProbeSpace(wchar_t *p);
  60. static const wchar_t *Query_ProbeNonAlphaNum(const wchar_t *p);
  61. static wchar_t *Query_ProbeAlphaNum(wchar_t *p);
  62. static int Query_isControlChar(wchar_t p);
  63. BOOL Query(const wchar_t *query);
  64. BOOL Query_Parse(const wchar_t *query);
  65. #else
  66. static int Query_GetNextToken(const char *p, size_t *size, CFStringRef *token, int tokentable=0);
  67. static const char *Query_EatSpace(const char *p);
  68. static char *Query_ProbeSpace(char *p);
  69. static const char *Query_ProbeNonAlphaNum(const char *p);
  70. static char *Query_ProbeAlphaNum(char *p);
  71. static int Query_isControlChar(char p);
  72. BOOL Query(const char *query);
  73. BOOL Query_Parse(const char *query);
  74. #endif
  75. #ifdef _WIN32
  76. const wchar_t *GetLastQuery();
  77. #elif defined(__APPLE__)
  78. CFStringRef GetLastQuery();
  79. #endif
  80. public://fucko: protected
  81. //String token;
  82. LinkedList pstack;
  83. #ifdef _WIN32
  84. wchar_t *token;
  85. #else
  86. CFStringRef token;
  87. #endif
  88. #ifdef _WIN32
  89. wchar_t *last_query;
  90. #elif defined(__APPLE__)
  91. CFStringRef last_query;
  92. #endif
  93. int last_query_failed;
  94. protected:
  95. Record *CurrentRecord;
  96. int CurrentRecordIdx;
  97. LinkedList FilterList;
  98. Index *lastLocateIndex;
  99. int lastLocateIdx;
  100. Field *lastLocateFieldClone;
  101. int lastLocateFrom;
  102. int lastLocateId;
  103. BOOL Edition;
  104. int ResultPtr;
  105. BOOL FiltersOK;
  106. public:
  107. bool MatchFilter(Filter *filter);
  108. typedef bool (*FilterWalker)(Scanner *scanner, Filter *filter, void *context);
  109. void WalkFilters(FilterWalker walker, void *context);
  110. #ifdef _WIN32
  111. ColumnField *GetColumnByName(const wchar_t *FieldName);
  112. #else
  113. ColumnField *GetColumnByName(CFStringRef FieldName);
  114. #endif
  115. ColumnField *GetColumnById(unsigned char id);
  116. #ifdef _WIN32
  117. Field *NewFieldByName(const wchar_t *fieldName, unsigned char Perm);
  118. #else
  119. Field *NewFieldByName(CFStringRef fieldName, unsigned char Perm);
  120. #endif
  121. Field *NewFieldById(unsigned char Id, unsigned char Perm);
  122. void DeleteField(Field *field);
  123. #ifdef _WIN32
  124. void DeleteFieldByName(const wchar_t *name);
  125. #else
  126. void DeleteFieldByName(CFStringRef name);
  127. #endif
  128. void DeleteFieldById(unsigned char Id);
  129. void Cancel(void);
  130. void Insert(void);
  131. void Edit(void);
  132. void Post(void);
  133. void Delete(void);
  134. #ifdef _WIN32
  135. Field *GetFieldByName(const wchar_t *FieldName);
  136. #else
  137. Field *GetFieldByName(CFStringRef FieldName);
  138. #endif
  139. Field *GetFieldById(unsigned char Id);
  140. void First(int *killswitch=0);
  141. void Last(int *killswitch=0);
  142. int Next(int *killswitch=0);
  143. int Previous(int *killswitch=0);
  144. BOOL Eof(void);
  145. BOOL Bof(void);
  146. void New(void);
  147. int GetRecordsCount(void);
  148. void GetRecordById(int Id, BOOL checkFilters=TRUE);
  149. int GetRecordId(void);
  150. void Sync(void);
  151. #ifdef _WIN32
  152. BOOL LocateByName(const wchar_t *column, int From, Field *field, int *nskip=NULL);
  153. #else
  154. BOOL LocateByName(CFStringRef column, int From, Field *field, int *nskip=NULL);
  155. #endif
  156. BOOL LocateById(int Id, int From, Field *field, int *nskip=NULL);
  157. BOOL LocateByIdEx(int Id, int From, Field *field, int *nskip, int comp_mode);
  158. // Filters
  159. #ifdef _WIN32
  160. int AddFilterByName(const wchar_t *name, Field *Data, unsigned char Op);
  161. #else
  162. int AddFilterByName(CFStringRef name, Field *Data, unsigned char Op);
  163. #endif
  164. int AddFilterById(unsigned char Id, Field *Data, unsigned char Op);
  165. int AddFilterOp(unsigned char Op);
  166. void RemoveFilters(void);
  167. Filter *GetLastFilter(void);
  168. #ifdef _WIN32
  169. BOOL SetWorkingIndexByName(const wchar_t *desc);
  170. #else
  171. BOOL SetWorkingIndexByName(CFStringRef desc);
  172. #endif
  173. BOOL SetWorkingIndexById(unsigned char Id);
  174. #ifdef _WIN32
  175. void Search(const wchar_t *search_string);
  176. #endif
  177. BOOL HasIndexChanged(void) { return iModified; }
  178. void ClearDirtyBit(void);
  179. float FragmentationLevel(void);
  180. Table *GetTable();
  181. int in_query_parser;
  182. int disable_date_resolution;
  183. };
  184. #endif