PixThanks to the work of Patrick West, libdap now has a complete
set of STL iterators that act as replacements for the aging Pix
iterators. There are new methods and types for all the classes that
act as containers (DDS, DAS, Constructor, AttrTable). Here's an
example of the old Pix code used to access things in an Structure
variable:2
Structure *structure;
BaseType *var;
Pix p = structure->first_var();
while (p) {
var = structure->var(p);
// do stuff
structure->next_var(p);
}
Here's the code rewritten using the STL iterators:
BaseType *var;
Constructor::Vars_iter p = structure->var_begin();
while (p != structure->var_end()) {
var = *p;
// do stuff
++p;
}
Some things to note:
begin() method which returns an iterator that references the
start of the contained items.
BaseType pointer that the iterator p references, use the
dereferencing operator * (i.e. var = *p; note that
var is a pointer to a BaseType).
var_end()
method. You can assign the value of var_end() to a variable
and test against that if you think the cost of calling the method
in a loop is too high.
Note that the iterators used for Structure and Sequence are defined in
their parent class Constructor while Grid, DDS,
DAS and AttrTable contain their own type definitions. Look
at the class' documentation to see which new methods replace the
`Pix methods.'
Note that Patrick also created a set of Pix adapters that enable
the old Pix types to work by adapting them to STL iterators. It's best
to treat all the Pix code as deprecated, but the adapters ease
the work by enabling you to break it up over several releases.