1
0

nde_c.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #pragma once
  2. /* C style API.
  3. We'll eventually deprecate the C++ API as it presents a lot of linking challenges
  4. */
  5. #include "nde_defines.h"
  6. #ifdef _WIN32
  7. #include "NDEString.h"
  8. #include <bfc/platform/types.h>
  9. #endif
  10. #ifdef __APPLE__
  11. #include <CoreFoundation/CoreFoundation.h>
  12. #endif
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #ifdef __APPLE__
  17. typedef time_t __time64_t; // TODO: find a way to do native 64bit time values
  18. #endif
  19. typedef struct nde_database_struct_t { } *nde_database_t;
  20. typedef struct nde_table_struct_t { } *nde_table_t;
  21. typedef struct nde_scanner_t_struct_t { } *nde_scanner_t;
  22. typedef struct nde_field_t_struct_t { } *nde_field_t;
  23. typedef struct nde_filter_struct_t { } *nde_filter_t;
  24. /* Database functions */
  25. // Windows API
  26. #ifdef _WIN32
  27. NDE_API void NDE_Init();
  28. NDE_API void NDE_Quit();
  29. #ifdef __cplusplus
  30. NDE_API nde_database_t NDE_CreateDatabase(HINSTANCE hInstance=0);
  31. #else
  32. NDE_API nde_database_t NDE_CreateDatabase(HINSTANCE hInstance);
  33. #endif
  34. NDE_API void NDE_DestroyDatabase(nde_database_t db);
  35. NDE_API nde_table_t NDE_Database_OpenTable(nde_database_t db, const wchar_t *filename, const wchar_t *filename_index, int create, int cache);
  36. NDE_API void NDE_Database_CloseTable(nde_database_t db, nde_table_t table);
  37. /* Table functions */
  38. NDE_API nde_field_t NDE_Table_NewColumn(nde_table_t table, unsigned char id, const char *name, unsigned char type);
  39. NDE_API void NDE_Table_PostColumns(nde_table_t table);
  40. NDE_API void NDE_Table_AddIndexByID(nde_table_t table, unsigned char id, const char *name);
  41. NDE_API nde_scanner_t NDE_Table_CreateScanner(nde_table_t table);
  42. NDE_API void NDE_Table_DestroyScanner(nde_table_t table, nde_scanner_t scanner);
  43. NDE_API void NDE_Table_Sync(nde_table_t table);
  44. #ifdef __cplusplus
  45. NDE_API void NDE_Table_Compact(nde_table_t table, int *progress=0);
  46. #else
  47. NDE_API void NDE_Table_Compact(nde_table_t table, int *progress);
  48. #endif
  49. NDE_API int NDE_Table_GetRecordsCount(nde_table_t table);
  50. NDE_API nde_field_t NDE_Table_GetColumnByID(nde_table_t table, unsigned char id);
  51. #ifdef _WIN32
  52. NDE_API nde_field_t NDE_Table_GetColumnByName(nde_table_t table, const char *name);
  53. #else
  54. NDE_API nde_field_t NDE_Table_GetColumnByName(nde_table_t table, CFStringRef name);
  55. #endif
  56. NDE_API void NDE_Table_SetColumnSearchableByID(nde_table_t table, unsigned char id, int searchable);
  57. /* Scanner functions */
  58. NDE_API int NDE_Scanner_Query(nde_scanner_t scanner, const wchar_t *query);
  59. NDE_API void NDE_Scanner_Search(nde_scanner_t scanner, const wchar_t *search_term);
  60. NDE_API const wchar_t *NDE_Scanner_GetLastQuery(nde_scanner_t scanner);
  61. NDE_API int NDE_Scanner_GetRecordsCount(nde_scanner_t scanner);
  62. NDE_API void NDE_Scanner_New(nde_scanner_t scanner);
  63. NDE_API void NDE_Scanner_Post(nde_scanner_t scanner);
  64. #ifdef __cplusplus
  65. NDE_API void NDE_Scanner_First(nde_scanner_t scanner, int *killswitch=0);
  66. NDE_API int NDE_Scanner_Next(nde_scanner_t scanner, int *killswitch=0);
  67. #else
  68. NDE_API void NDE_Scanner_First(nde_scanner_t scanner, int *killswitch);
  69. NDE_API int NDE_Scanner_Next(nde_scanner_t scanner, int *killswitch);
  70. #endif
  71. NDE_API void NDE_Scanner_Delete(nde_scanner_t scanner);
  72. NDE_API void NDE_Scanner_Edit(nde_scanner_t scanner);
  73. NDE_API int NDE_Scanner_EOF(nde_scanner_t scanner);
  74. NDE_API int NDE_Scanner_BOF(nde_scanner_t scanner);
  75. NDE_API nde_field_t NDE_Scanner_NewFieldByID(nde_scanner_t scanner, unsigned char id);
  76. NDE_API nde_field_t NDE_Scanner_NewFieldByName(nde_scanner_t scanner, const char *name);
  77. NDE_API nde_field_t NDE_Scanner_GetFieldByID(nde_scanner_t scanner, unsigned char id);
  78. NDE_API nde_field_t NDE_Scanner_GetFieldByName(nde_scanner_t scanner, const char *name);
  79. NDE_API void NDE_Scanner_AddFilterByID(nde_scanner_t scanner, unsigned char id, nde_field_t field, unsigned char filter_operation);
  80. #ifdef __cplusplus
  81. NDE_API int NDE_Scanner_LocateInteger(nde_scanner_t scanner, unsigned char id, int from, int value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  82. NDE_API int NDE_Scanner_LocateString(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  83. NDE_API int NDE_Scanner_LocateNDEString(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  84. NDE_API int NDE_Scanner_LocateFilename(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  85. NDE_API int NDE_Scanner_LocateNDEFilename(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  86. NDE_API int NDE_Scanner_LocateField(nde_scanner_t scanner, unsigned char id, int from, nde_field_t field, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  87. #else
  88. NDE_API int NDE_Scanner_LocateInteger(nde_scanner_t scanner, unsigned char id, int from, int value, int *nskip, int compare_mode);
  89. NDE_API int NDE_Scanner_LocateString(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip, int compare_mode);
  90. NDE_API int NDE_Scanner_LocateNDEString(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip, int compare_mode);
  91. NDE_API int NDE_Scanner_LocateFilename(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip, int compare_mode);
  92. NDE_API int NDE_Scanner_LocateNDEFilename(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip, int compare_mode);
  93. NDE_API int NDE_Scanner_LocateField(nde_scanner_t scanner, unsigned char id, int from, nde_field_t field, int *nskip, int compare_mode);
  94. #endif
  95. NDE_API void NDE_Scanner_DeleteField(nde_scanner_t scanner, nde_field_t field);
  96. NDE_API void NDE_Scanner_RemoveFilters(nde_scanner_t scanner);
  97. /* Filter functions */
  98. NDE_API unsigned char NDE_Filter_GetID(nde_filter_t filter);
  99. NDE_API unsigned char NDE_Filter_GetOp(nde_filter_t filter);
  100. NDE_API nde_field_t NDE_Filter_GetData(nde_filter_t filter);
  101. /* Field functions */
  102. NDE_API unsigned char NDE_Field_GetType(nde_field_t field);
  103. NDE_API unsigned char NDE_Field_GetID(nde_field_t field);
  104. /* String Field functions */
  105. NDE_API wchar_t *NDE_StringField_GetString(nde_field_t field); /* returns non-const because it's an NDE string (reference counted, see ndestring.h) */
  106. NDE_API void NDE_StringField_SetNDEString(nde_field_t field, wchar_t *nde_string);
  107. NDE_API void NDE_StringField_SetString(nde_field_t field, const wchar_t *str);
  108. /* IntegerField functions */
  109. NDE_API void NDE_IntegerField_SetValue(nde_field_t field, int value);
  110. NDE_API int NDE_IntegerField_GetValue(nde_field_t field);
  111. NDE_API nde_field_t NDE_IntegerField_Create(int value); /* mainly used for NDE_Scanner_AddFilterByID */
  112. /* BinaryField functions */
  113. // on windows, the data pointer is optionally reference counted via ndestring (ndestring_retain if you plan on keeping it)
  114. NDE_API void *NDE_BinaryField_GetData(nde_field_t field, size_t *length);
  115. NDE_API void NDE_BinaryField_SetData(nde_field_t field, const void *data, size_t length);
  116. /* Int128Field functions */
  117. NDE_API void NDE_Int128Field_SetValue(nde_field_t field, const void *value);
  118. /* ColumnField functions */
  119. NDE_API const wchar_t *NDE_ColumnField_GetFieldName(nde_field_t field);
  120. NDE_API unsigned char NDE_ColumnField_GetDataType(nde_field_t field);
  121. NDE_API __time64_t NDE_Time_ApplyConversion(__time64_t value, const wchar_t *str, class TimeParse *tp);
  122. #elif defined(__APPLE__) // Mac OS X API, uses CFStringRef for a lot of stuff
  123. NDE_API void NDE_Init();
  124. NDE_API void NDE_Quit();
  125. NDE_API nde_database_t NDE_CreateDatabase();
  126. NDE_API void NDE_DestroyDatabase(nde_database_t db);
  127. NDE_API nde_table_t NDE_Database_OpenTable(nde_database_t db, const char *filename, const char *filename_index, int create, int cache);
  128. NDE_API void NDE_Database_CloseTable(nde_database_t db, nde_table_t table);
  129. /* Table functions */
  130. NDE_API nde_field_t NDE_Table_NewColumn(nde_table_t table, unsigned char id, const char *name, unsigned char type);
  131. NDE_API void NDE_Table_PostColumns(nde_table_t table);
  132. NDE_API void NDE_Table_AddIndexByID(nde_table_t table, unsigned char id, const char *name);
  133. NDE_API nde_scanner_t NDE_Table_CreateScanner(nde_table_t table);
  134. NDE_API void NDE_Table_DestroyScanner(nde_table_t table, nde_scanner_t scanner);
  135. NDE_API void NDE_Table_Sync(nde_table_t table);
  136. #ifdef __cplusplus
  137. NDE_API void NDE_Table_Compact(nde_table_t table, int *progress=0);
  138. #else
  139. NDE_API void NDE_Table_Compact(nde_table_t table, int *progress);
  140. #endif
  141. NDE_API int NDE_Table_GetRecordsCount(nde_table_t table);
  142. NDE_API nde_field_t NDE_Table_GetColumnByID(nde_table_t table, unsigned char id);
  143. #ifdef _WIN32
  144. NDE_API nde_field_t NDE_Table_GetColumnByName(nde_table_t table, const char *name);
  145. #else
  146. NDE_API nde_field_t NDE_Table_GetColumnByName(nde_table_t table, CFStringRef name);
  147. #endif
  148. /* Scanner functions */
  149. NDE_API int NDE_Scanner_Query(nde_scanner_t scanner, const wchar_t *query);
  150. NDE_API CFStringRef NDE_Scanner_GetLastQuery(nde_scanner_t scanner);
  151. NDE_API int NDE_Scanner_GetRecordsCount(nde_scanner_t scanner);
  152. NDE_API void NDE_Scanner_New(nde_scanner_t scanner);
  153. NDE_API void NDE_Scanner_Post(nde_scanner_t scanner);
  154. #ifdef __cplusplus
  155. NDE_API void NDE_Scanner_First(nde_scanner_t scanner, int *killswitch=0);
  156. NDE_API int NDE_Scanner_Next(nde_scanner_t scanner, int *killswitch=0);
  157. #else
  158. NDE_API void NDE_Scanner_First(nde_scanner_t scanner, int *killswitch);
  159. NDE_API int NDE_Scanner_Next(nde_scanner_t scanner, int *killswitch);
  160. #endif
  161. NDE_API void NDE_Scanner_Delete(nde_scanner_t scanner);
  162. NDE_API void NDE_Scanner_Edit(nde_scanner_t scanner);
  163. NDE_API int NDE_Scanner_EOF(nde_scanner_t scanner);
  164. NDE_API int NDE_Scanner_BOF(nde_scanner_t scanner);
  165. NDE_API nde_field_t NDE_Scanner_NewFieldByID(nde_scanner_t scanner, unsigned char id);
  166. NDE_API nde_field_t NDE_Scanner_NewFieldByName(nde_scanner_t scanner, const char *name);
  167. NDE_API nde_field_t NDE_Scanner_GetFieldByID(nde_scanner_t scanner, unsigned char id);
  168. NDE_API nde_field_t NDE_Scanner_GetFieldByName(nde_scanner_t scanner, const char *name);
  169. NDE_API void NDE_Scanner_AddFilterByID(nde_scanner_t scanner, unsigned char id, nde_field_t field, unsigned char filter_operation);
  170. #ifdef __cplusplus
  171. NDE_API int NDE_Scanner_LocateInteger(nde_scanner_t scanner, unsigned char id, int from, int value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  172. NDE_API int NDE_Scanner_LocateString(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  173. NDE_API int NDE_Scanner_LocateNDEString(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  174. NDE_API int NDE_Scanner_LocateFilename(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  175. NDE_API int NDE_Scanner_LocateNDEFilename(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  176. NDE_API int NDE_Scanner_LocateField(nde_scanner_t scanner, unsigned char id, int from, nde_field_t field, int *nskip=0, int compare_mode=COMPARE_MODE_EXACT);
  177. #else
  178. NDE_API int NDE_Scanner_LocateInteger(nde_scanner_t scanner, unsigned char id, int from, int value, int *nskip, int compare_mode);
  179. NDE_API int NDE_Scanner_LocateString(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip, int compare_mode);
  180. NDE_API int NDE_Scanner_LocateNDEString(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip, int compare_mode);
  181. NDE_API int NDE_Scanner_LocateFilename(nde_scanner_t scanner, unsigned char id, int from, const wchar_t *value, int *nskip, int compare_mode);
  182. NDE_API int NDE_Scanner_LocateNDEFilename(nde_scanner_t scanner, unsigned char id, int from, wchar_t *value, int *nskip, int compare_mode);
  183. NDE_API int NDE_Scanner_LocateField(nde_scanner_t scanner, unsigned char id, int from, nde_field_t field, int *nskip, int compare_mode);
  184. #endif
  185. NDE_API void NDE_Scanner_DeleteField(nde_scanner_t scanner, nde_field_t field);
  186. NDE_API void NDE_Scanner_RemoveFilters(nde_scanner_t scanner);
  187. /* Filter functions */
  188. NDE_API unsigned char NDE_Filter_GetID(nde_filter_t filter);
  189. NDE_API unsigned char NDE_Filter_GetOp(nde_filter_t filter);
  190. NDE_API nde_field_t NDE_Filter_GetData(nde_filter_t filter);
  191. /* Field functions */
  192. NDE_API unsigned char NDE_Field_GetType(nde_field_t field);
  193. NDE_API unsigned char NDE_Field_GetID(nde_field_t field);
  194. /* String Field functions */
  195. NDE_API CFStringRef NDE_StringField_GetString(nde_field_t field); /* returns non-const because it's an NDE string (reference counted, see ndestring.h) */
  196. NDE_API void NDE_StringField_SetString(nde_field_t field, CFStringRef string);
  197. /* IntegerField functions */
  198. NDE_API void NDE_IntegerField_SetValue(nde_field_t field, int value);
  199. NDE_API int NDE_IntegerField_GetValue(nde_field_t field);
  200. NDE_API nde_field_t NDE_IntegerField_Create(int value); /* mainly used for NDE_Scanner_AddFilterByID */
  201. /* BinaryField functions */
  202. NDE_API void *NDE_BinaryField_GetData(nde_field_t field, size_t *length);
  203. NDE_API CFDataRef NDE_BinaryField_GetCFData(nde_field_t field);
  204. NDE_API void NDE_BinaryField_SetData(nde_field_t field, const void *data, size_t length);
  205. /* Int128Field functions */
  206. NDE_API void NDE_Int128Field_SetValue(nde_field_t field, const void *value);
  207. /* ColumnField functions */
  208. #ifdef _WIN32
  209. NDE_API const char *NDE_ColumnField_GetFieldName(nde_field_t field);
  210. #else
  211. NDE_API CFStringRef NDE_ColumnField_GetFieldName(nde_field_t field);
  212. #endif
  213. NDE_API unsigned char NDE_ColumnField_GetDataType(nde_field_t field);
  214. NDE_API __time64_t NDE_Time_ApplyConversion(__time64_t value, const wchar_t *str, class TimeParse *tp);
  215. #endif
  216. #ifdef __cplusplus
  217. }
  218. #endif