1 | /* -*- c-basic-offset: 2 -*- */ |
2 | /* |
3 | Copyright(C) 2014 Kouhei Sutou <kou@clear-code.com> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #include <string.h> |
21 | |
22 | #include "mrn_smart_grn_obj.hpp" |
23 | |
24 | namespace mrn { |
25 | SmartGrnObj::SmartGrnObj(grn_ctx *ctx, grn_obj *obj) |
26 | : ctx_(ctx), |
27 | obj_(obj) { |
28 | } |
29 | |
30 | SmartGrnObj::SmartGrnObj(grn_ctx *ctx, const char *name, int name_size) |
31 | : ctx_(ctx), |
32 | obj_(NULL) { |
33 | if (name_size < 0) { |
34 | name_size = strlen(name); |
35 | } |
36 | obj_ = grn_ctx_get(ctx_, name, name_size); |
37 | } |
38 | |
39 | SmartGrnObj::SmartGrnObj(grn_ctx *ctx, grn_id id) |
40 | : ctx_(ctx), |
41 | obj_(grn_ctx_at(ctx_, id)) { |
42 | } |
43 | |
44 | SmartGrnObj::~SmartGrnObj() { |
45 | if (obj_) { |
46 | grn_obj_unlink(ctx_, obj_); |
47 | } |
48 | } |
49 | |
50 | grn_obj *SmartGrnObj::get() { |
51 | return obj_; |
52 | } |
53 | |
54 | grn_obj *SmartGrnObj::release() { |
55 | grn_obj *obj = obj_; |
56 | obj_ = NULL; |
57 | return obj; |
58 | } |
59 | } |
60 | |