PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/perl/Choicetool/Data/Tuple.pm

#
Perl | 90 lines | 46 code | 23 blank | 21 comment | 1 complexity | b9ff28c40f84b690b4938a9b4b52328c MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- perl -*-
  2. #
  3. # Tuple.pm
  4. #
  5. # Copyright (C) 2008, 2009 Francesco Salvestrini
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. package Choicetool::Data::Tuple;
  22. use 5.8.0;
  23. use warnings;
  24. use strict;
  25. use diagnostics;
  26. use Choicetool::Base::Debug;
  27. use Choicetool::Base::Trace;
  28. sub new ($$)
  29. {
  30. my $class = shift;
  31. my $size = shift;
  32. assert(defined($class));
  33. assert(defined($size));
  34. assert($size > 0);
  35. my $self = { };
  36. $self->{SIZE} = $size;
  37. $self->{DATA} = ( );
  38. bless $self, $class;
  39. return $self;
  40. }
  41. sub clear ($)
  42. {
  43. my $self = shift;
  44. # $self->{SIZE} = $size;
  45. $self->{DATA} = ( );
  46. assert(defined($self));
  47. }
  48. sub size ($)
  49. {
  50. my $self = shift;
  51. assert(defined($self));
  52. return $self->{SIZE};
  53. }
  54. sub value
  55. {
  56. my $self = shift;
  57. my $index = shift;
  58. my $value = shift;
  59. assert(defined($self));
  60. assert(defined($index));
  61. assert($index < $self->{SIZE});
  62. if (defined($value)) {
  63. $self->{DATA}[$index] = $value;
  64. }
  65. return $self->{DATA}[$index];
  66. }
  67. 1;