Back to index

lightning-sunbird  0.9+nobinonly
nsStringEnumerator.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is String Enumerator.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corp.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alec Flett <alecf@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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 
00039 #include "nsIStringEnumerator.h"
00040 #include "nsVoidArray.h"
00041 
00042 // nsIStringEnumerator/nsIUTF8StringEnumerator implementations
00043 //
00044 // Currently all implementations support both interfaces. The
00045 // constructors below provide the most common interface for the given
00046 // type (i.e. nsIStringEnumerator for PRUnichar* strings, and so
00047 // forth) but any resulting enumerators can be queried to the other
00048 // type. Internally, the enumerators will hold onto the type that was
00049 // passed in and do conversion if GetNext() for the other type of
00050 // string is called.
00051 
00052 // There are a few different types of enumerators:
00053 
00054 //
00055 // These enumerators hold a pointer to the array. Be careful
00056 // because modifying the array may confuse the iterator, especially if
00057 // you insert or remove elements in the middle of the array.
00058 //
00059 
00060 // The non-adopting enumerator requires that the array sticks around
00061 // at least as long as the enumerator does. These are for constant
00062 // string arrays that the enumerator does not own, this could be used
00063 // in VERY specialized cases such as when the provider KNOWS that the
00064 // string enumerator will be consumed immediately, or will at least
00065 // outlast the array.
00066 // For example:
00067 //
00068 // nsCStringArray array;
00069 // array.AppendCString("abc");
00070 // array.AppendCString("def");
00071 // NS_NewStringEnumerator(&enumerator, &array, PR_TRUE);
00072 //
00073 // // call some internal method which iterates the enumerator
00074 // InternalMethod(enumerator);
00075 // NS_RELEASE(enumerator);
00076 //
00077 NS_COM nsresult
00078 NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult,
00079                            const nsCStringArray* aArray);
00080 
00081 NS_COM nsresult
00082 NS_NewStringEnumerator(nsIStringEnumerator** aResult,
00083                        const nsStringArray* aArray);
00084 
00085 // Adopting string enumerators assume ownership of the array and will
00086 // call |operator delete| on the array when the enumerator is destroyed
00087 // this is useful when the provider creates an array soley for the
00088 // purpose of creating the enumerator.
00089 // For example:
00090 //
00091 // nsCStringArray* array = new nsCStringArray;
00092 // array->AppendString("abcd");
00093 // NS_NewAdoptingStringEnumerator(&result, array);
00094 NS_COM nsresult
00095 NS_NewAdoptingStringEnumerator(nsIStringEnumerator** aResult,
00096                                nsStringArray* aArray);
00097 
00098 NS_COM nsresult
00099 NS_NewAdoptingUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult,
00100                                    nsCStringArray* aArray);
00101 
00102 
00103 // these versions take a refcounted "owner" which will be addreffed
00104 // when the enumerator is created, and destroyed when the enumerator
00105 // is released. This allows providers to give non-owning pointers to
00106 // ns*StringArray member variables without worrying about lifetime
00107 // issues
00108 // For example:
00109 //
00110 // nsresult MyClass::Enumerate(nsIUTF8StringEnumerator** aResult) {
00111 //     mCategoryList->AppendString("abcd");
00112 //     return NS_NewStringEnumerator(aResult, mCategoryList, this);
00113 // }
00114 //
00115 NS_COM nsresult
00116 NS_NewStringEnumerator(nsIStringEnumerator** aResult,
00117                        const nsStringArray* aArray,
00118                        nsISupports* aOwner);
00119 NS_COM nsresult
00120 NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult,
00121                            const nsCStringArray* aArray,
00122                            nsISupports* aOwner);