mongory 0.7.3-aarch64-linux-musl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mongory might be problematic. Click here for more details.

Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +88 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG.md +364 -0
  6. data/CODE_OF_CONDUCT.md +84 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +488 -0
  9. data/Rakefile +107 -0
  10. data/SUBMODULE_INTEGRATION.md +325 -0
  11. data/docs/advanced_usage.md +40 -0
  12. data/docs/clang_bridge.md +69 -0
  13. data/docs/field_names.md +30 -0
  14. data/docs/migration.md +30 -0
  15. data/docs/performance.md +61 -0
  16. data/examples/README.md +41 -0
  17. data/examples/benchmark-rails.rb +52 -0
  18. data/examples/benchmark.rb +184 -0
  19. data/ext/mongory_ext/extconf.rb +91 -0
  20. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +122 -0
  21. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +161 -0
  22. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +79 -0
  23. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +95 -0
  24. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +127 -0
  25. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +175 -0
  26. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +76 -0
  27. data/ext/mongory_ext/mongory-core/include/mongory-core.h +12 -0
  28. data/ext/mongory_ext/mongory-core/src/foundations/array.c +287 -0
  29. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +19 -0
  30. data/ext/mongory_ext/mongory-core/src/foundations/config.c +270 -0
  31. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +48 -0
  32. data/ext/mongory_ext/mongory-core/src/foundations/error.c +38 -0
  33. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +298 -0
  34. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +65 -0
  35. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +49 -0
  36. data/ext/mongory_ext/mongory-core/src/foundations/table.c +498 -0
  37. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +210 -0
  38. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +70 -0
  39. data/ext/mongory_ext/mongory-core/src/foundations/value.c +500 -0
  40. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +164 -0
  41. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.h +47 -0
  42. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +122 -0
  43. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +100 -0
  44. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +217 -0
  45. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +83 -0
  46. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +573 -0
  47. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +125 -0
  48. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +147 -0
  49. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.h +48 -0
  50. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +124 -0
  51. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +46 -0
  52. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +126 -0
  53. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +46 -0
  54. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +314 -0
  55. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.h +97 -0
  56. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +252 -0
  57. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +79 -0
  58. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +23 -0
  59. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +60 -0
  60. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +23 -0
  61. data/ext/mongory_ext/mongory_ext.c +683 -0
  62. data/lib/generators/mongory/install/install_generator.rb +42 -0
  63. data/lib/generators/mongory/install/templates/initializer.rb.erb +83 -0
  64. data/lib/generators/mongory/matcher/matcher_generator.rb +56 -0
  65. data/lib/generators/mongory/matcher/templates/matcher.rb.erb +92 -0
  66. data/lib/generators/mongory/matcher/templates/matcher_spec.rb.erb +17 -0
  67. data/lib/mongory/c_query_builder.rb +44 -0
  68. data/lib/mongory/converters/abstract_converter.rb +111 -0
  69. data/lib/mongory/converters/condition_converter.rb +64 -0
  70. data/lib/mongory/converters/converted.rb +81 -0
  71. data/lib/mongory/converters/data_converter.rb +37 -0
  72. data/lib/mongory/converters/key_converter.rb +87 -0
  73. data/lib/mongory/converters/value_converter.rb +52 -0
  74. data/lib/mongory/converters.rb +8 -0
  75. data/lib/mongory/matchers/abstract_matcher.rb +219 -0
  76. data/lib/mongory/matchers/abstract_multi_matcher.rb +124 -0
  77. data/lib/mongory/matchers/and_matcher.rb +72 -0
  78. data/lib/mongory/matchers/array_record_matcher.rb +93 -0
  79. data/lib/mongory/matchers/elem_match_matcher.rb +55 -0
  80. data/lib/mongory/matchers/eq_matcher.rb +46 -0
  81. data/lib/mongory/matchers/every_matcher.rb +56 -0
  82. data/lib/mongory/matchers/exists_matcher.rb +53 -0
  83. data/lib/mongory/matchers/field_matcher.rb +147 -0
  84. data/lib/mongory/matchers/gt_matcher.rb +41 -0
  85. data/lib/mongory/matchers/gte_matcher.rb +41 -0
  86. data/lib/mongory/matchers/hash_condition_matcher.rb +62 -0
  87. data/lib/mongory/matchers/in_matcher.rb +68 -0
  88. data/lib/mongory/matchers/literal_matcher.rb +121 -0
  89. data/lib/mongory/matchers/lt_matcher.rb +41 -0
  90. data/lib/mongory/matchers/lte_matcher.rb +41 -0
  91. data/lib/mongory/matchers/ne_matcher.rb +38 -0
  92. data/lib/mongory/matchers/nin_matcher.rb +68 -0
  93. data/lib/mongory/matchers/not_matcher.rb +40 -0
  94. data/lib/mongory/matchers/or_matcher.rb +68 -0
  95. data/lib/mongory/matchers/present_matcher.rb +55 -0
  96. data/lib/mongory/matchers/regex_matcher.rb +80 -0
  97. data/lib/mongory/matchers/size_matcher.rb +54 -0
  98. data/lib/mongory/matchers.rb +176 -0
  99. data/lib/mongory/mongoid.rb +19 -0
  100. data/lib/mongory/query_builder.rb +257 -0
  101. data/lib/mongory/query_matcher.rb +93 -0
  102. data/lib/mongory/query_operator.rb +28 -0
  103. data/lib/mongory/rails.rb +15 -0
  104. data/lib/mongory/utils/context.rb +48 -0
  105. data/lib/mongory/utils/debugger.rb +125 -0
  106. data/lib/mongory/utils/rails_patch.rb +22 -0
  107. data/lib/mongory/utils/singleton_builder.rb +31 -0
  108. data/lib/mongory/utils.rb +76 -0
  109. data/lib/mongory/version.rb +5 -0
  110. data/lib/mongory.rb +123 -0
  111. data/lib/mongory_ext.so +0 -0
  112. data/mongory.gemspec +62 -0
  113. data/scripts/build_with_core.sh +292 -0
  114. data/sig/mongory.rbs +4 -0
  115. metadata +159 -0
