diff options
Diffstat (limited to 'lib/VarnishMib/HashTable.pm')
-rw-r--r-- | lib/VarnishMib/HashTable.pm | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/lib/VarnishMib/HashTable.pm b/lib/VarnishMib/HashTable.pm index 0f3b47e..1faef96 100644 --- a/lib/VarnishMib/HashTable.pm +++ b/lib/VarnishMib/HashTable.pm @@ -150,2 +150,16 @@ sub create { +=head2 format_input_table + + $ht->format_input_table([FILEHANDLE]); + +Outputs to I<FILEHANDLE> (default B<STDOUT>) a C array of input names. The +array is declared as + + char const *PFXname_table[] + +where I<PFX> is replaced by the prefix given when creating the HashTable +object. + +=cut + sub format_input_table { @@ -154,3 +168,3 @@ sub format_input_table { croak "no input data to format" unless $self->{input}; - print $fh 'char const *' . $self->{prefix} . "name_table[] = {\n"; + print $fh 'static char const *' . $self->{prefix} . "name_table[] = {\n"; foreach my $name (@{$self->{input}}) { @@ -162,2 +176,17 @@ sub format_input_table { +=head2 format_data_table + + $ht->format_data_table(CTYPE [, FILEHANDLE]) + +Outputs a C array of data associated with input strings. The array is declared +as + + CTYPE PFXdata_table[N]; + +where I<CTYPE> is the first parameter to the method, I<PFX> is the prefix and +I<N> is the dimension (number of strings for which the hash table is built). +Both B<name_table> and B<data_table> have the same dimension. + +=cut + sub format_data_table { @@ -167,5 +196,19 @@ sub format_data_table { my $n = @{$self->{input}}; - print $fh $type . ' ' . $self->{prefix} . "data_table[$n];\n"; + print $fh 'static '. $type . ' ' . $self->{prefix} . "data_table[$n];\n"; } +=head2 format_hash_table + + $ht->format_hash_table([FILEHANDLE]); + + +Outputs the hash table to I<FILEHANDLE> (B<STDOUT> by default). The table +is declared as + + int PFXhash_table[] + +where I<PFX> is the prefix. + +=cut + sub format_hash_table { @@ -188,2 +231,17 @@ sub format_hash_table { +=head2 format_code + + $ht->format_code([FILEHANDLE]) + +Formats the supporting C code to the I<FILEHANDLE> (B<STDOUT>, if not given). +The code contains at least the following function: + + unsigned string_hash(const char *str, unsigned size) + +which, given the string I<str> and the size of the hash table (I<size>) +returns the index in the table starting from which the pointer to that +string and associated data can be located. + +=cut + sub format_code { |