Coverage Report

Created: 2025-08-28 06:43

/src/tinysparql/src/libtinysparql/tracker-deserializer-rdf.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2022, Red Hat, Inc
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, write to the
16
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA  02110-1301, USA.
18
 *
19
 * Author: Carlos Garnacho <carlosg@gnome.org>
20
 */
21
22
#include "config.h"
23
24
#include "tracker-deserializer-rdf.h"
25
26
#include "tracker-private.h"
27
28
static gchar *col_names[] = {
29
  "subject",
30
  "predicate",
31
  "object",
32
  "graph",
33
};
34
35
G_STATIC_ASSERT (G_N_ELEMENTS (col_names) == TRACKER_RDF_N_COLS);
36
37
enum {
38
  PROP_0,
39
  PROP_HAS_GRAPH,
40
  N_PROPS
41
};
42
43
static GParamSpec *props[N_PROPS];
44
45
typedef struct _TrackerDeserializerRdfPrivate TrackerDeserializerRdfPrivate;
46
47
struct _TrackerDeserializerRdfPrivate
48
{
49
  gboolean has_graph;
50
};
51
52
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TrackerDeserializerRdf, tracker_deserializer_rdf,
53
                                     TRACKER_TYPE_DESERIALIZER)
54
55
static void
56
tracker_deserializer_rdf_set_property (GObject      *object,
57
                                       guint         prop_id,
58
                                       const GValue *value,
59
                                       GParamSpec   *pspec)
60
8
{
61
8
  TrackerDeserializerRdf *serializer_rdf = TRACKER_DESERIALIZER_RDF (object);
62
8
  TrackerDeserializerRdfPrivate *priv =
63
8
    tracker_deserializer_rdf_get_instance_private (serializer_rdf);
64
65
8
  switch (prop_id) {
66
8
  case PROP_HAS_GRAPH:
67
8
    priv->has_graph = g_value_get_boolean (value);
68
8
    break;
69
0
  default:
70
0
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
71
0
    break;
72
8
  }
73
8
}
74
75
static void
76
tracker_deserializer_rdf_get_property (GObject    *object,
77
                                       guint       prop_id,
78
                                       GValue     *value,
79
                                       GParamSpec *pspec)
80
8
{
81
8
  TrackerDeserializerRdf *serializer_rdf = TRACKER_DESERIALIZER_RDF (object);
82
8
  TrackerDeserializerRdfPrivate *priv =
83
8
    tracker_deserializer_rdf_get_instance_private (serializer_rdf);
84
85
8
  switch (prop_id) {
86
8
  case PROP_HAS_GRAPH:
87
8
    g_value_set_boolean (value, priv->has_graph);
88
8
    break;
89
0
  default:
90
0
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
91
0
    break;
92
8
  }
93
8
}
94
95
static const gchar *
96
tracker_deserializer_rdf_get_variable_name (TrackerSparqlCursor *cursor,
97
                                            gint                 column)
98
0
{
99
0
  if (column >= tracker_sparql_cursor_get_n_columns (cursor))
100
0
    return NULL;
101
102
0
  g_assert (column < TRACKER_RDF_N_COLS);
103
104
0
  return col_names[column];
105
0
}
106
107
static gint
108
tracker_deserializer_rdf_get_n_columns (TrackerSparqlCursor *cursor)
109
0
{
110
0
  TrackerDeserializerRdf *deserializer_rdf =
111
0
    TRACKER_DESERIALIZER_RDF (cursor);
112
0
  TrackerDeserializerRdfPrivate *priv =
113
0
    tracker_deserializer_rdf_get_instance_private (deserializer_rdf);
114
115
0
  return (priv->has_graph) ? TRACKER_RDF_N_COLS : TRACKER_RDF_N_COLS - 1;
116
0
}
117
118
static void
119
tracker_deserializer_rdf_class_init (TrackerDeserializerRdfClass *klass)
120
1
{
121
1
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
122
1
  TrackerSparqlCursorClass *cursor_class = TRACKER_SPARQL_CURSOR_CLASS (klass);
123
124
1
  object_class->set_property = tracker_deserializer_rdf_set_property;
125
1
  object_class->get_property = tracker_deserializer_rdf_get_property;
126
127
1
  cursor_class->get_variable_name = tracker_deserializer_rdf_get_variable_name;
128
1
  cursor_class->get_n_columns = tracker_deserializer_rdf_get_n_columns;
129
130
1
  props[PROP_HAS_GRAPH] =
131
1
    g_param_spec_boolean ("has-graph",
132
1
                          "Has graph",
133
1
                          "Has graph",
134
1
                          FALSE,
135
1
                          G_PARAM_CONSTRUCT_ONLY |
136
1
                          G_PARAM_STATIC_STRINGS |
137
1
                          G_PARAM_READABLE |
138
1
                          G_PARAM_WRITABLE);
139
140
1
  g_object_class_install_properties (object_class, N_PROPS, props);
141
1
}
142
143
static void
144
tracker_deserializer_rdf_init (TrackerDeserializerRdf *deserializer_rdf)
145
8
{
146
8
}