dictionary: Make dict_get_weight_format() return by value, not pointer.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 25 Feb 2023 02:46:48 +0000 (18:46 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 25 Feb 2023 03:01:35 +0000 (19:01 -0800)
This seems like a better interface.

src/data/dictionary.c
src/data/dictionary.h
src/language/commands/crosstabs.c
src/language/commands/jonckheere-terpstra.c
src/language/commands/ks-one-sample.c
src/language/commands/npar-summary.c
src/language/commands/npar-summary.h
src/language/commands/oneway.c
src/output/pivot-table.c
src/output/pivot-table.h

index a2a622c93765cef2cbfef731d7961d6f05d650e7..800bad9463523fbc8e2b1b00f4ef66cc21966c0f 100644 (file)
@@ -1315,10 +1315,10 @@ dict_get_rounded_case_weight (const struct dictionary *d,
 }
 
 /* Returns the format to use for weights. */
-const struct fmt_spec *
+struct fmt_spec
 dict_get_weight_format (const struct dictionary *d)
 {
-  return d->weight ? var_get_print_format (d->weight) : &F_8_0;
+  return d->weight ? *var_get_print_format (d->weight) : F_8_0;
 }
 
 /* Sets the weighting variable of D to V, or turning off
index f709f11dd99324e1b45cae40186bc40296543988..e1d67ee7049ec131e883a334ec46e06a78f4c531 100644 (file)
@@ -102,7 +102,7 @@ double dict_get_rounded_case_weight (const struct dictionary *,
                                      const struct ccase *, bool *);
 struct variable *dict_get_weight (const struct dictionary *);
 void dict_set_weight (struct dictionary *, struct variable *);
-const struct fmt_spec *dict_get_weight_format (const struct dictionary *);
+struct fmt_spec dict_get_weight_format (const struct dictionary *);
 
 /* Filter variable. */
 struct variable *dict_get_filter (const struct dictionary *);
index 72579b0b972a17b7be971b8e92e943dd1daccfdc..0ed8452dc574d76069bdad43433387fa8a20ff7a 100644 (file)
@@ -288,7 +288,7 @@ cmd_crosstabs (struct lexer *lexer, struct dataset *ds)
     .exclude = MV_ANY,
     .barchart = false,
     .bad_warn = true,
-    .weight_format = *dict_get_weight_format (dataset_dict (ds)),
+    .weight_format = dict_get_weight_format (dataset_dict (ds)),
 
     .variables = NULL,
     .n_variables = 0,
@@ -1385,7 +1385,7 @@ create_crosstab_table (struct crosstabs_proc *proc, struct crosstabulation *xt,
   struct pivot_table *table = pivot_table_create__ (
     pivot_value_new_user_text_nocopy (ds_steal_cstr (&title)),
     "Crosstabulation");
-  pivot_table_set_weight_format (table, &proc->weight_format);
+  pivot_table_set_weight_format (table, proc->weight_format);
 
   struct pivot_dimension *statistics = pivot_dimension_create (
     table, PIVOT_AXIS_ROW, N_("Statistics"));
@@ -1419,7 +1419,7 @@ static struct pivot_table *
 create_chisq_table (struct crosstabulation *xt)
 {
   struct pivot_table *chisq = pivot_table_create (N_("Chi-Square Tests"));
-  pivot_table_set_weight_format (chisq, &xt->weight_format);
+  pivot_table_set_weight_format (chisq, xt->weight_format);
 
   pivot_dimension_create (
     chisq, PIVOT_AXIS_ROW, N_("Statistics"),
@@ -1449,7 +1449,7 @@ static struct pivot_table *
 create_sym_table (struct crosstabulation *xt)
 {
   struct pivot_table *sym = pivot_table_create (N_("Symmetric Measures"));
-  pivot_table_set_weight_format (sym, &xt->weight_format);
+  pivot_table_set_weight_format (sym, xt->weight_format);
 
   pivot_dimension_create (
     sym, PIVOT_AXIS_COLUMN, N_("Values"),
@@ -1488,7 +1488,7 @@ create_risk_table (struct crosstabulation *xt,
                    struct pivot_dimension **risk_statistics)
 {
   struct pivot_table *risk = pivot_table_create (N_("Risk Estimate"));
-  pivot_table_set_weight_format (risk, &xt->weight_format);
+  pivot_table_set_weight_format (risk, xt->weight_format);
 
   struct pivot_dimension *values = pivot_dimension_create (
     risk, PIVOT_AXIS_COLUMN, N_("Values"),
@@ -1534,7 +1534,7 @@ static struct pivot_table *
 create_direct_table (struct crosstabulation *xt)
 {
   struct pivot_table *direct = pivot_table_create (N_("Directional Measures"));
-  pivot_table_set_weight_format (direct, &xt->weight_format);
+  pivot_table_set_weight_format (direct, xt->weight_format);
 
   pivot_dimension_create (
     direct, PIVOT_AXIS_COLUMN, N_("Values"),
index 7d654bbecbff4ef86155abbdb354578c09366ef4..b0385fa577bc5fba89fdac23734c6fcddb5666f3 100644 (file)
@@ -222,7 +222,7 @@ struct jt
 };
 
 static void show_jt (const struct n_sample_test *, const struct jt *,
-                     const struct fmt_spec *wfmt);
+                     const struct fmt_spec wfmt);
 
 
 void
@@ -350,7 +350,7 @@ jonckheere_terpstra_execute (const struct dataset *ds,
 \f
 static void
 show_jt (const struct n_sample_test *nst, const struct jt *jt,
-         const struct fmt_spec *wfmt)
+         const struct fmt_spec wfmt)
 {
   struct pivot_table *table = pivot_table_create (
     N_("Jonckheere-Terpstra Test"));
index f02b9309c3ef39045cadf2f065f4625a27ac91f1..b3e250aea8b010c5f6d3e995be2fc3f22626eadb 100644 (file)
@@ -126,7 +126,7 @@ ks_asymp_sig (double z)
     }
 }
 
-static void show_results (const struct ks *, const struct ks_one_sample_test *,  const struct fmt_spec *);
+static void show_results (const struct ks *, const struct ks_one_sample_test *,  const struct fmt_spec);
 
 
 void
@@ -140,7 +140,7 @@ ks_one_sample_execute (const struct dataset *ds,
   const struct ks_one_sample_test *kst = UP_CAST (test, const struct ks_one_sample_test, parent.parent);
   const struct one_sample_test *ost = &kst->parent;
   struct ccase *c;
-  const struct fmt_spec *wfmt = dict_get_weight_format (dict);
+  const struct fmt_spec wfmt = dict_get_weight_format (dict);
   bool warn = true;
   int v;
   struct casereader *r = casereader_clone (input);
@@ -268,7 +268,7 @@ ks_one_sample_execute (const struct dataset *ds,
 static void
 show_results (const struct ks *ks,
              const struct ks_one_sample_test *kst,
-             const struct fmt_spec *wfmt)
+             const struct fmt_spec wfmt)
 {
   struct pivot_table *table = pivot_table_create (
     N_("One-Sample Kolmogorov-Smirnov Test"));
index fddf30639ebba7d2539c284d56ac1e741df84900..08a678df8368e70bfa30112f716afe763d4be9aa 100644 (file)
@@ -93,7 +93,7 @@ void
 do_summary_box (const struct descriptives *desc,
                const struct variable *const *vv,
                int n_vars,
-                const struct fmt_spec *wfmt)
+                const struct fmt_spec wfmt)
 {
   if (!desc)
     return;
index 3955bd64119d054ff6318b7b97849fce14b5edb0..003cf89e9f86ef6fda55c41eda0a3bc07cb03398 100644 (file)
@@ -37,7 +37,7 @@ void
 do_summary_box (const struct descriptives *desc,
                const struct variable *const *vv,
                int n_vars,
-                const struct fmt_spec *wfmt);
+                const struct fmt_spec wfmt);
 
 void npar_summary_calc_descriptives (struct descriptives *desc,
                                     struct casereader *input,
index 49b06c73d292582c07abc3f9ba8ff8cda817b1be..ba4e1c1395006eca0637ef39bb8e6a36123f0f80 100644 (file)
@@ -139,7 +139,7 @@ struct oneway_spec
 
   /* The weight variable */
   const struct variable *wv;
-  const struct fmt_spec *wfmt;
+  const struct fmt_spec wfmt;
 
   /* The confidence level for multiple comparisons */
   double alpha;
index bec8638bd03a037a3a096b2209968e6d0999486e..c6197beb04dde747307cc757169b00836f69a8cc 100644 (file)
@@ -1368,19 +1368,17 @@ pivot_table_set_weight_var (struct pivot_table *table,
                             const struct variable *wv)
 {
   if (wv)
-    pivot_table_set_weight_format (table, var_get_print_format (wv));
+    pivot_table_set_weight_format (table, *var_get_print_format (wv));
 }
 
 /* Sets the format used for PIVOT_RC_COUNT cells to WFMT, which should be the
-   format for the dictionary whose data or statistics are being put into TABLE.
-
-   This has no effect if WFMT is NULL. */
+   format for the dictionary whose data or statistics are being put into
+   TABLE. */
 void
 pivot_table_set_weight_format (struct pivot_table *table,
-                               const struct fmt_spec *wfmt)
+                               const struct fmt_spec wfmt)
 {
-  if (wfmt)
-    table->weight_format = *wfmt;
+  table->weight_format = wfmt;
 }
 
 /* Returns true if TABLE has no cells, false otherwise. */
index 145e356cf3ef83a0a869e25e78fef4a0be29eb80..c52c7654b1c7c0e17a43ab3612151263d39db667 100644 (file)
@@ -577,7 +577,7 @@ void pivot_table_set_look (struct pivot_table *,
 void pivot_table_set_weight_var (struct pivot_table *,
                                  const struct variable *);
 void pivot_table_set_weight_format (struct pivot_table *,
-                                    const struct fmt_spec *);
+                                    const struct fmt_spec);
 
 /* Query. */
 bool pivot_table_is_empty (const struct pivot_table *);