Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsIStringEnumerator.h" |
michael@0 | 7 | #include "nsStringFwd.h" |
michael@0 | 8 | #include "nsTArrayForwardDeclare.h" |
michael@0 | 9 | |
michael@0 | 10 | // nsIStringEnumerator/nsIUTF8StringEnumerator implementations |
michael@0 | 11 | // |
michael@0 | 12 | // Currently all implementations support both interfaces. The |
michael@0 | 13 | // constructors below provide the most common interface for the given |
michael@0 | 14 | // type (i.e. nsIStringEnumerator for char16_t* strings, and so |
michael@0 | 15 | // forth) but any resulting enumerators can be queried to the other |
michael@0 | 16 | // type. Internally, the enumerators will hold onto the type that was |
michael@0 | 17 | // passed in and do conversion if GetNext() for the other type of |
michael@0 | 18 | // string is called. |
michael@0 | 19 | |
michael@0 | 20 | // There are a few different types of enumerators: |
michael@0 | 21 | |
michael@0 | 22 | // |
michael@0 | 23 | // These enumerators hold a pointer to the array. Be careful |
michael@0 | 24 | // because modifying the array may confuse the iterator, especially if |
michael@0 | 25 | // you insert or remove elements in the middle of the array. |
michael@0 | 26 | // |
michael@0 | 27 | |
michael@0 | 28 | // The non-adopting enumerator requires that the array sticks around |
michael@0 | 29 | // at least as long as the enumerator does. These are for constant |
michael@0 | 30 | // string arrays that the enumerator does not own, this could be used |
michael@0 | 31 | // in VERY specialized cases such as when the provider KNOWS that the |
michael@0 | 32 | // string enumerator will be consumed immediately, or will at least |
michael@0 | 33 | // outlast the array. |
michael@0 | 34 | // For example: |
michael@0 | 35 | // |
michael@0 | 36 | // nsTArray<nsCString> array; |
michael@0 | 37 | // array.AppendCString("abc"); |
michael@0 | 38 | // array.AppendCString("def"); |
michael@0 | 39 | // NS_NewStringEnumerator(&enumerator, &array, true); |
michael@0 | 40 | // |
michael@0 | 41 | // // call some internal method which iterates the enumerator |
michael@0 | 42 | // InternalMethod(enumerator); |
michael@0 | 43 | // NS_RELEASE(enumerator); |
michael@0 | 44 | // |
michael@0 | 45 | nsresult |
michael@0 | 46 | NS_NewStringEnumerator(nsIStringEnumerator** aResult, |
michael@0 | 47 | const nsTArray<nsString>* aArray, |
michael@0 | 48 | nsISupports* aOwner); |
michael@0 | 49 | nsresult |
michael@0 | 50 | NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult, |
michael@0 | 51 | const nsTArray<nsCString>* aArray); |
michael@0 | 52 | |
michael@0 | 53 | nsresult |
michael@0 | 54 | NS_NewStringEnumerator(nsIStringEnumerator** aResult, |
michael@0 | 55 | const nsTArray<nsString>* aArray); |
michael@0 | 56 | |
michael@0 | 57 | // Adopting string enumerators assume ownership of the array and will |
michael@0 | 58 | // call |operator delete| on the array when the enumerator is destroyed |
michael@0 | 59 | // this is useful when the provider creates an array solely for the |
michael@0 | 60 | // purpose of creating the enumerator. |
michael@0 | 61 | // For example: |
michael@0 | 62 | // |
michael@0 | 63 | // nsTArray<nsCString>* array = new nsTArray<nsCString>; |
michael@0 | 64 | // array->AppendString("abcd"); |
michael@0 | 65 | // NS_NewAdoptingStringEnumerator(&result, array); |
michael@0 | 66 | nsresult |
michael@0 | 67 | NS_NewAdoptingStringEnumerator(nsIStringEnumerator** aResult, |
michael@0 | 68 | nsTArray<nsString>* aArray); |
michael@0 | 69 | |
michael@0 | 70 | nsresult |
michael@0 | 71 | NS_NewAdoptingUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult, |
michael@0 | 72 | nsTArray<nsCString>* aArray); |
michael@0 | 73 | |
michael@0 | 74 | |
michael@0 | 75 | // these versions take a refcounted "owner" which will be addreffed |
michael@0 | 76 | // when the enumerator is created, and destroyed when the enumerator |
michael@0 | 77 | // is released. This allows providers to give non-owning pointers to |
michael@0 | 78 | // ns*StringArray member variables without worrying about lifetime |
michael@0 | 79 | // issues |
michael@0 | 80 | // For example: |
michael@0 | 81 | // |
michael@0 | 82 | // nsresult MyClass::Enumerate(nsIUTF8StringEnumerator** aResult) { |
michael@0 | 83 | // mCategoryList->AppendString("abcd"); |
michael@0 | 84 | // return NS_NewStringEnumerator(aResult, mCategoryList, this); |
michael@0 | 85 | // } |
michael@0 | 86 | // |
michael@0 | 87 | nsresult |
michael@0 | 88 | NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult, |
michael@0 | 89 | const nsTArray<nsCString>* aArray, |
michael@0 | 90 | nsISupports* aOwner); |