Source: bag.h


Annotated List
Files
Globals
Hierarchy
Index
// ##########################################################################
// ####                                                                  ####
// ####                      RTP Audio Server Project                    ####
// ####                    ============================                  ####
// ####                                                                  ####
// #### Bag Template                                                     ####
// ####                                                                  ####
// #### Version 1.00  --  February 04, 2001                              ####
// ####                                                                  ####
// #### Copyright (C) 1999  Thomas Dreibholz                             ####
// ####               2000  Universität Bonn, Abt. IV                    ####
// ####               2001  EMail: Dreibholz@bigfoot.com                 ####
// ####                     WWW:   http://www.bigfoot.com/~dreibholz     ####
// ####                                                                  ####
// ##########################################################################


#ifndef BAG_H
#define BAG_H


#include "system.h"


/**
  * Internal structure for Bag template.
  */
template<class T> struct BagNode {
   BagNode<T>* Prev;
   BagNode<T>* Next;
   T            Element;
};


/**
  * This class implements the Bag datatype template.
  *
  * @short   Bag
  * @author  Thomas Dreibholz (Dreibholz@bigfoot.com)
  * @version 1.0
  */
template<class T> class Bag
{
   // ====== Constructor/Destructor =========================================
   public:
   /**
     * Constructor.
     */
   Bag();
   
   /**
     * Destructor.
     */
   ~Bag();


   // ====== Element add/remove/test functions ==============================
   /**
     * Add element to head of bag.
     *
     * @param element Element to be added.
     * @return true, if element has been added; false, if not.
     */
   bool addHead(T element);

   /**
     * Add element to tail of bag.
     *
     * @param element Element to be added.
     * @return true, if element has been added; false, if not.
     */
   bool addTail(T element);

   /**
     * Remove element from bag.
     *
     * @param element Element to be removed.
     */
   void remove(T element);

   /**
     * Remove first element from bag.
     */
   inline void removeHead();

   /**
     * Remove last element from bag.
     */
   inline void removeTail();

   /**
     * Check, if bag contains an element.
     *
     * @param element Element to be checked to be in the bag.
     */
   inline bool contains(const T& element) const;

   /**
     * Get number of elements in the bag.
     *
     * @return Number of elements.
     */
   inline cardinal getCount() const;

   
   // ====== Bag iteration functions ========================================
   /**
     * Get first element. If true is returned, the given reference will be a
     * reference to the element.
     *
     * @param element Reference to hold the element's reference.
     * @return true, if the reference is valid.
     */
   inline bool first(T& element);

   /**
     * Get last element. If true is returned, the given reference will be a
     * reference to the element.
     *
     * @param element Reference to hold the element's reference.
     * @return true, if the reference is valid.
     */
   inline bool last(T& element);

   /**
     * Get next element. If true is returned, the given reference will be a
     * reference to the element.
     *
     * @param element Reference to hold the element's reference.
     * @return true, if the reference is valid.
     */
   inline bool next(T& element);

   /**
     * Get previous element. If true is returned, the given reference will be a
     * reference to the element.
     *
     * @param element Reference to hold the element's reference.
     * @return true, if the reference is valid.
     */
   inline bool prev(T& element);


   // ====== Protected data =================================================
   protected:
   /**
     * Get BagNode for an element.
     *
     * @param element Element.
     * @return Pointer to BagNode or NULL, if element is not in the bag.
     */
   BagNode<T>* findNode(const T& element) const;
   
   /**
     * Remove a BagNode.
     *
     * @param node BagNode to be removed.
     */
   void removeNode(BagNode<T>* node);


   // ====== Private data ===================================================
   private:
   cardinal    Count;
   BagNode<T>  FirstNode;
   BagNode<T>* Pointer;
};


#include "bag.icc"
#include "bag.cc"


#endif

Generated by: viper@odin on Sun Feb 4 18:54:51 2001, using kdoc 2.0a22.