/*H+ TTGenericArray.h
*
*    SCCS ID: %Z%%M% %I% %E% SMI
*
*    Copyright (c) 1990-1993 Sun Microsystems, Inc.  All rights reserved.
*    See SUN_LEGAL_NOTICE file for terms of the license.
*
*    PURPOSE:
*
*    Defines the TTGenericArray class.
*
*    AUTHOR: Mark Soloway
*
*    REVISION HISTORY:
*
*    Who       When       Why                   
*    --------- ---------- -----------------------
*    MGS       09/10/90   Original creation.
*    MGS       01/27/92   Make SVR4 compatible.
*
*H-*/

/*C+ TTGenericArray
*
*    DESCRIPTION:
*
*    The TTGenericArray class provides a way to create polymorphic arrays
*    of any object sub-classed off of the TTGeneric object class.
*    The array can have objects added to it, deleted from it, accessed
*    randomly, traversed in order, and have other arrays appended to it.
*    When the array is deleted via the delete operator, delete is called
*    on each of the items in the array.
*
*    INHERITED CLASSES:
*
*    TTGeneric - Inheriting the TTGeneric class will allow the TTGenericArray
*                class to be treated as a TTGeneric object.  Therefore,
*                a TTGenericArray can contain a TTGenericArray.
*
*    ORDINARY DATA MEMBERS:
*
*    int         growSize     - The amount to grow the physical size
*                               when it is exceeded.
*    TTGeneric **array         - The actual array of objects.
*    int         numItems     - The number of items in the array.
*    int         physicalSize - The current size of allocated memory holding
*			        the array.
*    int         position     - The current traversal position.
*
*    PUBLIC MEMBER FUNCTIONS:
*
*    void setGrowSize (int)      - Sets the grow size of the physical memory
*                                  of the array if the number of items
*				   exceeds the current physical size of the
*				   array.
*    void addItem (TTGeneric *)  - Adds the specified item to the end of
*                                  the array.
*    TTGeneric *removeItem (int) - Removes and returns the specified item from
*                                  the array.
*    void removeItem (const TTGeneric *)
*                                - Removes the item from the array that matches
*                                  the specified pointer.
*    TTGeneric *getItem (int) const
*                                - Gets the specified item from the array.
*    int findItem (const TTGeneric *) const
*                                - Finds the item that matches the specified
*                                  pointer and returns the position number.
*    TTGeneric *traverse (TTBoolean reset_flag)
*                                - Traverses the array.  If the reset flag
*                                  is set, traversal starts at the beginning
*                                  of the array.
*    void clear ()               - Clears the array and destroys each item
*                                  in the array.
*    void dropItems ()           - Drops the items from the array without
*                                  destroying each item.
*    int getSize () const        - Returns the number of items in the array.
*    TTGenericArray &operator= (const TTGenericArray&)
*                                - Allows assignment of one array to another.
*    TTGeneric* &operator[] (int) const
*                                - Allows access to the specified item in
*                                  the array.  The array entry can be read and
*                                  modified.
*    TTGenericArray operator+ (const TTGenericArray&)
*                                - Concatenates two arrays.
*
*C-*/
#ifndef _TT_GENERIC_ARRAY_H
#define _TT_GENERIC_ARRAY_H

// Includes
#include <stddef.h>

#include "TTBoolean.h"
#include "TTGeneric.h"

// Class Definition
class TTGenericArray : public TTGeneric {
public:
  TTGenericArray () { growSize = 10;
		     array = (TTGeneric **) NULL;
		     numItems = 0;
		     physicalSize = 0;
		     position = 0; }
  TTGenericArray (const TTGenericArray& l);
  ~TTGenericArray () { if (numItems) {
                        for (int i=0; i < numItems; i++)
		  	delete array [i];
		        delete array;
		      }
		    }

  void	          setGrowSize (int grow_size) { if (grow_size > 0)
					          growSize = grow_size;
					      }
  void            addItem (TTGeneric *);
  TTGeneric      *removeItem (int);
  void	          removeItem (const TTGeneric *);
  TTGeneric      *getItem (int) const;
  int             findItem (const TTGeneric *) const;
  TTGeneric      *traverse (TTBoolean);
  void            clear () { numItems = 0;
			     physicalSize = 0;
			     position = 0;
			     delete [] array;
			     array = (TTGeneric **) NULL;
			   }
  void            dropItems () { numItems = 0;
			         physicalSize = 0;
			         position = 0;
			         delete array;
			         array = (TTGeneric **) NULL;
			       }
  int             getSize () const { return numItems; }
  TTGenericArray &operator= (const TTGenericArray&);
  TTGeneric*     &operator[] (int) const;
  TTGenericArray  operator+ (const TTGenericArray&);

private:
  int         growSize;
  TTGeneric **array;
  int         numItems;
  int         physicalSize;
  int         position;
};

#endif /* _TT_GENERIC_ARRAY_H */
