evolution-3.6.4/widgets/table/e-table-memory-callbacks.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-table-memory-callbacks.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-table-memory-callbacks.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Chris Lahey <clahey@ximian.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include "e-util/e-util.h"
 29 
 30 #include "e-table-memory-callbacks.h"
 31 
 32 G_DEFINE_TYPE (ETableMemoryCallbacks, e_table_memory_callbacks, E_TYPE_TABLE_MEMORY)
 33 
 34 static gint
 35 etmc_column_count (ETableModel *etm)
 36 {
 37 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
 38 
 39 	if (etmc->col_count)
 40 		return etmc->col_count (etm, etmc->data);
 41 	else
 42 		return 0;
 43 }
 44 
 45 static gpointer
 46 etmc_value_at (ETableModel *etm,
 47                gint col,
 48                gint row)
 49 {
 50 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
 51 
 52 	if (etmc->value_at)
 53 		return etmc->value_at (etm, col, row, etmc->data);
 54 	else
 55 		return NULL;
 56 }
 57 
 58 static void
 59 etmc_set_value_at (ETableModel *etm,
 60                    gint col,
 61                    gint row,
 62                    gconstpointer val)
 63 {
 64 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
 65 
 66 	if (etmc->set_value_at)
 67 		etmc->set_value_at (etm, col, row, val, etmc->data);
 68 }
 69 
 70 static gboolean
 71 etmc_is_cell_editable (ETableModel *etm,
 72                        gint col,
 73                        gint row)
 74 {
 75 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
 76 
 77 	if (etmc->is_cell_editable)
 78 		return etmc->is_cell_editable (etm, col, row, etmc->data);
 79 	else
 80 		return FALSE;
 81 }
 82 
 83 /* The default for etmc_duplicate_value is to return the raw value. */
 84 static gpointer
 85 etmc_duplicate_value (ETableModel *etm,
 86                       gint col,
 87                       gconstpointer value)
 88 {
 89 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
 90 
 91 	if (etmc->duplicate_value)
 92 		return etmc->duplicate_value (etm, col, value, etmc->data);
 93 	else
 94 		return (gpointer) value;
 95 }
 96 
 97 static void
 98 etmc_free_value (ETableModel *etm,
 99                  gint col,
100                  gpointer value)
101 {
102 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
103 
104 	if (etmc->free_value)
105 		etmc->free_value (etm, col, value, etmc->data);
106 }
107 
108 static gpointer
109 etmc_initialize_value (ETableModel *etm,
110                        gint col)
111 {
112 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
113 
114 	if (etmc->initialize_value)
115 		return etmc->initialize_value (etm, col, etmc->data);
116 	else
117 		return NULL;
118 }
119 
120 static gboolean
121 etmc_value_is_empty (ETableModel *etm,
122                      gint col,
123                      gconstpointer value)
124 {
125 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
126 
127 	if (etmc->value_is_empty)
128 		return etmc->value_is_empty (etm, col, value, etmc->data);
129 	else
130 		return FALSE;
131 }
132 
133 static gchar *
134 etmc_value_to_string (ETableModel *etm,
135                       gint col,
136                       gconstpointer value)
137 {
138 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
139 
140 	if (etmc->value_to_string)
141 		return etmc->value_to_string (etm, col, value, etmc->data);
142 	else
143 		return g_strdup ("");
144 }
145 
146 static void
147 etmc_append_row (ETableModel *etm,
148                  ETableModel *source,
149                  gint row)
150 {
151 	ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm);
152 
153 	if (etmc->append_row)
154 		etmc->append_row (etm, source, row, etmc->data);
155 }
156 
157 static void
158 e_table_memory_callbacks_class_init (ETableMemoryCallbacksClass *class)
159 {
160 	ETableModelClass *model_class = E_TABLE_MODEL_CLASS (class);
161 
162 	model_class->column_count     = etmc_column_count;
163 	model_class->value_at         = etmc_value_at;
164 	model_class->set_value_at     = etmc_set_value_at;
165 	model_class->is_cell_editable = etmc_is_cell_editable;
166 	model_class->duplicate_value  = etmc_duplicate_value;
167 	model_class->free_value       = etmc_free_value;
168 	model_class->initialize_value = etmc_initialize_value;
169 	model_class->value_is_empty   = etmc_value_is_empty;
170 	model_class->value_to_string  = etmc_value_to_string;
171 	model_class->append_row       = etmc_append_row;
172 
173 }
174 
175 static void
176 e_table_memory_callbacks_init (ETableMemoryCallbacks *etmc)
177 {
178 	/* nothing to do */
179 }
180 
181 /**
182  * e_table_memory_callbacks_new:
183  * @col_count:
184  * @value_at:
185  * @set_value_at:
186  * @is_cell_editable:
187  * @duplicate_value:
188  * @free_value:
189  * @initialize_value:
190  * @value_is_empty:
191  * @value_to_string:
192  * @data: closure pointer.
193  *
194  * This initializes a new ETableMemoryCallbacksModel object.
195  * ETableMemoryCallbacksModel is an implementaiton of the abstract class
196  * ETableModel.  The ETableMemoryCallbacksModel is designed to allow people
197  * to easily create ETableModels without having to create a new GType
198  * derived from ETableModel every time they need one.
199  *
200  * Instead, ETableMemoryCallbacksModel uses a setup based in callback
201  * functions, every callback function signature mimics the signature of
202  * each ETableModel method and passes the extra @data pointer to each one
203  * of the method to provide them with any context they might want to use.
204  *
205  * Returns: An ETableMemoryCallbacksModel object (which is also an ETableModel
206  * object).
207  */
208 ETableModel *
209 e_table_memory_callbacks_new (ETableMemoryCallbacksColumnCountFn col_count,
210                               ETableMemoryCallbacksValueAtFn value_at,
211                               ETableMemoryCallbacksSetValueAtFn set_value_at,
212                               ETableMemoryCallbacksIsCellEditableFn is_cell_editable,
213                               ETableMemoryCallbacksDuplicateValueFn duplicate_value,
214                               ETableMemoryCallbacksFreeValueFn free_value,
215                               ETableMemoryCallbacksInitializeValueFn initialize_value,
216                               ETableMemoryCallbacksValueIsEmptyFn value_is_empty,
217                               ETableMemoryCallbacksValueToStringFn value_to_string,
218                               gpointer data)
219 {
220 	ETableMemoryCallbacks *et;
221 
222 	et = g_object_new (E_TYPE_TABLE_MEMORY_CALLBACKS, NULL);
223 
224 	et->col_count        = col_count;
225 	et->value_at         = value_at;
226 	et->set_value_at     = set_value_at;
227 	et->is_cell_editable = is_cell_editable;
228 	et->duplicate_value  = duplicate_value;
229 	et->free_value       = free_value;
230 	et->initialize_value = initialize_value;
231 	et->value_is_empty   = value_is_empty;
232 	et->value_to_string  = value_to_string;
233 	et->data             = data;
234 
235 	return (ETableModel *) et;
236  }