casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
casa::ListIter< t > Class Template Reference

Doubly linked non-constant list iterator The List class above only provides for the list framework. More...

#include <List.h>

Inheritance diagram for casa::ListIter< t >:
casa::ConstListIter< t > casa::NoticeTarget

List of all members.

Public Member Functions

 ListIter (List< t > *st, Bool OWN=False)
 This constructor allows one to construct a ListIter and attach it to the List parameter.
 ListIter (List< t > &st)
 This constructor allows one to construct a ListIter and attach it to the List parameter.
 ListIter (const ListIter< t > &other)
 These constructors allow for the creation of a ListIter from another ListIter.
 ListIter (const ListIter< t > *other)
 ListIter ()
 This is the default constructor.
void addRight (t e)
 This function adds the element to the right of the current cursor position.
void removeRight ()
 This function removes the element to the right of the current cursor position.
virtual void swapRight (ListIter< t > &)
 This function swaps the list section after the current position of the list with the right section of the list of another iterator.
t & getRight ()
 Returns the element to the right of the cursor.
const t & getRight () const
 Returns the element to the right of the cursor.
virtual ListIter< t > & assign (List< t > *other, Bool OWN=False)
 This function changes the List which this ListIter tracks and specifies that the List should be deleted when this iterator is deleted.
virtual ListIter< t > & operator= (List< t > &other)
 This assignment operator changes the List which this iterator tracks to the List parameter.
virtual ListIter< t > & operator= (List< t > *other)
virtual ListIter< t > & operator= (const ListIter< t > &other)
 These assignment operators allow one to change the List to which this iterator tracks to the List currently associated with the argument ListIter.
virtual ListIter< t > & operator= (const ListIter< t > *other)
 ~ListIter ()
 
     

Protected Member Functions

virtual Link< t > * newLink (t &e, Link< t > *p=0, Link< t > *n=0)

Protected Attributes

Bool own
 Indicates if this iterator "owns" the container it observes.

Private Member Functions

ConstListIter< t > & operator= (const List< t > &)
 This assignment operator substitutes the "List<t>" tracked by this iterator to the "List<t>" passed as an argument.
ConstListIter< t > & operator= (const List< t > *)
ConstListIter< t > & operator= (const ConstListIter< t > &)
 This assignment operator substitutes the "List<t>" tracked by this iterator to the "List<t>" tracked by the passed "ConstListIter<t>" argument.
ConstListIter< t > & operator= (const ConstListIter< t > *)

Detailed Description

template<class t>
class casa::ListIter< t >

Doubly linked non-constant list iterator The List class above only provides for the list framework.

This is one of two classes which allow list iteration, insertion, and removal. This class can be used to modify a list. Unlike ConstListIter , this class can insert and remove elements from a list as well as look at or observe a list. ConstListIter should be used whenever the list is not modified.

All of the operations take place to the right of a conceptual cursor. The cursor starts out before the first element of the list and can be incremented past the last element of the list. Going further than the end of the list results in an exception. All additions and deletions occur to the right of this conceptual cursor. In addition, this class uses the Notice class to ensure that multiple iterators which are observing the same list are updated as the list changes. This is important when multiple iterators are used.

Example

    #include <casa/Containers/List.h>
    #include <casa/Containers/ListIO.h>
   
    main() {
                                                // The conceptual cursors are:
                                                //   |  for one
                                                //   ^  for two
                                                //   _  for three
        ListIter<int> one(new List<int>,True);
        ListIter<int> three, two = one;
        one.addRight(12);                       //  |^ 12
        one.addRight(2);                        //  |^ 2 12
        one.addRight(89);                       //  |^ 89 2 12
        cout << one.getRight() << " " 
             << two.getRight() << endl;
        two.addRight(21);                       //  |^ 21 89 2 12
        cout << one.getRight() << " " 
             << two.getRight() << endl;
        one++; two++; two++;                    //   21 | 89 ^ 2 12
        three = one;                            //   21 |_ 89 ^ 2 12
        one.removeRight();                      //   21 |^_ 2 12
        cout << one.getRight() << " " 
             << two.getRight() << " "
             << three.getRight() << endl;
        three.addRight(17);                     //   21 |^_ 17 2 12
   
        cout << one.getRight() << " " 
             << two.getRight() << " "
             << three.getRight() << endl;
   
        one.toEnd();                            //   21 ^_ 17 2 12 |
        one.addRight(18);                       //   21 ^_ 17 2 12 | 18
        two.pos(3);                             //   21 _ 17 2 ^ 12 | 18
        three--;                                //   _ 21 17 2 ^ 12 | 18
        two.step();                             //   _ 21 17 2 12 ^| 18
        one.step(4);                            //   _ 21 17 | 2 12 ^ 18
        cout << "one:   " << one << endl;
        cout << "two:   " << two << endl;
        cout << "three: " << three << endl;
   
        return 0;
    }

