str: Add function xstrdup_if_nonnull() and introduce many users.
[pspp] / src / output / output-item-provider.h
index 1273f13419df8819c139f7fd07a60d60ff9dfd49..552549cee9eaa54fee0288fd2b5dc9877f49c637 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef OUTPUT_ITEM_PROVIDER_H
 #define OUTPUT_ITEM_PROVIDER_H 1
 
+#include "libpspp/str.h"
 #include "output/output-item.h"
 
 /* Class structure for an output item.
    instance of output_item. */
 struct output_item_class
   {
+    /* Returns the localized label to use for ITEM.  This is only called when
+       ITEM does not have an explicitly set label, that is, when 'item->label'
+       is NULL. */
+    const char *(*get_label) (const struct output_item *item);
+
     /* Destroys and frees ITEM.  Called when output_item_unref() drops ITEM's
        reference count to 0. */
     void (*destroy) (struct output_item *item);
   };
 
-void output_item_init (struct output_item *, const struct output_item_class *);
+#define OUTPUT_ITEM_INITIALIZER(CLASS) { .class = CLASS, .ref_cnt = 1 }
+#define OUTPUT_ITEM_CLONE_INITIALIZER(SRC)                      \
+  {                                                             \
+    .class = (SRC)->class,                                      \
+    .ref_cnt = 1,                                               \
+    .label = xstrdup_if_nonnull ((SRC)->label),                 \
+  }
 
 #endif /* output/output-item-provider.h */