1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
.. -*- rst -*-
.. highlightlang:: none
``grn_ctx``
===========
Summary
-------
:c:type:`grn_ctx` is the most important object. :c:type:`grn_ctx`
keeps the current information such as:
* The last occurred error.
* The current encoding.
* The default thresholds. (e.g. :ref:`select-match-escalation-threshold`)
* The default command version. (See :doc:`/reference/command/command_version`)
:c:type:`grn_ctx` provides platform features such as:
* Memory management.
* Logging.
Most APIs receive :c:type:`grn_ctx` as the first argument.
You can't use the same :c:type:`grn_ctx` from two or more threads. You
need to create a :c:type:`grn_ctx` for a thread. You can use two or
more :c:type:`grn_ctx` in a thread but it is not needed for usual
use-case.
Example
-------
TODO...
Reference
---------
.. c:type:: grn_ctx
TODO...
.. c:function:: grn_rc grn_ctx_init(grn_ctx *ctx, int flags)
ctxを初期化します。
:param ctx: 初期化するctx構造体へのポインタを指定します。
:param flags: 初期化する ``ctx`` のオプションを指定します。
:return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` on error.
.. c:function:: grn_rc grn_ctx_fin(grn_ctx *ctx)
ctxの管理するメモリを解放し、使用を終了します。
If ``ctx`` is initialized by :c:func:`grn_ctx_open()` not
:c:func:`grn_ctx_init()`, you need to use
:c:func:`grn_ctx_close()` instead of :c:func:`grn_ctx_fin()`.
:param ctx: 解放するctx構造体へのポインタを指定します。
:return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` on error.
.. c:function:: grn_ctx *grn_ctx_open(int flags)
初期化された :c:type:`grn_ctx` オブジェクトを返します。
:c:func:`grn_ctx_init()` で初期化された :c:type:`grn_ctx` オブジェクトは構造体の実体をAPIの呼び元で確保するのに対して、 :c:func:`grn_ctx_open()` ではGroongaライブラリの内部で、実体を確保します。
どちらで初期化された :c:type:`grn_ctx` も、 :c:func:`grn_ctx_fin()` で解放できます。
:c:func:`grn_ctx_open()` で確保した :c:type:`grn_ctx` 構造体に関しては、:c:func:`grn_ctx_fin()` で解放した後に、その :c:type:`grn_ctx` で作成した :c:type:`grn_obj` を :c:func:`grn_obj_close()` によって解放しても問題ありません。
:param flags: 初期化する ``ctx`` のオプションを指定します。
:return: 初期化された :c:type:`grn_ctx` オブジェクトを返します。
.. c:function:: grn_rc grn_ctx_close(grn_ctx *ctx)
It calls :c:func:`grn_ctx_fin()` and frees allocated memory for ``ctx`` by :c:func:`grn_ctx_open()`.
:param ctx: no longer needed :c:type:`grn_ctx`.
:return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` on error.
.. c:function:: grn_rc grn_ctx_set_finalizer(grn_ctx *ctx, grn_proc_func *func)
ctxを破棄するときに呼ばれる関数を設定します。
:param ctx: 対象ctxを指定します。
:param func: ``ctx`` を破棄するときに呼ばれる関数を指定します。
:return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` on error.
.. c:function:: grn_command_version grn_ctx_get_command_version(grn_ctx *ctx)
command_versionを返します。
.. c:function:: grn_rc grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version)
command_versionを変更します。
:param version: 変更後のcommand_versionを指定します。
.. c:function:: grn_rc grn_ctx_use(grn_ctx *ctx, grn_obj *db)
ctxが操作対象とするdbを指定します。NULLを指定した場合は、dbを操作しない状態(init直後の状態)になります。
Don't use it with :c:type:`grn_ctx` that has ``GRN_CTX_PER_DB`` flag.
:param db: ctxが使用するdbを指定します。
.. c:function:: grn_obj *grn_ctx_db(grn_ctx *ctx)
ctxが現在操作対象としているdbを返します。dbを使用していない場合はNULLを返します。
.. c:function:: grn_obj *grn_ctx_get(grn_ctx *ctx, const char *name, int name_size)
ctxが使用するdbからnameに対応するオブジェクトを検索して返す。nameに一致するオブジェクトが存在しなければNULLを返す。
:param name: 検索しようとするオブジェクトの名前。
:param name_size: The number of bytes of name. If negative value is specified, name is assumed that NULL-terminated string.
.. c:function:: grn_obj *grn_ctx_at(grn_ctx *ctx, grn_id id)
ctx、またはctxが使用するdbからidに対応するオブジェクトを検索して返す。idに一致するオブジェクトが存在しなければNULLを返す。
:param id: 検索しようとするオブジェクトのidを指定します。
.. c:function:: grn_rc grn_ctx_get_all_tables(grn_ctx *ctx, grn_obj *tables_buffer)
It pushes all tables in the database of ``ctx`` into
``tables_buffer``. ``tables_buffer`` should be initialized as
``GRN_PVECTOR``. You can use ``GRN_PTR_INIT()`` with
``GRN_OBJ_VECTOR`` flags to initialize ``tables_buffer``.
Here is an example:
.. code-block :: c
grn_rc rc;
grn_obj tables;
int i;
int n_tables;
GRN_PTR_INIT(&tables, GRN_OBJ_VECTOR, GRN_ID_NIL);
rc = grn_ctx_get_all_tables(ctx, &tables);
if (rc != GRN_SUCCESS) {
GRN_OBJ_FIN(ctx, &tables);
/* Handle error. */
return;
}
n_tables = GRN_BULK_VSIZE(&tables) / sizeof(grn_obj *);
for (i = 0; i < n_tables; i++) {
grn_obj *table = GRN_PTR_VALUE_AT(&tables, i);
/* Use table. */
}
/* Free resources. */
for (i = 0; i < n_tables; i++) {
grn_obj *table = GRN_PTR_VALUE_AT(&tables, i);
grn_obj_unlink(ctx, table);
}
GRN_OBJ_FIN(ctx, &tables);
:param ctx: The context object.
:param table_buffer: The output buffer to store tables.
:return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` on error.
.. c:function:: grn_content_type grn_ctx_get_output_type(grn_ctx *ctx)
Gets the current output type of the context.
Normally, this function isn't needed.
:param ctx: The context object.
:return: The output type of the context.
.. c:function:: grn_rc grn_ctx_set_output_type(grn_ctx *ctx, grn_content_type type)
Sets the new output type to the context. It is used by executing a
command by :c:func:`grn_expr_exec()`. If you use
:c:func:`grn_ctx_send()`, the new output type isn't
used. :c:func:`grn_ctx_send()` sets output type from command line
internally.
Normally, this function isn't needed.
:param ctx: The context object.
:param type: The new output type.
:return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` on error.
.. c:function:: grn_bool_rc grn_ctx_is_opened(grn_ctx *ctx, grn_id id)
Checks whether object with the ID is opened or not.
:param ctx: The context object.
:param id: The object ID to be checked.
:return: ``GRN_TRUE`` if object with the ID is opened,
``GRN_FALSE`` otherwise.
|