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