Back to index

lightning-sunbird  0.9+nobinonly
nsUInt32Array.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK *****
00038  * This Original Code has been modified by IBM Corporation. Modifications made by IBM 
00039  * described herein are Copyright (c) International Business Machines Corporation, 2000.
00040  * Modifications to Mozilla code or documentation identified per MPL Section 3.3
00041  *
00042  * Date             Modified by     Description of modification
00043  * 04/20/2000       IBM Corp.      OS/2 VisualAge build.
00044  */
00045 #ifndef _nsUInt32Array_H_
00046 #define _nsUInt32Array_H_
00047 
00048 #include "nscore.h"
00049 #include "nsCRT.h"
00050 #include "prmem.h"
00051 #include "msgCore.h"
00052 
00053 class NS_MSG_BASE nsUInt32Array
00054 {
00055 public:
00056   // Construction/destruction
00057   nsUInt32Array();
00058   virtual ~nsUInt32Array();
00059   
00060   // State/attribute member functions
00061   PRUint32          GetSize() const;
00062   PRBool            SetSize(PRUint32 nNewSize, PRBool AdjustGrowth=PR_FALSE, PRUint32 nGrowBy = 0);
00063   PRBool            AllocateSpace(PRUint32 nNewSize) {
00064     if (nNewSize == 0) return PR_TRUE;
00065     PRUint32 saveSize = m_nSize;
00066     nsresult rv = SetSize(nNewSize);
00067     m_nSize = saveSize;
00068     return rv;
00069   };
00070   
00071   // Accessor member functions
00072   PRUint32            &ElementAt(PRUint32 nIndex);
00073   PRUint32             GetAt(PRUint32 nIndex) const;
00074   PRUint32            *GetData();
00075   void               SetAt(PRUint32 nIndex, PRUint32 newElement);
00076   PRUint32           IndexOf(PRUint32 element);
00077   PRUint32           IndexOfSorted(PRUint32 element);
00078   
00079   // Insertion/deletion member functions
00080   PRUint32  Add(PRUint32 newElement);
00081   PRUint32          Add(PRUint32 *elementPtr, PRUint32 numElements); 
00082   void            InsertAt(PRUint32 nIndex, PRUint32 newElement, PRUint32 nCount = 1);
00083   void               InsertAt(PRUint32 nStartIndex, const nsUInt32Array *pNewArray);
00084   void               RemoveAll();
00085   void               RemoveAt(PRUint32 nIndex, PRUint32 nCount = 1);
00086   void               SetAtGrow(PRUint32 nIndex, PRUint32 newElement);
00087   PRBool             RemoveElement(PRUint32 element);
00088   // Sorting member functions
00089   void               QuickSort(int (* PR_CALLBACK compare) (const void *elem1, const void *elem2, void *) = NULL);
00090   
00091   // Overloaded operators
00092   PRUint32             operator[](PRUint32 nIndex) const { return GetAt(nIndex); }
00093   PRUint32            &operator[](PRUint32 nIndex) { return ElementAt(nIndex); }
00094   
00095   // Miscellaneous member functions
00096   PRUint32            *CloneData(); 
00097   void               CopyArray(nsUInt32Array *oldA);
00098   void               CopyArray(nsUInt32Array &oldA);
00099   
00100 protected:
00101   // Member data
00102   PRUint32 m_nSize;
00103   PRUint32 m_nMaxSize;
00104   PRUint32 m_nGrowBy;
00105   PRUint32* m_pData;
00106 };
00107 
00108 
00109 #endif // _DWordArray_H_