1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
---|
2 | *
|
---|
3 | * ***** BEGIN LICENSE BLOCK *****
|
---|
4 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
5 | *
|
---|
6 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
7 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
8 | * the License. You may obtain a copy of the License at
|
---|
9 | * http://www.mozilla.org/MPL/
|
---|
10 | *
|
---|
11 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
13 | * for the specific language governing rights and limitations under the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * The Original Code is nsValueArray.h/nsValueArray.cpp code, released
|
---|
17 | * Dec 28, 2001.
|
---|
18 | *
|
---|
19 | * The Initial Developer of the Original Code is
|
---|
20 | * Netscape Communications Corporation.
|
---|
21 | * Portions created by the Initial Developer are Copyright (C) 2001
|
---|
22 | * the Initial Developer. All Rights Reserved.
|
---|
23 | *
|
---|
24 | * Contributor(s):
|
---|
25 | * Garrett Arch Blythe, 20-December-2001
|
---|
26 | *
|
---|
27 | * Alternatively, the contents of this file may be used under the terms of
|
---|
28 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
29 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
30 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
31 | * of those above. If you wish to allow use of your version of this file only
|
---|
32 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
33 | * use your version of this file under the terms of the MPL, indicate your
|
---|
34 | * decision by deleting the provisions above and replace them with the notice
|
---|
35 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
36 | * the provisions above, a recipient may use your version of this file under
|
---|
37 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
38 | *
|
---|
39 | * ***** END LICENSE BLOCK ***** */
|
---|
40 | #ifndef nsValueArray_h___
|
---|
41 | #define nsValueArray_h___
|
---|
42 |
|
---|
43 | //
|
---|
44 | // nsValueArray.h
|
---|
45 | //
|
---|
46 | // Implement an array class to store unsigned integer values.
|
---|
47 | // The maximum value must be known up front. Once known, the
|
---|
48 | // smallest memory representation will be attempted; i.e. if the
|
---|
49 | // maximum value was 1275, then 2 bytes (uint16) would represent each value
|
---|
50 | // in the array instead of 4 bytes (uint32).
|
---|
51 | //
|
---|
52 | #include "nscore.h"
|
---|
53 |
|
---|
54 | typedef PRUint32 nsValueArrayCount;
|
---|
55 | typedef PRUint32 nsValueArrayIndex;
|
---|
56 | typedef PRUint32 nsValueArrayValue;
|
---|
57 | #define NSVALUEARRAY_INVALID ((nsValueArrayValue)-1)
|
---|
58 |
|
---|
59 | class NS_COM nsValueArray {
|
---|
60 | public:
|
---|
61 | nsValueArray(nsValueArrayValue aMaxValue,
|
---|
62 | nsValueArrayCount aInitialCapacity = 0);
|
---|
63 | ~nsValueArray();
|
---|
64 |
|
---|
65 | //
|
---|
66 | // Assignment.
|
---|
67 | //
|
---|
68 | public:
|
---|
69 | nsValueArray& operator=(const nsValueArray& other);
|
---|
70 |
|
---|
71 | //
|
---|
72 | // Array size information.
|
---|
73 | // Ability to add more values without growing is Capacity - Count.
|
---|
74 | //
|
---|
75 | public:
|
---|
76 | inline nsValueArrayCount Count() const {
|
---|
77 | return mCount;
|
---|
78 | }
|
---|
79 |
|
---|
80 | inline nsValueArrayCount Capacity() const {
|
---|
81 | return mCapacity;
|
---|
82 | }
|
---|
83 |
|
---|
84 | void Compact();
|
---|
85 |
|
---|
86 | // Removes all elements from this array
|
---|
87 | inline void Clear() {
|
---|
88 | mCount = 0;
|
---|
89 | }
|
---|
90 |
|
---|
91 | //
|
---|
92 | // Array access.
|
---|
93 | //
|
---|
94 | public:
|
---|
95 | nsValueArrayValue ValueAt(nsValueArrayIndex aIndex) const;
|
---|
96 |
|
---|
97 | inline nsValueArrayValue operator[](nsValueArrayIndex aIndex) const {
|
---|
98 | return ValueAt(aIndex);
|
---|
99 | }
|
---|
100 |
|
---|
101 | nsValueArrayIndex IndexOf(nsValueArrayValue aPossibleValue) const;
|
---|
102 |
|
---|
103 | inline PRBool AppendValue(nsValueArrayValue aValue) {
|
---|
104 | return InsertValueAt(aValue, Count());
|
---|
105 | }
|
---|
106 |
|
---|
107 | inline PRBool RemoveValue(nsValueArrayValue aValue) {
|
---|
108 | return RemoveValueAt(IndexOf(aValue));
|
---|
109 | }
|
---|
110 |
|
---|
111 | PRBool InsertValueAt(nsValueArrayValue aValue, nsValueArrayIndex aIndex);
|
---|
112 |
|
---|
113 | PRBool RemoveValueAt(nsValueArrayIndex aIndex);
|
---|
114 |
|
---|
115 | //
|
---|
116 | // Data members.
|
---|
117 | //
|
---|
118 | private:
|
---|
119 | nsValueArrayCount mCount;
|
---|
120 | nsValueArrayCount mCapacity;
|
---|
121 | PRUint8* mValueArray;
|
---|
122 | PRUint8 mBytesPerValue;
|
---|
123 | };
|
---|
124 |
|
---|
125 | #endif /* nsValueArray_h___ */
|
---|