Class-STL-Containers
view release on metacpan or search on metacpan
docs/class-stl-containers.pod view on Meta::CPAN
# $result now contains (1, 2, 3, 4, 5, 6, 7, 8, 9);
# Vector container...
my $v = stl::vector(qw(first second third fourth fifth));
my $e = $v->at(0); # return pointer to first element.
print 'Element-0:', $e->data(), "\n"; # Element-0:first
$e = $v->at($v->size()-1); # return pointer to last element.
print 'Element-last:', $e->data(), "\n"; # Element-last:fifth
$e = $v->at(2); # return pointer to 3rd element (idx=2).
print 'Element-2:', $e->data(), "\n"; # Element-2:third
# Priority Queue
my $p = stl::priority_queue();
$p->push($p->factory(priority => 10, data => 'ten'));
$p->push($p->factory(priority => 2, data => 'two'));
$p->push($p->factory(priority => 12, data => 'twelve'));
$p->push($p->factory(priority => 3, data => 'three'));
$p->push($p->factory(priority => 11, data => 'eleven'));
$p->push($p->factory(priority => 1, data => 'one'));
$p->push($p->factory(priority => 1, data => 'one-2'));
$p->push($p->factory(priority => 12, data => 'twelve-2'));
$p->push($p->factory(priority => 20, data => 'twenty'), $p->factory(priority => 0, data => 'zero'));
print "\$p->size()=", $p->size(), "\n";
print "\$p->top():", $p->top(), "\n";
$p->top()->priority(7); # change priority for top element.
$p->refresh(); # refresh required after priority change.
$p->pop(); # remove element with highest priority.
print "\$p->top():", $p->top(), "\n";
# Clone $d container into $d1...
my $d1 = $d->clone();
my $d2 = stl::deque(qw(sixth seventh eight));
# Append $d container to end of $d2 container...
$d2 += $d;
# DataMembers -- Class builder helper...
{
package MyClass;
use Class::STL::ClassMembers (
qw(attrib1 attrib2), # data members
Class::STL::ClassMembers::DataMember->new(
name => 'attrib3', default => '100', validate => '^\d+$'), # data member with attributes
Class::STL::ClassMembers::DataMember->new(
name => 'attrib4', default => 'med', validate => '^(high|med|low)$'),
);
use Class::STL::ClassMembers::Constructor; # produce class new() function
}
my $cl = MyClass->new(attrib1 => 'hello', attrib2 => 'world');
print $cl->attrib1(), " ", $cl->attrib2(), "\n"; # 'hello world'
$cl->attrib1(ucfirst($cl->attrib1));
$cl->attrib2(ucfirst($cl->attrib2));
print $cl->attrib1(), " ", $cl->attrib2(), "\n"; # 'Hello World'
$cl->attrib4('avg'); # Causes progam to die with '** Function attrib2 value failed validation...'
=head1 DESCRIPTION
This package provides a framework for rapid Object Oriented Perl application development. It consists of a number of base classes that are similar to the C++/STL framework, plus a number of I<helper> classes which provide the I<glue> to transparently...
The I<STL> functionality provided consists of F<containers>, F<algorithms>, F<utilities> and F<iterators> as follows:
=item F<Containers>
vector, list, deque, queue, priority_queue, stack, tree.
=item F<Iterators>
iterator, bidirectional_iterator, reverse_iterator, forward_iterator.
=item F<Algorithms>
find, find_if, for_each, transform, count, count_if, copy, copy_backward, remove, remove_if, remove_copy, remove_copy_if, replace, replace_if, replace_copy, replace_copy_if.
=item F<Utilities>
equal_to, not_equal_to, greater, greater_equal, less, less_equal, compare, bind1st, bind2nd, mem_fun, ptr_fun, ptr_fun_binary, matches, matches_ic, logical_and, logical_or, multiplies, divides, plus, minus, modulus.
=head2 F<Differences From C++/STL>
Most of the functions have the same arguments and return types as their STL equivalent. There are some differences though between the C++/STL and this implementation:
=item Iterators and the I<end()> function
An I<iterator> object points to a numeric position within the container, and not to an I<element>. If new elements are inserted to, or removed from, a postion preceding the iterator, then the iterator will point to the same I<position> but to a diffe...
The I<end> function will return a newly constructed iterator object which will point to the I<last> element within the container, unlike the C++/STL equivalent which points to I<after> the last element.
=item The I<tree> Container
This container provides a hierarchical tree structure. Each element within a I<tree> container can be either a simple element or another container object. The I<algorithms> and overridden I<to_array> functions will traverse the tree and pocess all el...
=item Utilities I<matches>, I<matches_ic> functions
These utilities provide unary functions for regular expression matching. The first or second argument will be a regular expression string. The I<match_ic> provides case insensitive matching.
=item Container I<append> function
This function and the overridden C<+>, C<+=> operators will combine the two containers together.
=item The I<clone> function
This function returns a newly constructed object that is a copy of its caller object.
=item The Container I<to_array> function
( run in 2.597 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )