PageRenderTime 36ms CodeModel.GetById 29ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

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