Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / output / mk-class-boilerplate
1 #! /usr/bin/perl
2
3 while (<>) {
4     if (my ($class, $super) = /boilerplate for ([a-zA-Z0-9_]+), a subclass of ([a-zA-Z0-9_]+)/) {
5         while (<>) {
6             last if /\f/;
7         }
8         print <<EOF;
9 /* This boilerplate for ${class}, a subclass of ${super}, was
10    autogenerated by mk-class-boilerplate. */
11
12 #include <assert.h>
13 #include "libpspp/cast.h"
14
15 extern const struct ${super}_class ${class}_class;
16
17 /* Returns true if SUPER is a ${class}, otherwise false. */
18 static inline bool
19 is_${class} (const struct ${super} *super)
20 {
21   return super->class == &${class}_class;
22 }
23
24 /* Returns SUPER converted to ${class}.  SUPER must be a ${class}, as
25    reported by is_${class}. */
26 static inline struct ${class} *
27 to_${class} (const struct ${super} *super)
28 {
29   assert (is_${class} (super));
30   return UP_CAST (super, struct ${class}, ${super});
31 }
32
33 /* Returns INSTANCE converted to ${super}. */
34 static inline struct ${super} *
35 ${class}_super (const struct ${class} *instance)
36 {
37   return CONST_CAST (struct ${super} *, &instance->${super});
38 }
39
40 /* Increments INSTANCE's reference count and returns INSTANCE. */
41 static inline struct ${class} *
42 ${class}_ref (const struct ${class} *instance)
43 {
44   return to_${class} (${super}_ref (&instance->${super}));
45 }
46
47 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
48    the reference count is now zero. */
49 static inline void
50 ${class}_unref (struct ${class} *instance)
51 {
52   ${super}_unref (&instance->${super});
53 }
54
55 /* Returns true if INSTANCE's reference count is greater than 1,
56    false otherwise. */
57 static inline bool
58 ${class}_is_shared (const struct ${class} *instance)
59 {
60   return ${super}_is_shared (&instance->${super});
61 }
62
63 EOF
64         if ($super ne 'output_item') {
65             print <<EOF;
66 static inline void
67 ${class}_submit (struct ${class} *instance)
68 {
69   ${super}_submit (&instance->${super});
70 }
71 EOF
72         } else {
73             print "void ${class}_submit (struct ${class} *);\n";
74         }
75     }
76     print;
77 }