Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

PMObjectContainerIter Class Reference

Helperclass to iterate various container types of PMObjectPtr. More...

#include <PMObjectContainerIter.h>

List of all members.

Public Member Functions

template<class ObjPtr>
 PMObjectContainerIter (const std::vector< ObjPtr > &cont_r)
template<class ObjPtr>
 PMObjectContainerIter (const std::list< ObjPtr > &cont_r)
template<class ObjPtr>
 PMObjectContainerIter (const std::set< ObjPtr > &cont_r)
template<typename Tp, class ObjPtr>
 PMObjectContainerIter (const std::map< Tp, ObjPtr > &cont_r)
 PMObjectContainerIter (const PMObjectContainerIter &rhs)
PMObjectContainerIteroperator= (const PMObjectContainerIter &rhs)
 ~PMObjectContainerIter ()
void setBegin ()
void setNext ()
bool atEnd () const
PMObjectPtr operator * () const
PMObjectPtr operator-> () const
unsigned size () const
bool empty () const

Private Attributes

ContBase_cont

Classes

class  ContBase
 Iteration interface to be provided by helper classes hiding a container. More...
class  StdCont
 Helper class hiding a std::vector, list or set. More...


Detailed Description

Helperclass to iterate various container types of PMObjectPtr.

A PMObjectContainerIter allows to iterate various container classes containing PMObjectPtr or derived classes. The concrete container to iterate is passed as const & to the constructor and hidden inside a pivate helper class.

The public interface allows to iterate all PMObjectPtr stored in the container whithout need to know the concrete containers type.

Example:

 void DoSomething( PMObjectContainerIter iter_r )
 {
   if ( iter_r.size() == 0 )
     return; // container is empty
   for ( iter_r.setBegin(); !iter_r.atEnd(); iter_r.setNext() ) {
     PMObjectPtr elem = *iter_r;
     // do something with elem
   }
 }
 ...
 {
   std::list<PMObjectPtr> objlist;
   std::set<PMPackagePtr> pkgset;  // PMPackagePtr inherits PMObjectPtr
   ...
   DoSomething( objlist );
   DoSomething( pkgset );
   ...
 }
 

Adding a new container type is quite simple.class PMObjectContainerIter::ContBase defines the interface any helper class must provide. Create, or use an appropriate existing, helper class derived from PMObjectContainerIter::ContBase. Provide a constructor that takes the new container type as argument, creates the helper class from it, and stores it in _cont.


Constructor & Destructor Documentation

template<class ObjPtr>
PMObjectContainerIter::PMObjectContainerIter const std::vector< ObjPtr > &  cont_r  )  [inline]
 

template<class ObjPtr>
PMObjectContainerIter::PMObjectContainerIter const std::list< ObjPtr > &  cont_r  )  [inline]
 

template<class ObjPtr>
PMObjectContainerIter::PMObjectContainerIter const std::set< ObjPtr > &  cont_r  )  [inline]
 

template<typename Tp, class ObjPtr>
PMObjectContainerIter::PMObjectContainerIter const std::map< Tp, ObjPtr > &  cont_r  )  [inline]
 

PMObjectContainerIter::PMObjectContainerIter const PMObjectContainerIter rhs  )  [inline]
 

PMObjectContainerIter::~PMObjectContainerIter  )  [inline]
 


Member Function Documentation

bool PMObjectContainerIter::atEnd  )  const [inline]
 

Return true if the iterator reached the end of the container.

bool PMObjectContainerIter::empty  )  const [inline]
 

Return true if the container is empty.

PMObjectPtr PMObjectContainerIter::operator *  )  const [inline]
 

Return the PMObjectPtr located at the current iterator position. If atEnd() is true, the behaviour is undefined.

PMObjectPtr PMObjectContainerIter::operator->  )  const [inline]
 

Access the PMObject referenced by the PMObjectPtr located at the current iterator position. If atEnd() is true, the behaviour is undefined. It's a shortcut for (*iter)->.

Keep in mind that operator ->is special. The PMObjectPtr returned is in fact an intermediate result to which the base semantics of -> is then applied, yielding a result.

PMObjectContainerIter& PMObjectContainerIter::operator= const PMObjectContainerIter rhs  )  [inline]
 

void PMObjectContainerIter::setBegin  )  [inline]
 

Set iterator to the fist element.

void PMObjectContainerIter::setNext  )  [inline]
 

Advance iterator to next element.

unsigned PMObjectContainerIter::size  )  const [inline]
 

Return the containers size.


Member Data Documentation

ContBase* PMObjectContainerIter::_cont [private]
 


The documentation for this class was generated from the following file:
Generated on Mon Sep 12 21:52:14 2005 for yast2-packagemanager by  doxygen 1.4.4