str: Add function xstrdup_if_nonnull() and introduce many users.
[pspp] / src / output / output-item-provider.h
index a810f97c7d2627ae60bc49631b4554c68e408ebe..552549cee9eaa54fee0288fd2b5dc9877f49c637 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -17,7 +17,8 @@
 #ifndef OUTPUT_ITEM_PROVIDER_H
 #define OUTPUT_ITEM_PROVIDER_H 1
 
-#include <output/output-item.h>
+#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 */