treewide: Replace <name>_cnt by n_<name>s and <name>_cap by allocated_<name>.
[pspp] / src / ui / gui / psppire-dict.c
index e381e5dab7a40050df1a47f89e33564ded7341f6..215a1d3e5811cbe02a3c94589fb8d81d5cec178a 100644 (file)
@@ -63,8 +63,6 @@ enum  {
 
 
 /* --- prototypes --- */
-static void psppire_dict_class_init    (PsppireDictClass       *class);
-static void psppire_dict_init  (PsppireDict            *dict);
 static void psppire_dict_dispose       (GObject                *object);
 
 static void dictionary_tree_model_init (GtkTreeModelIface *iface);
@@ -76,7 +74,7 @@ gni (GListModel *list)
 {
   PsppireDict *dict = PSPPIRE_DICT (list);
 
-  return psppire_dict_get_var_cnt (dict);
+  return psppire_dict_get_n_vars (dict);
 }
 
 static GType
@@ -92,7 +90,7 @@ gi (GListModel *list, guint id)
 
   PsppireDict *dict = PSPPIRE_DICT (list);
 
-  if (id >= psppire_dict_get_var_cnt (dict))
+  if (id >= psppire_dict_get_n_vars (dict))
     {
       gtk_button_set_label (GTK_BUTTON (button),  _("Var"));
     }
@@ -141,55 +139,12 @@ static GObjectClass     *parent_class = NULL;
 static guint signals [n_SIGNALS];
 
 /* --- functions --- */
-/**
- * psppire_dict_get_type:
- * @returns: the type ID for accelerator groups.
- */
-GType
-psppire_dict_get_type (void)
-{
-  static GType object_type = 0;
-
-  if (!object_type)
-    {
-      static const GTypeInfo object_info = {
-       sizeof (PsppireDictClass),
-       (GBaseInitFunc) NULL,
-       (GBaseFinalizeFunc) NULL,
-       (GClassInitFunc) psppire_dict_class_init,
-       NULL,   /* class_finalize */
-       NULL,   /* class_data */
-       sizeof (PsppireDict),
-       0,      /* n_preallocs */
-       (GInstanceInitFunc) psppire_dict_init,
-      };
-
-      static const GInterfaceInfo tree_model_info = {
-       (GInterfaceInitFunc) dictionary_tree_model_init,
-       NULL,
-       NULL
-      };
-
-      static const GInterfaceInfo list_model_info = {
-       (GInterfaceInitFunc) ssw_init_iface,
-       NULL,
-       NULL
-      };
-
-      object_type = g_type_register_static (G_TYPE_OBJECT,
-                                           "PsppireDict",
-                                           &object_info, 0);
-
-      g_type_add_interface_static (object_type, GTK_TYPE_TREE_MODEL,
-                                  &tree_model_info);
-
-      g_type_add_interface_static (object_type, G_TYPE_LIST_MODEL,
-                                  &list_model_info);
-    }
-
-  return object_type;
-}
 
+G_DEFINE_TYPE_WITH_CODE (PsppireDict, psppire_dict, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
+                                               dictionary_tree_model_init)
+                        G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
+                                               ssw_init_iface))
 
 static void
 psppire_dict_class_init (PsppireDictClass *class)
@@ -390,8 +345,8 @@ psppire_dict_replace_dictionary (PsppireDict *dict, struct dictionary *d)
 
   struct dictionary *old_dict = dict->dict;
 
-  guint old_n = dict_get_var_cnt (dict->dict);
-  guint new_n = dict_get_var_cnt (d);
+  guint old_n = dict_get_n_vars (dict->dict);
+  guint new_n = dict_get_n_vars (d);
 
   dict->dict = dict_ref (d);
   dict_unref (old_dict);
@@ -483,7 +438,7 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n)
   g_return_if_fail (d);
   g_return_if_fail (d->dict);
   g_return_if_fail (PSPPIRE_IS_DICT (d));
-  size_t varcnt = dict_get_var_cnt (d->dict);
+  size_t varcnt = dict_get_n_vars (d->dict);
   g_return_if_fail (first < varcnt);
   g_return_if_fail (first >= 0);
   g_return_if_fail (n > 0);
