output-item: Make command name part of every output_item.
[pspp] / src / output / image-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2020 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef OUTPUT_IMAGE_ITEM_H
18 #define OUTPUT_IMAGE_ITEM_H 1
19
20 #include <cairo.h>
21 #include <stdbool.h>
22 #include "output/output-item.h"
23
24 struct image_item
25   {
26     struct output_item output_item; /* Superclass */
27     cairo_surface_t *image;
28   };
29
30 struct image_item *image_item_create (cairo_surface_t *);
31 struct image_item *image_item_unshare (struct image_item *);
32 \f
33 /* This boilerplate for image_item, a subclass of output_item, was
34    autogenerated by mk-class-boilerplate. */
35
36 #include <assert.h>
37 #include "libpspp/cast.h"
38
39 extern const struct output_item_class image_item_class;
40
41 /* Returns true if SUPER is a image_item, otherwise false. */
42 static inline bool
43 is_image_item (const struct output_item *super)
44 {
45   return super->class == &image_item_class;
46 }
47
48 /* Returns SUPER converted to image_item.  SUPER must be a image_item, as
49    reported by is_image_item. */
50 static inline struct image_item *
51 to_image_item (const struct output_item *super)
52 {
53   assert (is_image_item (super));
54   return UP_CAST (super, struct image_item, output_item);
55 }
56
57 /* Returns INSTANCE converted to output_item. */
58 static inline struct output_item *
59 image_item_super (const struct image_item *instance)
60 {
61   return CONST_CAST (struct output_item *, &instance->output_item);
62 }
63
64 /* Increments INSTANCE's reference count and returns INSTANCE. */
65 static inline struct image_item *
66 image_item_ref (const struct image_item *instance)
67 {
68   return to_image_item (output_item_ref (&instance->output_item));
69 }
70
71 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
72    the reference count is now zero. */
73 static inline void
74 image_item_unref (struct image_item *instance)
75 {
76   output_item_unref (&instance->output_item);
77 }
78
79 /* Returns true if INSTANCE's reference count is greater than 1,
80    false otherwise. */
81 static inline bool
82 image_item_is_shared (const struct image_item *instance)
83 {
84   return output_item_is_shared (&instance->output_item);
85 }
86
87 void image_item_submit (struct image_item *);
88 \f
89 #endif /* output/image-item.h */