add new sigc++2 directory
[ardour.git] / libs / glibmm2 / tools / pm / FunctionBase.pm
1 package FunctionBase;
2
3 use strict;
4 use warnings;
5 use Util;
6
7 BEGIN {
8      use Exporter   ();
9      our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
10
11      # set the version for version checking
12      $VERSION     = 1.00;
13      @ISA         = qw(Exporter);
14      @EXPORT      = qw(&func1 &func2 &func4);
15      %EXPORT_TAGS = ( );
16      # your exported package globals go here,
17      # as well as any optionally exported functions
18      @EXPORT_OK   = qw($Var1 %Hashit &func3);
19      }
20 our @EXPORT_OK;
21
22 ##################################################
23 ### FunctionBase
24 # Contains data and methods used by both Function (C++ declarations) and GtkDefs::Function (C defs descriptions)
25 # Note that GtkDefs::Signal inherits from GtkDefs::Function so it get these methods too.
26 #
27 #  class Function : FunctionBase
28 #    {
29 #       string array param_types;
30 #       string array param_names;
31 #       string array param_documentation;
32 #       string return_documention;
33 #    }
34
35
36 # $string args_types_only($)
37 # comma-delimited argument types.
38 sub args_types_only($)
39 {
40   my ($self) = @_;
41
42   my $param_types = $$self{param_types};
43   return join(", ", @$param_types);
44 }
45
46 # $string args_names_only($)
47 sub args_names_only($)
48 {
49   my ($self) = @_;
50
51   my $param_names = $$self{param_names};
52   return join(", ", @$param_names);
53 }
54
55 # $string args_types_and_names($)
56 sub args_types_and_names($)
57 {
58   my ($self) = @_;
59
60   my $i;
61
62   my $param_names = $$self{param_names};
63   my $param_types = $$self{param_types};
64   my @out;
65
66   #debugging:
67   #if($#$param_types)
68   #{
69   #  return "NOARGS";
70   #}
71
72   for ($i = 0; $i < $#$param_types + 1; $i++)
73   {
74     my $str = sprintf("%s %s", $$param_types[$i], $$param_names[$i]);
75     push(@out, $str);
76   }
77
78   my $result =  join(", ", @out);
79   return $result;
80 }
81
82 # $string args_names_only_without_object($)
83 sub args_names_only_without_object2($)
84 {
85   my ($self) = @_;
86
87   my $param_names = $$self{param_names};
88
89   my $result = "";
90   my $bInclude = 0; #Ignore the first (object) arg.
91   foreach (@{$param_names})
92   {
93     # Add comma if there was an arg before this one:
94     if( $result ne "")
95     {
96       $result .= ", ";
97     }
98
99     # Append this arg if it's not the first one:
100     if($bInclude)
101     {
102       $result .= $_;
103     }
104
105     $bInclude = 1;
106   }
107
108   return $result;
109 }
110
111 # $string args_types_and_names_without_object($)
112 sub args_types_and_names_without_object($)
113 {
114   my ($self) = @_;
115
116   my $param_names = $$self{param_names};
117   my $param_types = $$self{param_types};
118   my $i = 0;
119   my @out;
120
121   for ($i = 1; $i < $#$param_types + 1; $i++) #Ignore the first arg.
122   {
123     my $str = sprintf("%s %s", $$param_types[$i], $$param_names[$i]);
124     push(@out, $str);
125   }
126
127   return join(", ", @out);
128 }
129
130 # $string args_names_only_without_object($)
131 sub args_names_only_without_object($)
132 {
133   my ($self) = @_;
134
135   my $param_names = $$self{param_names};
136
137   my $result = "";
138   my $bInclude = 0; #Ignore the first (object) arg.
139   foreach (@{$param_names})
140   {
141     # Add comma if there was an arg before this one:
142     if( $result ne "")
143     {
144       $result .= ", ";
145     }
146
147     # Append this arg if it's not the first one:
148     if($bInclude)
149     {
150       $result .= $_;
151     }
152
153     $bInclude = 1;
154   }
155
156   return $result;
157 }
158
159 sub dump($)
160 {
161   my ($self) = @_;
162
163   my $param_types = $$self{param_types};
164   my $param_names = $$self{param_names};
165
166   print "<function>\n";
167   foreach (keys %$self)
168   {
169     print "  <$_ value=\"$$self{$_}\"/>\n" if (!ref $$self{$_} && $$self{$_} ne "");
170   }
171
172   if (scalar(@$param_types)>0)
173   {
174     print "  <parameters>\n";
175
176     for (my $i = 0; $i < scalar(@$param_types); $i++)
177     {
178       print "    \"$$param_types[$i]\" \"$$param_names[$i]\" \n";
179     }
180
181     print "  </parameters>\n";
182   }
183
184   print "</function>\n\n";
185 }
186
187 sub args_types_and_names_with_default_values($)
188 {
189   my ($self) = @_;
190
191   my $i;
192
193   my $param_names = $$self{param_names};
194   my $param_types = $$self{param_types};
195   my $param_default_values = $$self{param_default_values};
196   my @out;
197   
198   for ($i = 0; $i < $#$param_types + 1; $i++)
199   {
200     my $str = sprintf("%s %s", $$param_types[$i], $$param_names[$i]);
201
202     if(defined($$param_default_values[$i]))
203     {
204       if($$param_default_values[$i] ne "")
205       {
206         $str .= " = " . $$param_default_values[$i];
207       }
208     }
209
210     push(@out, $str);
211   }
212
213   return join(", ", @out);
214 }
215
216 1; # indicate proper module load.
217