@@ -496,17 +451,16 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n)
 gboolean
 psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name)
 {
-  struct variable *var;
   g_assert (d);
   g_assert (PSPPIRE_IS_DICT (d));
 
   if (! dict_id_is_valid (d->dict, name, false))
     return FALSE;
 
-  if (idx < dict_get_var_cnt (d->dict))
+  if (idx < dict_get_n_vars (d->dict))
     {
       /* This is an existing variable? */
-      var = dict_get_var (d->dict, idx);
+      struct variable * var = dict_get_var (d->dict, idx);
       dict_rename_var (d->dict, var, name);
     }
   else
@@ -529,7 +483,7 @@ psppire_dict_get_variable (const PsppireDict *d, gint idx)
   g_return_val_if_fail (d, NULL);
   g_return_val_if_fail (d->dict, NULL);
 
-  if (dict_get_var_cnt (d->dict) <= idx)
+  if (dict_get_n_vars (d->dict) <= idx)
     return NULL;
 
   return dict_get_var (d->dict, idx);
@@ -538,18 +492,18 @@ psppire_dict_get_variable (const PsppireDict *d, gint idx)
 
 /* Return the number of variables in the dictionary */
 gint
-psppire_dict_get_var_cnt (const PsppireDict *d)
+psppire_dict_get_n_vars (const PsppireDict *d)
 {
   g_return_val_if_fail (d, -1);
   g_return_val_if_fail (d->dict, -1);
 
-  return dict_get_var_cnt (d->dict);
+  return dict_get_n_vars (d->dict);
 }
 
 
 /* Return the number of `union value's in the dictionary */
 size_t
-psppire_dict_get_value_cnt (const PsppireDict *d)
+psppire_dict_get_n_values (const PsppireDict *d)
 {
   g_return_val_if_fail (d, -1);
   g_return_val_if_fail (d->dict, -1);
@@ -760,7 +714,7 @@ tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path)
 
   n = indices [0];
 
-  if (n < 0 || n >= psppire_dict_get_var_cnt (dict))
+  if (n < 0 || n >= psppire_dict_get_n_vars (dict))
     {
       iter->stamp = 0;
       iter->user_data = NULL;
@@ -794,7 +748,7 @@ tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter)
 
   idx = var_get_dict_index (var);
 
-  if (idx + 1 >= psppire_dict_get_var_cnt (dict))
+  if (idx + 1 >= psppire_dict_get_n_vars (dict))
     {
       iter->user_data = NULL;
       iter->stamp = 0;
@@ -902,7 +856,7 @@ tree_model_n_children (GtkTreeModel *model,
   PsppireDict *dict = PSPPIRE_DICT (model);
 
   if (iter == NULL)
-    return psppire_dict_get_var_cnt (dict);
+    return psppire_dict_get_n_vars (dict);
 
   return 0;
 }
@@ -920,7 +874,7 @@ tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter,
   if (parent)
     return FALSE;
 
-  if (n >= psppire_dict_get_var_cnt (dict))
+  if (n >= psppire_dict_get_n_vars (dict))
     return FALSE;
 
   iter->stamp = dict->stamp;
@@ -956,29 +910,6 @@ psppire_dict_get_weight_variable (const PsppireDict *dict)
   return dict_get_weight (dict->dict);
 }
 
-
-
-#if DEBUGGING
-void
-psppire_dict_dump (const PsppireDict *dict)
-{
-  gint i;
-  const struct dictionary *d = dict->dict;
-
-  for (i = 0; i < dict_get_var_cnt (d); ++i)
-    {
-      const struct variable *v = psppire_dict_get_variable (dict, i);
-      int di = var_get_dict_index (v);
-      g_print ("`%s' idx=%d, fv=%d\n",
-              var_get_name(v),
-              di,
-              var_get_case_index(v));
-
-    }
-}
-#endif
-
-
 const gchar *
 psppire_dict_encoding (const PsppireDict *dict)
 {