Debian Codegraph @

shumate/vector/shumate-vector-symbol-info.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 James Westman <[email protected]>
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, see <https://www.gnu.org/licenses/>.
16 */
17
18
19 #include "shumate-vector-symbol-info-private.h"
20
21
22 G_DEFINE_BOXED_TYPE (ShumateVectorSymbolInfo, shumate_vector_symbol_info, shumate_vector_symbol_info_ref, shumate_vector_symbol_info_unref)
23
24
25 static void
26 shumate_vector_symbol_details_free (ShumateVectorSymbolDetails *details)
27 {
28 g_assert (details != NULL);
29 g_assert_cmpint (details->ref_count, ==, 0);
30
31 g_clear_pointer (&details->layer, g_free);
32 g_clear_pointer (&details->feature_id, g_free);
33 g_clear_pointer (&details->source_layer, g_free);
34
35 g_clear_object (&details->icon_image);
36
37 g_clear_pointer (&details->formatted_text, g_ptr_array_unref);
38 g_clear_pointer (&details->text_font, g_free);
39
40 g_clear_pointer (&details->cursor, g_free);
41
42 g_clear_pointer (&details->tags, g_hash_table_unref);
43
44 g_free (details);
45 }
46
47 ShumateVectorSymbolDetails *
48 shumate_vector_symbol_details_ref (ShumateVectorSymbolDetails *details)
49 {
50 g_return_val_if_fail (details, NULL);
51 g_return_val_if_fail (details->ref_count, NULL);
52
53 g_atomic_int_inc (&details->ref_count);
54
55 return details;
56 }
57
58 void
59 shumate_vector_symbol_details_unref (ShumateVectorSymbolDetails *details)
60 {
61 g_return_if_fail (details);
62 g_return_if_fail (details->ref_count);
63
64 if (g_atomic_int_dec_and_test (&details->ref_count))
65 shumate_vector_symbol_details_free (details);
66 }
67
68 static void
69 shumate_vector_symbol_info_free (ShumateVectorSymbolInfo *self)
70 {
71 g_assert (self != NULL);
72 g_assert_cmpint (self->ref_count, ==, 0);
73
74 g_clear_pointer (&self->details, shumate_vector_symbol_details_unref);
75
76 g_clear_pointer (&self->line, shumate_vector_line_string_free);
77
78 g_free (self);
79 }
80
81 ShumateVectorSymbolInfo *
82 shumate_vector_symbol_info_ref (ShumateVectorSymbolInfo *self)
83 {
84 g_return_val_if_fail (self, NULL);
85 g_return_val_if_fail (self->ref_count, NULL);
86
87 g_atomic_int_inc (&self->ref_count);
88
89 return self;
90 }
91
92 void
93 shumate_vector_symbol_info_unref (ShumateVectorSymbolInfo *self)
94 {
95 g_return_if_fail (self);
96 g_return_if_fail (self->ref_count);
97
98 if (g_atomic_int_dec_and_test (&self->ref_count))
99 shumate_vector_symbol_info_free (self);
100 }
101
102
103 void
104 shumate_vector_symbol_info_set_line_points (ShumateVectorSymbolInfo *self,
105 ShumateVectorLineString *linestring,
106 float position)
107 {
108 ShumateVectorPoint center;
109 g_clear_pointer (&self->line, shumate_vector_line_string_free);
110 self->line = linestring;
111
112 shumate_vector_line_string_bounds (self->line, &self->line_size, &center);
113 self->x = center.x;
114 self->y = center.y;
115 self->line_length = shumate_vector_line_string_length (self->line);
116 self->line_position = position;
117 }
118
119 int
120 shumate_vector_symbol_info_compare (ShumateVectorSymbolInfo *a,
121 ShumateVectorSymbolInfo *b)
122 {
123 if (a->details->layer_idx < b->details->layer_idx)
124 return -1;
125 else if (a->details->layer_idx > b->details->layer_idx)
126 return 1;
127 else if (a->details->symbol_sort_key < b->details->symbol_sort_key)
128 return -1;
129 else if (a->details->symbol_sort_key > b->details->symbol_sort_key)
130 return 1;
131 else
132 return 0;
133 }