Prev Up Next
Go backward to 1.1 Using the factory
Go up to Top
Go forward to 3 New Methods in Connect

2 STL Iterators Versus Pix

Thanks 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:

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.


James Gallagher <jgallagher@opendap.org>, 2005-11-02, Revision: 12461

Prev Up Next