a97b2270d6f1d1cc055a244ed04c4e0f6d1952ed
[pspp-builds.git] / src / output / message-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2010 Free Sonftware 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_MESSAGE_ITEM_H
18 #define OUTPUT_MESSAGE_ITEM_H 1
19
20 /* Message items.
21
22    A message item is a subclass of an output item (see
23    output/output-item.h).
24
25    A message item is an error, warning, or note to the user.
26
27    Message items should not be submitted directly to the output subsystem.
28    Instead, use the msg() function in libpspp/message.h, which will ensure that
29    the message gets routed properly for the PSPP user interface in use. */
30
31 #include <stdbool.h>
32 #include <output/output-item.h>
33
34 /* A message item. */
35 struct message_item
36   {
37     struct output_item output_item;
38     struct msg *msg;
39   };
40
41 struct message_item *message_item_create (const struct msg *);
42
43 const struct msg *message_item_get_msg (const struct message_item *);
44 \f
45 /* This boilerplate for message_item, a subclass of output_item, was
46    autogenerated by mk-class-boilerplate. */
47
48 #include <assert.h>
49 #include <libpspp/cast.h>
50
51 extern const struct output_item_class message_item_class;
52
53 /* Returns true if SUPER is a message_item, otherwise false. */
54 static inline bool
55 is_message_item (const struct output_item *super)
56 {
57   return super->class == &message_item_class;
58 }
59
60 /* Returns SUPER converted to message_item.  SUPER must be a message_item, as
61    reported by is_message_item. */
62 static inline struct message_item *
63 to_message_item (const struct output_item *super)
64 {
65   assert (is_message_item (super));
66   return UP_CAST (super, struct message_item, output_item);
67 }
68
69 /* Returns INSTANCE converted to output_item. */
70 static inline struct output_item *
71 message_item_super (const struct message_item *instance)
72 {
73   return CONST_CAST (struct output_item *, &instance->output_item);
74 }
75
76 /* Increments INSTANCE's reference count and returns INSTANCE. */
77 static inline struct message_item *
78 message_item_ref (const struct message_item *instance)
79 {
80   return to_message_item (output_item_ref (&instance->output_item));
81 }
82
83 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
84    the reference count is now zero. */
85 static inline void
86 message_item_unref (struct message_item *instance)
87 {
88   output_item_unref (&instance->output_item);
89 }
90
91 /* Returns true if INSTANCE's reference count is greater than 1,
92    false otherwise. */
93 static inline bool
94 message_item_is_shared (const struct message_item *instance)
95 {
96   return output_item_is_shared (&instance->output_item);
97 }
98
99 void message_item_submit (struct message_item *);
100 \f
101 #endif /* output/message-item.h */