@@ -0,0 +1,95 @@
1
+ #ifndef MONGORY_MEMORY_POOL
2
+ #define MONGORY_MEMORY_POOL
3
+
4
+ /**
5
+ * @file memory_pool.h
6
+ * @brief Defines the mongory_memory_pool structure and its associated
7
+ * operations.
8
+ *
9
+ * A memory pool is used for efficient memory management within the Mongory
10
+ * library. It allows for allocating blocks of memory that can be freed
11
+ * all at once when the pool itself is destroyed. This can reduce the overhead
12
+ * of individual allocations and deallocations and help prevent memory leaks.
13
+ */
14
+
15
+ #include "mongory-core/foundations/error.h"
16
+ #include <stdbool.h>
17
+ #include <stdlib.h> // For size_t
18
+
19
+ // Forward declaration of the memory pool structure.
20
+ typedef struct mongory_memory_pool mongory_memory_pool;
21
+
22
+ #define MG_ALLOC(p, n) (p->alloc(p, n))
23
+ #define MG_ALLOC_PTR(p, t) ((t*)MG_ALLOC(p, sizeof(t)))
24
+ #define MG_ALLOC_OBJ(p, t) ((t)MG_ALLOC(p, sizeof(t)))
25
+ #define MG_ALLOC_ARY(p, t, n) ((t*)MG_ALLOC(p, sizeof(t) * (n)))
26
+ /**
27
+ * @struct mongory_memory_pool
28
+ * @brief Represents a memory pool for managing memory allocations.
29
+ *
30
+ * The pool uses a context (`ctx`) to store its internal state, which typically
31
+ * includes a list of allocated memory chunks.
32
+ * It provides function pointers for allocation, tracing (optional), and freeing
33
+ * the entire pool. An error field can store information about the last error
34
+ * encountered during pool operations.
35
+ */
36
+ struct mongory_memory_pool {
37
+ /**
38
+ * @brief Allocates a block of memory from the pool.
39
+ * @param ctx A pointer to the pool's internal context.
40
+ * @param size The number of bytes to allocate.
41
+ * @return void* A pointer to the allocated memory block, or NULL on failure.
42
+ * Memory allocated this way is typically aligned.
43
+ */
44
+ void *(*alloc)(mongory_memory_pool *pool, size_t size);
45
+
46
+ /**
47
+ * @brief Traces an externally allocated memory block, associating it with the
48
+ * pool.
49
+ *
50
+ * This is useful if memory is allocated outside the pool's `alloc` function
51
+ * (e.g., by an external library) but its lifecycle should be tied to the
52
+ * pool. When the pool is freed, traced memory blocks might also be freed
53
+ * depending on the pool's implementation.
54
+ *
55
+ * @param ctx A pointer to the pool's internal context.
56
+ * @param ptr A pointer to the memory block to trace.
57
+ * @param size The size of the memory block.
58
+ */
59
+ void (*trace)(mongory_memory_pool *pool, void *ptr, size_t size);
60
+
61
+ /**
62
+ * @brief Resets the memory pool to its initial state.
63
+ * @param ctx A pointer to the pool's internal context.
64
+ */
65
+ void (*reset)(mongory_memory_pool *pool);
66
+
67
+ /**
68
+ * @brief Frees the entire memory pool, including all memory blocks allocated
69
+ * from it and any traced memory blocks (depending on implementation).
70
+ * @param self A pointer to the mongory_memory_pool instance to be freed.
71
+ */
72
+ void (*free)(mongory_memory_pool *self);
73
+
74
+ void *ctx; /**< Pointer to the internal context/state of the memory
75
+ pool. This is managed by the pool implementation. */
76
+ mongory_error *error; /**< Pointer to a mongory_error structure. If an
77
+ operation fails (e.g., allocation), this may be set
78
+ to describe the error. The memory for this error
79
+ struct itself is typically allocated from the pool or
80
+ is a static error object. */
81
+ };
82
+
83
+ /**
84
+ * @brief Creates a new mongory_memory_pool instance.
85
+ *
86
+ * Initializes the pool structure and its internal context, preparing it for
87
+ * allocations.
88
+ *
89
+ * @return mongory_memory_pool* A pointer to the newly created memory pool, or
90
+ * NULL if creation fails (e.g., initial memory allocation for the pool's
91
+ * context failed).
92
+ */
93
+ mongory_memory_pool *mongory_memory_pool_new();
94
+
95
+ #endif /* MONGORY_MEMORY_POOL */
@@ -0,0 +1,127 @@
1
+ #ifndef MONGORY_TABLE_H
2
+ #define MONGORY_TABLE_H
3
+
4
+ /**
5
+ * @file table.h
6
+ * @brief Defines the mongory_table structure (a hash table) and its
7
+ * associated operations.
8
+ *
9
+ * mongory_table implements a hash table mapping string keys to mongory_value
10
+ * pointers. It uses a mongory_memory_pool for its allocations and handles
11
+ * operations like get, set, delete, and iteration over key-value pairs.
12
+ * The table automatically resizes (rehashes) when its load factor is exceeded.
13
+ */
14
+
15
+ #include "mongory-core/foundations/array.h" // Used internally by the table
16
+ #include "mongory-core/foundations/memory_pool.h"
17
+ #include "mongory-core/foundations/value.h"
18
+ #include <stdbool.h>
19
+ #include <stddef.h> // For size_t
20
+
21
+ // Forward declaration of the mongory_table structure.
22
+ struct mongory_table;
23
+ /**
24
+ * @brief Alias for `struct mongory_table`.
25
+ */
26
+ typedef struct mongory_table mongory_table;
27
+
28
+ /**
29
+ * @brief Callback function type for iterating over key-value pairs in a table.
30
+ * @param key The current key (null-terminated string).
31
+ * @param value A pointer to the current mongory_value.
32
+ * @param acc An accumulator or context pointer passed through the iteration.
33
+ * @return bool Return true to continue iteration, false to stop.
34
+ */
35
+ typedef bool (*mongory_table_each_pair_callback_func)(char *key, mongory_value *value, void *acc);
36
+
37
+ /**
38
+ * @brief Function pointer type for retrieving a value by its key.
39
+ * @param self A pointer to the mongory_table instance.
40
+ * @param key The null-terminated string key.
41
+ * @return mongory_value* A pointer to the mongory_value associated with the
42
+ * key, or NULL if the key is not found.
43
+ */
44
+ typedef mongory_value *(*mongory_table_get_func)(mongory_table *self, char *key);
45
+
46
+ /**
47
+ * @brief Function pointer type for setting (adding or updating) a key-value
48
+ * pair.
49
+ * @param self A pointer to the mongory_table instance.
50
+ * @param key The null-terminated string key. The table will make its own copy
51
+ * of this key.
52
+ * @param value A pointer to the mongory_value to associate with the key.
53
+ * @return bool True if the operation was successful, false otherwise (e.g.,
54
+ * memory allocation failure).
55
+ */
56
+ typedef bool (*mongory_table_set_func)(mongory_table *self, char *key, mongory_value *value);
57
+
58
+ /**
59
+ * @brief Function pointer type for iterating over all key-value pairs in the
60
+ * table.
61
+ * @param self A pointer to the mongory_table instance.
62
+ * @param acc An accumulator or context pointer to be passed to the callback.
63
+ * @param callback The function to be executed for each key-value pair.
64
+ * @return bool True if the iteration completed fully, false if it was stopped
65
+ * by a callback.
66
+ */
67
+ typedef bool (*mongory_table_each_func)(mongory_table *self, void *acc, mongory_table_each_pair_callback_func callback);
68
+
69
+ /**
70
+ * @brief Function pointer type for deleting a key-value pair from the table.
71
+ * @param self A pointer to the mongory_table instance.
72
+ * @param key The null-terminated string key of the pair to delete.
73
+ * @return bool True if the key was found and deleted, false otherwise.
74
+ */
75
+ typedef bool (*mongory_table_del_func)(mongory_table *self, char *key);
76
+
77
+ /**
78
+ * @brief Creates a new mongory_table instance.
79
+ *
80
+ * Initializes the hash table with a default capacity and associates it with the
81
+ * provided memory pool for all internal allocations.
82
+ *
83
+ * @param pool A pointer to the mongory_memory_pool to be used for allocations.
84
+ * @return mongory_table* A pointer to the newly created mongory_table, or NULL
85
+ * if creation fails (e.g., memory allocation failure).
86
+ */
87
+ mongory_table *mongory_table_new(mongory_memory_pool *pool);
88
+
89
+ /**
90
+ * @brief Creates a new mongory_table instance with a nested table.
91
+ *
92
+ * This function is used to create a new mongory_table instance with a nested
93
+ * table. The nested table is created with the given memory pool and the given
94
+ * key-value pairs. The nested table is returned as a pointer to the
95
+ * mongory_table structure.
96
+ *
97
+ * @param pool A pointer to the mongory_memory_pool to be used for allocations.
98
+ * @param argc The number of key-value pairs to be set.
99
+ * @param ... The key-value pairs to be set.
100
+ * @return mongory_table* A pointer to the newly created mongory_table, or NULL
101
+ * if creation fails (e.g., memory allocation failure).
102
+ */
103
+ mongory_table *mongory_table_nested_wrap(mongory_memory_pool *pool, int argc, ...);
104
+ #define MG_TABLE_WRAP(pool, n, ...) mongory_value_wrap_t(pool, mongory_table_nested_wrap(pool, n, __VA_ARGS__))
105
+
106
+ /**
107
+ * @struct mongory_table
108
+ * @brief Represents a hash table mapping string keys to mongory_value pointers.
109
+ *
110
+ * Provides function pointers for common table operations, similar to an
111
+ * object-oriented interface. The `count` field indicates the number of
112
+ * key-value pairs currently in the table and should be treated as read-only by
113
+ * users of the table.
114
+ */
115
+ struct mongory_table {
116
+ mongory_memory_pool *pool; /**< The memory pool used for allocations. */
117
+ size_t count; /**< Read-only. The current number of key-value pairs in the
118
+ table. */
119
+ mongory_table_get_func get; /**< Function to get a value by key. */
120
+ mongory_table_each_func each; /**< Function to iterate over key-value pairs. */
121
+ mongory_table_set_func set; /**< Function to set a key-value pair. */
122
+ mongory_table_del_func del; /**< Function to delete a key-value pair. */
123
+ };
124
+
125
+ mongory_table *mongory_table_merge(mongory_table *table, mongory_table *other);
126
+
127
+ #endif /* MONGORY_TABLE_H */
@@ -0,0 +1,175 @@
1
+ #ifndef MONGORY_VALUE
2
+ #define MONGORY_VALUE
3
+
4
+ /**
5
+ * @file value.h
6
+ * @brief Defines the mongory_value structure, a generic value type for the
7
+ * Mongory library.
8
+ *
9
+ * `mongory_value` is a tagged union that can represent various data types such
10
+ * as null, boolean, integer, double, string, array, table, regex, pointers,
11
+ * and an unsupported type. It includes functions for wrapping C types into
12
+ * `mongory_value` objects, comparing values, and converting them to strings.
13
+ */
14
+
15
+ #include "mongory-core/foundations/memory_pool.h"
16
+ #include <stdbool.h>
17
+ #include <stdint.h> // For int64_t
18
+
19
+ // Forward declarations for complex types that can be stored in mongory_value.
20
+ struct mongory_array;
21
+ struct mongory_table;
22
+
23
+ // Forward declaration of mongory_value itself and its type enum.
24
+ struct mongory_value;
25
+ /**
26
+ * @brief Alias for `struct mongory_value`.
27
+ */
28
+ typedef struct mongory_value mongory_value;
29
+
30
+ enum mongory_type;
31
+ /**
32
+ * @brief Alias for `enum mongory_type`.
33
+ */
34
+ typedef enum mongory_type mongory_type;
35
+
36
+ /**
37
+ * @brief Function pointer type for comparing two mongory_value instances.
38
+ *
39
+ * @param a The first mongory_value.
40
+ * @param b The second mongory_value.
41
+ * @return int Returns:
42
+ * - 0 if a is equal to b.
43
+ * - A negative value if a is less than b.
44
+ * - A positive value if a is greater than b.
45
+ * - `mongory_value_compare_fail` (a specific constant) if the types
46
+ * are incompatible for comparison or an error occurs.
47
+ */
48
+ typedef int (*mongory_value_compare_func)(mongory_value *a, mongory_value *b);
49
+
50
+ /**
51
+ * @brief Function pointer type for converting a mongory_value to a string representation.
52
+ * @param value The mongory_value to convert.
53
+ * @param pool The memory pool to allocate from.
54
+ * @return char* A string literal representing the value, or NULL if allocation
55
+ * fails. The string is a literal and should not be freed.
56
+ */
57
+ typedef char *(*mongory_value_to_str_func)(mongory_value *value, mongory_memory_pool *pool);
58
+
59
+ /**
60
+ * @brief Converts the type of a mongory_value to its string representation.
61
+ * @param value A pointer to the mongory_value.
62
+ * @return char* A string literal representing the type (e.g., "Int", "String").
63
+ * Returns "UnknownType" if the type is not recognized. This string is a
64
+ * literal and should not be freed.
65
+ */
66
+ char *mongory_type_to_string(mongory_value *value);
67
+
68
+ /**
69
+ * @brief Extracts a pointer to the raw data stored within a mongory_value.
70
+ * The type of the returned pointer depends on the `mongory_value`'s type.
71
+ * For example, for an MONGORY_TYPE_INT, it returns `int64_t*`.
72
+ * @param value A pointer to the mongory_value.
73
+ * @return void* A pointer to the internal data, or NULL if the type is unknown
74
+ * or has no direct data pointer (e.g. MONGORY_TYPE_NULL).
75
+ */
76
+ void *mongory_value_extract(mongory_value *value);
77
+
78
+ /** @name Mongory Value Wrapper Functions
79
+ * Functions to create mongory_value instances from basic C types.
80
+ * These functions allocate a new mongory_value from the provided pool.
81
+ * @{
82
+ */
83
+ mongory_value *mongory_value_wrap_n(mongory_memory_pool *pool, void *n);
84
+ mongory_value *mongory_value_wrap_b(mongory_memory_pool *pool, bool b);
85
+ mongory_value *mongory_value_wrap_i(mongory_memory_pool *pool, int64_t i);
86
+ mongory_value *mongory_value_wrap_d(mongory_memory_pool *pool, double d);
87
+ mongory_value *mongory_value_wrap_s(mongory_memory_pool *pool, char *s);
88
+ mongory_value *mongory_value_wrap_a(mongory_memory_pool *pool, struct mongory_array *a);
89
+ mongory_value *mongory_value_wrap_t(mongory_memory_pool *pool, struct mongory_table *t);
90
+ mongory_value *mongory_value_wrap_regex(mongory_memory_pool *pool, void *regex);
91
+ mongory_value *mongory_value_wrap_ptr(mongory_memory_pool *pool, void *ptr);
92
+ mongory_value *mongory_value_wrap_u(mongory_memory_pool *pool, void *u);
93
+ /** @} */
94
+
95
+ /**
96
+ * @def MONGORY_TYPE_MACRO
97
+ * @brief X-Macro for defining mongory_type enum members and associated data.
98
+ * Simplifies the definition of types, their string names, and corresponding
99
+ * union fields.
100
+ * _(ENUM_NAME, UNIQUE_NUM_SUFFIX, "STRING_NAME", UNION_FIELD_NAME)
101
+ * Note: For MONGORY_TYPE_NULL, the 'i' field (int64_t) is arbitrarily used in
102
+ * the macro as the union needs a field, but it's not meaningful for null.
103
+ */
104
+ #define MONGORY_TYPE_MACRO(_) \
105
+ _(MONGORY_TYPE_NULL, 0, "Null", i) /* Field 'i' is arbitrary for NULL */ \
106
+ _(MONGORY_TYPE_BOOL, 10, "Bool", b) \
107
+ _(MONGORY_TYPE_INT, 11, "Int", i) \
108
+ _(MONGORY_TYPE_DOUBLE, 12, "Double", d) \
109
+ _(MONGORY_TYPE_STRING, 13, "String", s) \
110
+ _(MONGORY_TYPE_ARRAY, 14, "Array", a) \
111
+ _(MONGORY_TYPE_TABLE, 15, "Table", t) \
112
+ _(MONGORY_TYPE_REGEX, 16, "Regex", regex) /* Custom regex object pointer */ \
113
+ _(MONGORY_TYPE_POINTER, 17, "Pointer", ptr) /* Generic void pointer */ \
114
+ _(MONGORY_TYPE_UNSUPPORTED, 999, "Unsupported", u) /* External/unknown type pointer */
115
+
116
+ /**
117
+ * @def MONGORY_ENUM_MAGIC
118
+ * @brief A magic number used in generating enum values for mongory_type.
119
+ * Helps in creating somewhat unique integer values for the enums.
120
+ */
121
+ #define MONGORY_ENUM_MAGIC 103
122
+
123
+ /**
124
+ * @enum mongory_type
125
+ * @brief Enumerates the possible data types a mongory_value can hold.
126
+ * Values are generated using MONGORY_TYPE_MACRO and MONGORY_ENUM_MAGIC.
127
+ */
128
+ enum mongory_type {
129
+ #define DEFINE_ENUM(name, num, str, field) name = num * MONGORY_ENUM_MAGIC,
130
+ MONGORY_TYPE_MACRO(DEFINE_ENUM)
131
+ #undef DEFINE_ENUM
132
+ };
133
+
134
+ /**
135
+ * @var mongory_value_compare_fail
136
+ * @brief Special return value from compare functions indicating comparison
137
+ * failure (e.g. incompatible types).
138
+ */
139
+ static const int mongory_value_compare_fail = 97;
140
+
141
+ /**
142
+ * @struct mongory_value
143
+ * @brief Represents a generic value in the Mongory system.
144
+ *
145
+ * It's a tagged union, where `type` indicates which field in the `data` union
146
+ * is active. Each value also carries a pointer to the `mongory_memory_pool`
147
+ * it was allocated from (or is associated with) and a `comp` function for
148
+ * comparisons. The `origin` field can be used to store a pointer to an
149
+ * original external data structure if the `mongory_value` is a bridge or
150
+ * wrapper.
151
+ */
152
+ struct mongory_value {
153
+ mongory_memory_pool *pool; /**< Memory pool associated with this value. */
154
+ mongory_type type; /**< The type of data stored in the union. */
155
+ mongory_value_compare_func comp; /**< Function to compare this value with
156
+ another. */
157
+ mongory_value_to_str_func to_str; /**< Function to convert this value to a
158
+ string representation. */
159
+ union {
160
+ bool b; /**< Boolean data. */
161
+ int64_t i; /**< Integer data (64-bit). */
162
+ double d; /**< Double-precision floating-point data. */
163
+ char *s; /**< String data (null-terminated). String memory
164
+ is typically managed by the pool. */
165
+ struct mongory_array *a; /**< Pointer to a mongory_array. */
166
+ struct mongory_table *t; /**< Pointer to a mongory_table. */
167
+ void *regex; /**< Pointer to a custom regex object/structure. */
168
+ void *ptr; /**< Generic void pointer for other data. */
169
+ void *u; /**< Pointer for unsupported/external types. */
170
+ } data; /**< Union holding the actual data based on type. */
171
+ void *origin; /**< Optional pointer to an original external value, useful for
172
+ bridging with other data systems. */
173
+ };
174
+
175
+ #endif /* MONGORY_VALUE */
@@ -0,0 +1,76 @@
1
+ #ifndef MONGORY_MATCHER_H
2
+ #define MONGORY_MATCHER_H
3
+
4
+ /**
5
+ * @file matcher.h
6
+ * @brief Defines the core mongory_matcher structure and related types.
7
+ *
8
+ * This file provides the basic structure for all matchers in the Mongory
9
+ * library. A matcher is responsible for determining if a given `mongory_value`
10
+ * meets certain criteria defined by a `condition`.
11
+ */
12
+
13
+ #include "mongory-core/foundations/array.h" // For mongory_array (used in context)
14
+ #include "mongory-core/foundations/memory_pool.h"
15
+ #include "mongory-core/foundations/value.h"
16
+
17
+ // Forward declaration for the main matcher structure.
18
+ typedef struct mongory_matcher mongory_matcher;
19
+ /**
20
+ * @brief Creates a new generic matcher instance.
21
+ *
22
+ * This function typically serves as a high-level entry point for creating
23
+ * matchers. In the current implementation, it delegates to
24
+ * `mongory_matcher_table_cond_new`, implying that conditions are often
25
+ * table-based (similar to query documents).
26
+ *
27
+ * @param pool The memory pool to use for the matcher's allocations.
28
+ * @param condition A `mongory_value` representing the condition for this
29
+ * matcher.
30
+ * @return mongory_matcher* A pointer to the newly created matcher, or NULL on
31
+ * failure.
32
+ */
33
+ mongory_matcher *mongory_matcher_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
34
+
35
+ /**
36
+ * @brief Matches a value against a matcher.
37
+ * @param matcher The matcher to match against.
38
+ * @param value The value to match.
39
+ * @return True if the value matches the matcher, false otherwise.
40
+ */
41
+ bool mongory_matcher_match(mongory_matcher *matcher, mongory_value *value);
42
+
43
+ /**
44
+ * @brief Explains a matcher.
45
+ * @param matcher The matcher to explain.
46
+ * @param temp_pool The temporary pool to use for the explanation.
47
+ */
48
+ void mongory_matcher_explain(mongory_matcher *matcher, mongory_memory_pool *temp_pool);
49
+
50
+ /**
51
+ * @brief Traces a matcher.
52
+ * @param matcher The matcher to trace.
53
+ * @param value The value to trace.
54
+ */
55
+ bool mongory_matcher_trace(mongory_matcher *matcher, mongory_value *value);
56
+
57
+ /**
58
+ * @brief Prints the trace of a matcher.
59
+ * @param matcher The matcher to print the trace of.
60
+ */
61
+ void mongory_matcher_print_trace(mongory_matcher *matcher);
62
+
63
+ /**
64
+ * @brief Enables the trace of a matcher.
65
+ * @param matcher The matcher to enable the trace of.
66
+ * @param temp_pool The temporary pool to use for the trace.
67
+ */
68
+ void mongory_matcher_enable_trace(mongory_matcher *matcher, mongory_memory_pool *temp_pool);
69
+
70
+ /**
71
+ * @brief Disables the trace of a matcher.
72
+ * @param matcher The matcher to disable the trace of.
73
+ */
74
+ void mongory_matcher_disable_trace(mongory_matcher *matcher);
75
+
76
+ #endif /* MONGORY_MATCHER_H */
@@ -0,0 +1,12 @@
1
+ #ifndef MONGORY_CORE_H
2
+ #define MONGORY_CORE_H
3
+
4
+ #include "mongory-core/foundations/array.h"
5
+ #include "mongory-core/foundations/config.h"
6
+ #include "mongory-core/foundations/error.h"
7
+ #include "mongory-core/foundations/memory_pool.h"
8
+ #include "mongory-core/foundations/table.h"
9
+ #include "mongory-core/foundations/value.h"
10
+ #include "mongory-core/matchers/matcher.h"
11
+
12
+ #endif