Debian Codegraph @

genaccessors

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 $| = 1;
7
8 my %struct = ( 'AI::FANN' => 'struct fann *',
9 'AI::FANN::TrainData' => 'struct fann_train_data *' );
10
11 sub accessor {
12 my ($name, $type, $getter, $setter, @ixs) = @_;
13
14 my ($package, $method) = $name =~ /^(?:(.*)::)?(.*)$/
15 or die "wrong accessor name $name";
16
17 $package = $package ? "AI::FANN::$package" : 'AI::FANN';
18 my $struct = $struct{$package}
19 or die "wrong package name $package";
20
21 push @ixs, 'value' unless grep /^value$/, @ixs;
22 my @ixs1 = grep !/^value$/, @ixs;
23
24 my $nixs = @ixs;
25
26 my $types = join("\n ", "$struct self;", map "unsigned int $_;", @ixs1);
27 my $args = join(', ', 'self', @ixs1);
28 my $setargs = join(', ', 'self', @ixs);
29
30 if ($getter) {
31 if ($getter =~ /^->/) {
32 $getter = "self->$getter"
33 }
34 else {
35 $getter = "$getter($args)"
36 }
37 }
38
39 if ($setter) {
40 if ($setter =~ /^->/) {
41 $setter = "self->$setter = value"
42 }
43 else {
44 $setter = "$setter($setargs)"
45 }
46 }
47
48
49 print <<HEAD;
50
51 MODULE = AI::FANN PACKAGE = $package PREFIX = accessor_
52 HEAD
53
54 if ($setter and $getter) {
55 print <<EOA
56
57 $type
58 accessor_$method($args, value = NO_INIT)
59 $types
60 $type value
61 CODE:
62 if (items > $nixs) {
63 $setter;
64 }
65 RETVAL = $getter;
66 OUTPUT:
67 RETVAL
68 EOA
69
70 }
71 elsif ($getter) {
72 print <<EOA;
73
74 $type
75 accessor_$method($args)
76 $types
77 CODE:
78 RETVAL = $getter;
79 OUTPUT:
80 RETVAL
81 EOA
82
83 }
84 elsif ($setter) {
85 print <<EOA;
86 void
87 accessor_$method($args, value)
88 $types
89 $type value;
90 CODE:
91 $setter;
92 EOA
93
94 }
95 else {
96 die "both setter and getter are null"
97 }
98
99 print <<EOA;
100 CLEANUP:
101 _check_error(aTHX_ (struct fann_error *)self);
102
103 EOA
104 }
105
106
107 while(<DATA>) {
108 chomp;
109 next if /^\s*(?:#.*)?$/;
110 my (@args) = split /\s*,\s*/;
111 @args > 2 or die "wrong number of arguments: $_";
112
113 accessor(@args);
114 }
115
116 __DATA__
117
118 training_algorithm, enum fann_train_enum, fann_get_training_algorithm, fann_set_training_algorithm
119 train_error_function, enum fann_errorfunc_enum, fann_get_train_error_function, fann_set_train_error_function
120 train_stop_function, enum fann_stopfunc_enum, fann_get_train_stop_function, fann_set_train_stop_function
121 learning_rate, double, fann_get_learning_rate, fann_set_learning_rate
122 learning_momentum, double, fann_get_learning_momentum, fann_set_learning_momentum
123 bit_fail_limit, fann_type, fann_get_bit_fail_limit, fann_set_bit_fail_limit
124 quickprop_decay, double, fann_get_quickprop_decay, fann_set_quickprop_decay
125 quickprop_mu, double, fann_get_quickprop_mu, fann_set_quickprop_mu
126 rprop_increase_factor, double, fann_get_rprop_increase_factor, fann_set_rprop_increase_factor
127 rprop_decrease_factor, double, fann_get_rprop_decrease_factor, fann_set_rprop_decrease_factor
128 rprop_delta_min, double, fann_get_rprop_delta_min, fann_set_rprop_delta_min
129 rprop_delta_max, double, fann_get_rprop_delta_max, fann_set_rprop_delta_max
130 num_inputs, unsigned int, fann_get_num_input
131 num_outputs, unsigned int, fann_get_num_output
132 total_neurons, unsigned int, fann_get_total_neurons
133 total_connections, unsigned int, fann_get_total_connections
134 connection_rate, double, fann_get_connection_rate
135 MSE, double, fann_get_MSE
136 bit_fail, unsigned int, fann_get_bit_fail
137 cascade_output_change_fraction, double, fann_get_cascade_output_change_fraction, fann_set_cascade_output_change_fraction
138 cascade_output_stagnation_epochs, double, fann_get_cascade_output_stagnation_epochs, fann_set_cascade_output_stagnation_epochs
139 cascade_candidate_change_fraction, double, fann_get_cascade_candidate_change_fraction, fann_set_cascade_candidate_change_fraction
140 cascade_candidate_stagnation_epochs, unsigned int, fann_get_cascade_candidate_stagnation_epochs, fann_set_cascade_candidate_stagnation_epochs
141 cascade_weight_multiplier, fann_type, fann_get_cascade_weight_multiplier, fann_set_cascade_weight_multiplier
142 cascade_candidate_limit, fann_type, fann_get_cascade_candidate_limit, fann_set_cascade_candidate_limit
143 cascade_max_out_epochs, unsigned int, fann_get_cascade_max_out_epochs, fann_set_cascade_max_out_epochs
144 cascade_max_cand_epochs, unsigned int, fann_get_cascade_max_cand_epochs, fann_set_cascade_max_cand_epochs
145 cascade_num_candidates, unsigned int, fann_get_cascade_num_candidates
146 cascade_num_candidate_groups, unsigned int, fann_get_cascade_num_candidate_groups, fann_set_cascade_num_candidate_groups
147 neuron_activation_function, enum fann_activationfunc_enum, fann_get_activation_function, fann_set_activation_function, value, layer, neuron_index
148 layer_activation_function, enum fann_activationfunc_enum, , fann_set_activation_function_layer, value, layer
149 hidden_activation_function, enum fann_activationfunc_enum, , fann_set_activation_function_hidden
150 output_activation_function, enum fann_activationfunc_enum, , fann_set_activation_function_output
151 neuron_activation_steepness, fann_type, fann_get_activation_steepness, fann_set_activation_steepness, value, layer, neuron
152 layer_activation_steepness, fann_type, , fann_set_activation_steepness_layer, value, layer
153 hidden_activation_steepness, fann_type, , fann_set_activation_steepness_hidden
154 output_activation_steepness, fann_type, , fann_set_activation_steepness_output
155 layer_num_neurons, unsigned int, fann_get_num_neurons, , layer
156 num_layers, unsigned int, fann_get_num_layers
157
158 # neuron, struct fann_neuron *, fann_get_neuron, , layer, neuron_index
159
160 TrainData::num_inputs, unsigned int, fann_train_data_num_input
161 TrainData::num_outputs, unsigned int, fann_train_data_num_output
162 TrainData::length, unsigned int, fann_train_data_length
163