1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is String Enumerator.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
23 * Alec Flett <alecf@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsIStringEnumerator.h"
40 #include "nsVoidArray.h"
42 // nsIStringEnumerator/nsIUTF8StringEnumerator implementations
44 // Currently all implementations support both interfaces. The
45 // constructors below provide the most common interface for the given
46 // type (i.e. nsIStringEnumerator for PRUnichar* strings, and so
47 // forth) but any resulting enumerators can be queried to the other
48 // type. Internally, the enumerators will hold onto the type that was
49 // passed in and do conversion if GetNext() for the other type of
52 // There are a few different types of enumerators:
55 // These enumerators hold a pointer to the array. Be careful
56 // because modifying the array may confuse the iterator, especially if
57 // you insert or remove elements in the middle of the array.
60 // The non-adopting enumerator requires that the array sticks around
61 // at least as long as the enumerator does. These are for constant
62 // string arrays that the enumerator does not own, this could be used
63 // in VERY specialized cases such as when the provider KNOWS that the
64 // string enumerator will be consumed immediately, or will at least
68 // nsCStringArray array;
69 // array.AppendCString("abc");
70 // array.AppendCString("def");
71 // NS_NewStringEnumerator(&enumerator, &array, PR_TRUE);
73 // // call some internal method which iterates the enumerator
74 // InternalMethod(enumerator);
75 // NS_RELEASE(enumerator);
78 NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator
** aResult
,
79 const nsCStringArray
* aArray
);
82 NS_NewStringEnumerator(nsIStringEnumerator
** aResult
,
83 const nsStringArray
* aArray
);
85 // Adopting string enumerators assume ownership of the array and will
86 // call |operator delete| on the array when the enumerator is destroyed
87 // this is useful when the provider creates an array solely for the
88 // purpose of creating the enumerator.
91 // nsCStringArray* array = new nsCStringArray;
92 // array->AppendString("abcd");
93 // NS_NewAdoptingStringEnumerator(&result, array);
95 NS_NewAdoptingStringEnumerator(nsIStringEnumerator
** aResult
,
96 nsStringArray
* aArray
);
99 NS_NewAdoptingUTF8StringEnumerator(nsIUTF8StringEnumerator
** aResult
,
100 nsCStringArray
* aArray
);
103 // these versions take a refcounted "owner" which will be addreffed
104 // when the enumerator is created, and destroyed when the enumerator
105 // is released. This allows providers to give non-owning pointers to
106 // ns*StringArray member variables without worrying about lifetime
110 // nsresult MyClass::Enumerate(nsIUTF8StringEnumerator** aResult) {
111 // mCategoryList->AppendString("abcd");
112 // return NS_NewStringEnumerator(aResult, mCategoryList, this);
116 NS_NewStringEnumerator(nsIStringEnumerator
** aResult
,
117 const nsStringArray
* aArray
,
118 nsISupports
* aOwner
);
120 NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator
** aResult
,
121 const nsCStringArray
* aArray
,
122 nsISupports
* aOwner
);