The output from this example would look like:

              89 89
              21 21
              2 2 2
              17 2 17
              one:   len=5 pos=2 21 17 2 12 18
              two:   len=5 pos=4 21 17 2 12 18
              three: len=5 pos=0 21 17 2 12 18
        


Tip: This class uses the "Notice" classes to implement "dynamic" cursors so that multiple cursors are updated as elements are added and removed from the list;

Definition at line 603 of file List.h.


Constructor & Destructor Documentation

template<class t>
casa::ListIter< t >::ListIter ( List< t > *  st,
Bool  OWN = False 
) [inline]

This constructor allows one to construct a ListIter and attach it to the List parameter.

The own flag can be set to indicate that the List should be destroyed when the ListIter is deleted.

Definition at line 612 of file List.h.

template<class t>
casa::ListIter< t >::ListIter ( List< t > &  st)

This constructor allows one to construct a ListIter and attach it to the List parameter.

template<class t>
casa::ListIter< t >::ListIter ( const ListIter< t > &  other)

These constructors allow for the creation of a ListIter from another ListIter.

This will attach this ListIter to the List tracked by the ListIter parameter at the time of construction.

template<class t>
casa::ListIter< t >::ListIter ( const ListIter< t > *  other) [inline]

Definition at line 628 of file List.h.

template<class t>
casa::ListIter< t >::ListIter ( ) [inline]

This is the default constructor.

It allows one to create an initially invalid empty ListIter. The instantiated class will accept assignment and thus become valid later.

Definition at line 636 of file List.h.

template<class t>
casa::ListIter< t >::~ListIter ( )

     


Member Function Documentation

template<class t>
void casa::ListIter< t >::addRight ( e) [inline]

This function adds the element to the right of the current cursor position.

Allow container to update

Definition at line 643 of file List.h.

template<class t>
virtual ListIter<t>& casa::ListIter< t >::assign ( List< t > *  other,
Bool  OWN = False 
) [virtual]

This function changes the List which this ListIter tracks and specifies that the List should be deleted when this iterator is deleted.

template<class t>
t& casa::ListIter< t >::getRight ( ) [inline]

Returns the element to the right of the cursor.

Definition at line 675 of file List.h.

template<class t>
const t& casa::ListIter< t >::getRight ( ) const [inline]

Returns the element to the right of the cursor.

Reimplemented from casa::ConstListIter< t >.

Definition at line 680 of file List.h.

template<class t>
virtual Link<t>* casa::ListIter< t >::newLink ( t &  e,
Link< t > *  p = 0,
Link< t > *  n = 0 
) [protected, virtual]
template<class t>
virtual ListIter<t>& casa::ListIter< t >::operator= ( List< t > &  other) [virtual]

This assignment operator changes the List which this iterator tracks to the List parameter.

template<class t>
virtual ListIter<t>& casa::ListIter< t >::operator= ( List< t > *  other) [virtual]
template<class t>
virtual ListIter<t>& casa::ListIter< t >::operator= ( const ListIter< t > &  other) [virtual]

These assignment operators allow one to change the List to which this iterator tracks to the List currently associated with the argument ListIter.

template<class t>
virtual ListIter<t>& casa::ListIter< t >::operator= ( const ListIter< t > *  other) [virtual]
template<class t>
ConstListIter<t>& casa::ListIter< t >::operator= ( const List< t > &  other) [private, virtual]

This assignment operator substitutes the "List<t>" tracked by this iterator to the "List<t>" passed as an argument.

Reimplemented from casa::ConstListIter< t >.

template<class t>
ConstListIter<t>& casa::ListIter< t >::operator= ( const List< t > *  ) [private, virtual]

Reimplemented from casa::ConstListIter< t >.

template<class t>
ConstListIter<t>& casa::ListIter< t >::operator= ( const ConstListIter< t > &  other) [private, virtual]

This assignment operator substitutes the "List<t>" tracked by this iterator to the "List<t>" tracked by the passed "ConstListIter<t>" argument.

Reimplemented from casa::ConstListIter< t >.

template<class t>
ConstListIter<t>& casa::ListIter< t >::operator= ( const ConstListIter< t > *  ) [private, virtual]

Reimplemented from casa::ConstListIter< t >.

template<class t>
void casa::ListIter< t >::removeRight ( )

This function removes the element to the right of the current cursor position.

template<class t>
virtual void casa::ListIter< t >::swapRight ( ListIter< t > &  ) [virtual]

This function swaps the list section after the current position of the list with the right section of the list of another iterator.

This can be particularly useful for "remembering" the position of a cursor in a list.


Member Data Documentation

template<class t>
Bool casa::ListIter< t >::own [protected]

Indicates if this iterator "owns" the container it observes.

Definition at line 723 of file List.h.


The documentation for this class was generated from the following file: