line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2010 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Gtk2-Ex-TiedListColumn. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Gtk2-Ex-TiedListColumn is free software; you can redistribute it and/or |
6
|
|
|
|
|
|
|
# modify it under the terms of the GNU General Public License as published |
7
|
|
|
|
|
|
|
# by the Free Software Foundation; either version 3, or (at your option) any |
8
|
|
|
|
|
|
|
# later version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Gtk2-Ex-TiedListColumn is distributed in the hope that it will be useful, |
11
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
13
|
|
|
|
|
|
|
# Public License for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Gtk2-Ex-TiedListColumn. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Gtk2::Ex::TiedTreePath; |
20
|
2
|
|
|
2
|
|
1667
|
use 5.008; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
73
|
|
21
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
22
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1984
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = 5; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
27
|
|
|
|
|
|
|
#use Smart::Comments; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
0
|
|
|
0
|
1
|
|
my ($class, $path) = @_; |
31
|
0
|
|
|
|
|
|
tie (my @array, $class, $path); |
32
|
0
|
|
|
|
|
|
return \@array; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub TIEARRAY { |
36
|
0
|
|
|
0
|
|
|
my ($class, $path) = @_; |
37
|
0
|
|
|
|
|
|
return bless \$path, $class; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
# optional, not needed |
40
|
|
|
|
|
|
|
# sub UNTIE { } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# tied object method |
43
|
|
|
|
|
|
|
sub path { |
44
|
0
|
|
|
0
|
1
|
|
return ${$_[0]}; |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# negative indices already normalized to >=0 by the time they get here |
48
|
|
|
|
|
|
|
sub FETCH { |
49
|
0
|
|
|
0
|
|
|
my ($self, $index) = @_; |
50
|
|
|
|
|
|
|
### TiedTreePath FETCH: $index |
51
|
0
|
|
|
|
|
|
return (($$self)->get_indices)[$index]; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# negative indices already normalized to >=0 by the time they get here |
55
|
|
|
|
|
|
|
sub STORE { |
56
|
0
|
|
|
0
|
|
|
my ($self, $index, $value) = @_; |
57
|
|
|
|
|
|
|
### TiedTreePath STORE: [$index, $value] |
58
|
0
|
|
|
|
|
|
my $path = $$self; |
59
|
0
|
|
|
|
|
|
my $depth = $path->get_depth; |
60
|
0
|
0
|
|
|
|
|
if ($index >= $depth) { |
61
|
0
|
|
|
|
|
|
foreach ($depth .. $index-1) { |
62
|
0
|
|
|
|
|
|
$path->append_index (0); |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
$path->append_index ($value); |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
my @array = $path->get_indices; |
67
|
0
|
|
|
|
|
|
foreach ($index .. $depth-1) { |
68
|
0
|
|
|
|
|
|
$path->up; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
$path->append_index ($value); |
71
|
0
|
|
|
|
|
|
foreach my $i ($index+1 .. $depth-1) { |
72
|
0
|
|
|
|
|
|
$path->append_index ($array[$i]); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _path_clear { |
78
|
0
|
|
|
0
|
|
|
my ($path) = @_; |
79
|
0
|
|
|
|
|
|
while ($path->up) {} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
sub _path_set_indices { |
82
|
0
|
|
|
0
|
|
|
my $path = shift; |
83
|
0
|
|
|
|
|
|
_path_clear ($path); |
84
|
0
|
|
|
|
|
|
while (@_) { $path->append_index (shift @_); } |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub FETCHSIZE { |
88
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
89
|
|
|
|
|
|
|
### TiedTreePath FETCHSIZE |
90
|
0
|
|
|
|
|
|
return ($$self)->get_depth; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# big negative sizes normalized to 0 by the time they get here |
94
|
|
|
|
|
|
|
sub STORESIZE { |
95
|
0
|
|
|
0
|
|
|
my ($self, $want_size) = @_; |
96
|
|
|
|
|
|
|
### TiedTreePath STORESIZE: $want_size |
97
|
0
|
|
|
|
|
|
my $path = $$self; |
98
|
0
|
|
|
|
|
|
my $depth = $path->get_depth; |
99
|
0
|
|
|
|
|
|
foreach ($want_size .. $depth-1) { # shorten |
100
|
0
|
|
|
|
|
|
$path->up; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
foreach ($depth .. $want_size-1) { # lengthen |
103
|
0
|
|
|
|
|
|
$path->append_index (0); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
0
|
|
|
sub EXTEND { |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# negative indices already normalized to >=0 by the time they get here |
111
|
|
|
|
|
|
|
sub EXISTS { |
112
|
0
|
|
|
0
|
|
|
my ($self, $index) = @_; |
113
|
|
|
|
|
|
|
### TiedTreePath EXISTS: $index |
114
|
0
|
|
|
|
|
|
return ($index < ($$self)->get_depth); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# normalized to 0 <= $index <= FETCHSIZE-1 by the time get here |
118
|
|
|
|
|
|
|
sub DELETE { |
119
|
0
|
|
|
0
|
|
|
my ($self, $index) = @_; |
120
|
|
|
|
|
|
|
### TiedTreePath DELETE: $index |
121
|
0
|
|
|
|
|
|
my $path = $$self; |
122
|
0
|
|
|
|
|
|
my $ret; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if ($index < (my $depth = $path->get_depth)) { |
125
|
0
|
|
|
|
|
|
$ret = ($path->get_indices)[$index]; |
126
|
0
|
0
|
|
|
|
|
if ($index == $depth-1) { |
127
|
0
|
|
|
|
|
|
$path->up; |
128
|
|
|
|
|
|
|
} else { |
129
|
0
|
|
|
|
|
|
$self->STORE ($index, 0); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
0
|
|
|
|
|
|
return $ret; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub CLEAR { |
136
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
137
|
|
|
|
|
|
|
### TiedTreePath CLEAR |
138
|
0
|
|
|
|
|
|
_path_clear ($$self); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub PUSH { |
142
|
0
|
|
|
0
|
|
|
my $self = shift; |
143
|
0
|
|
|
|
|
|
my $path = $$self; |
144
|
0
|
|
|
|
|
|
while (@_) { |
145
|
0
|
|
|
|
|
|
$path->append_index (shift @_); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub POP { |
150
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
151
|
|
|
|
|
|
|
### TiedTreePath POP |
152
|
0
|
|
|
|
|
|
my $path = $$self; |
153
|
0
|
|
|
|
|
|
my $ret = ($path->get_indices)[-1]; |
154
|
0
|
|
|
|
|
|
$path->up; |
155
|
0
|
|
|
|
|
|
return $ret; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub SHIFT { |
159
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
160
|
|
|
|
|
|
|
### TiedTreePath SHIFT |
161
|
0
|
|
|
|
|
|
my $path = $$self; |
162
|
0
|
|
|
|
|
|
my @array = $path->get_indices; |
163
|
0
|
0
|
|
|
|
|
if (! @array) { return; } |
|
0
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $ret = shift @array; |
165
|
|
|
|
|
|
|
### $ret |
166
|
0
|
|
|
|
|
|
_path_set_indices ($path, @array); |
167
|
0
|
|
|
|
|
|
return $ret; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# don't have to return the new size here, FETCHSIZE is called separately |
171
|
|
|
|
|
|
|
sub UNSHIFT { |
172
|
0
|
|
|
0
|
|
|
my $self = shift; |
173
|
|
|
|
|
|
|
### TiedTreePath UNSHIFT |
174
|
0
|
|
|
|
|
|
my $path = $$self; |
175
|
0
|
|
|
|
|
|
push @_, $path->get_indices; |
176
|
0
|
|
|
|
|
|
_path_set_indices ($path, @_); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub SPLICE { |
180
|
0
|
|
|
0
|
|
|
my $self = shift; |
181
|
0
|
|
|
|
|
|
my $offset = shift; |
182
|
0
|
|
|
|
|
|
my $length = shift; |
183
|
|
|
|
|
|
|
### TiedTreePath SPLICE: [$offset,$length] |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my $path = $$self; |
186
|
0
|
|
|
|
|
|
my @array = $path->get_indices; |
187
|
0
|
0
|
|
|
|
|
if (wantarray) { |
188
|
0
|
|
|
|
|
|
my @ret = splice @array, $offset, $length, @_; |
189
|
0
|
|
|
|
|
|
_path_set_indices ($path, @array); |
190
|
0
|
|
|
|
|
|
return @ret; |
191
|
|
|
|
|
|
|
} else { |
192
|
0
|
|
|
|
|
|
my $ret = splice @array, $offset, $length, @_; |
193
|
0
|
|
|
|
|
|
_path_set_indices ($path, @array); |
194
|
0
|
|
|
|
|
|
return $ret; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |
199
|
|
|
|
|
|
|
__END__ |