Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #include "gnx.h" | ||
|
|
||
| #include <string.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif // __cplusplus | ||
|
|
||
| gnx_bool gnx_insert_row(grn_ctx *ctx, const char *table_name, | ||
| gnx_data_type key_type, const void *key, | ||
| gnx_int *row_id) { | ||
| grn_obj *table = grn_ctx_get(ctx, table_name, strlen(table_name)); | ||
| if (!table) { | ||
| *row_id = GNX_NA_INT; | ||
| return GNX_NA_BOOL; | ||
| } | ||
| // TODO: type check. | ||
| unsigned int key_size = 0; | ||
| switch (key_type) { | ||
| case GNX_NA: { | ||
| key = nullptr; | ||
| break; | ||
| } | ||
| case GNX_INT: { | ||
| key_size = sizeof(gnx_int); | ||
| break; | ||
| } | ||
| case GNX_FLOAT: { | ||
| key_size = sizeof(gnx_float); | ||
| break; | ||
| } | ||
| // case GNX_GEO_POINT: { | ||
| // key_size = sizeof(gnx_geo_point); | ||
| // } | ||
| case GNX_TEXT: { | ||
| gnx_text text = *static_cast<const gnx_text *>(key); | ||
| key = text.data; | ||
| key_size = text.size; | ||
| break; | ||
| } | ||
| default: { | ||
| *row_id = GNX_NA_INT; | ||
| return GNX_NA_BOOL; | ||
| } | ||
| } | ||
| int added; | ||
| grn_id id = grn_table_add(ctx, table, key, key_size, &added); | ||
| if (id == GRN_ID_NIL) { | ||
| *row_id = GNX_NA_INT; | ||
| return GNX_NA_BOOL; | ||
| } | ||
| *row_id = id; | ||
| return added ? GNX_TRUE : GNX_FALSE; | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } // extern "C" | ||
| #endif // __cplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #ifndef GNX_H | ||
| #define GNX_H | ||
|
|
||
| #include <groonga.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif // __cplusplus | ||
|
|
||
| typedef enum gnx_data_type { | ||
| GNX_NA, | ||
| GNX_BOOL, | ||
| GNX_INT, | ||
| GNX_FLOAT, | ||
| GNX_GEO_POINT, | ||
| GNX_TEXT | ||
| } gnx_data_type; | ||
|
|
||
| typedef uint8_t gnx_bool; | ||
| typedef int64_t gnx_int; | ||
| typedef double gnx_float; | ||
| //typedef gnx_geo_point struct { int32_t latitude; int32_t longitude; }; | ||
| typedef struct { | ||
| const char *data; | ||
| gnx_int size; | ||
| } gnx_text; | ||
|
|
||
| #define GNX_TRUE ((gnx_bool)3) | ||
| #define GNX_FALSE ((gnx_bool)0) | ||
|
|
||
| #define GNX_NA_BOOL ((gnx_bool)1) | ||
| #define GNX_NA_INT (((gnx_int)1) << 63) | ||
|
|
||
| gnx_bool gnx_insert_row(grn_ctx *ctx, const char *table_name, | ||
| gnx_data_type key_type, const void *key, | ||
| gnx_int *row_id); | ||
|
|
||
| #ifdef __cplusplus | ||
| } // extern "C" | ||
| #endif // __cplusplus | ||
|
|
||
| #endif // GNX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters