sbHashtableUtils.h
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2010 POTI, Inc.
8  * http://www.songbirdnest.com
9  *
10  * This file may be licensed under the terms of of the
11  * GNU General Public License Version 2 (the ``GPL'').
12  *
13  * Software distributed under the License is distributed
14  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
15  * express or implied. See the GPL for the specific language
16  * governing rights and limitations.
17  *
18  * You should have received a copy of the GPL along with this
19  * program. If not, go to http://www.gnu.org/licenses/gpl.html
20  * or write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  *=END SONGBIRD GPL
24  */
25 
26 #ifndef SBHASHTABLEUTILS_H_
27 #define SBHASHTABLEUTILS_H_
28 
29 #include <nsIMutableArray.h>
30 #include <nsDataHashtable.h>
31 #include <nsTArray.h>
32 
36 template <class T>
37 PLDHashOperator HashCopierEnumerator(typename T::KeyType aKey,
38  typename T::DataType aData,
39  void* userArg)
40 {
41  NS_ASSERTION(userArg, "ArrayBuilder passed a null arg");
42  typename T::Hashtable * table = reinterpret_cast<typename T::Hashtable*>(userArg);
43 
44  PRBool added = table->Put(aKey, aData);
45  NS_ENSURE_TRUE(added, PL_DHASH_STOP);
46 
47  return PL_DHASH_NEXT;
48 }
49 
64 template <class T>
65 nsresult sbCopyHashtable(typename T::Hashtable const & aSource,
66  typename T::Hashtable & aDest)
67 {
68  aSource.EnumerateRead(&HashCopierEnumerator<T>,
69  &aDest);
70 
71  return NS_OK;
72 }
73 
77 template <class E>
78 PLDHashOperator THashCOMPtrCopierToIArrayEnumerator(E* aKey,
79  void* userArg)
80 {
81  NS_ASSERTION(userArg, "ArrayBuilder passed a null arg");
82  nsIMutableArray* array =
83  reinterpret_cast<nsIMutableArray*>(userArg);
84 
85  nsresult rv = array->AppendElement(aKey->GetKey(), PR_FALSE);
86  NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
87 
88  return PL_DHASH_NEXT;
89 }
90 
94 template <class T>
95 nsresult sbCopyHashtableToArray(class nsTHashtable<T> & aSource,
96  nsIMutableArray* aDest)
97 {
98  NS_ENSURE_ARG_POINTER(aDest);
99 
100  aSource.EnumerateEntries(&THashCOMPtrCopierToIArrayEnumerator<T>,
101  aDest);
102 
103  return NS_OK;
104 }
105 
106 #endif /* SBHASHTABLEUTILS_H_ */
return NS_OK
inArray array
function E(H, I)
nsresult sbCopyHashtable(typename T::Hashtable const &aSource, typename T::Hashtable &aDest)
PLDHashOperator THashCOMPtrCopierToIArrayEnumerator(E *aKey, void *userArg)
nsresult sbCopyHashtableToArray(class nsTHashtable< T > &aSource, nsIMutableArray *aDest)
PLDHashOperator HashCopierEnumerator(typename T::KeyType aKey, typename T::DataType aData, void *userArg)
_updateTextAndScrollDataForFrame aData