sbSelectionListUtils.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://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 
27 #include "sbSelectionListUtils.h"
28 
29 #include <nsTArray.h>
30 #include <nsIObjectOutputStream.h>
31 
32 PLDHashOperator PR_CALLBACK
33 SB_SerializeSelectionListCallback(nsStringHashKey::KeyType aKey,
34  nsString aEntry,
35  void* aUserData)
36 {
37  NS_ASSERTION(aUserData, "Null userData!");
38 
39  nsIObjectOutputStream* stream =
40  static_cast<nsIObjectOutputStream*>(aUserData);
41  NS_ASSERTION(stream, "Could not cast user data");
42 
43  nsresult rv;
44  rv = stream->WriteWStringZ(aKey.BeginReading());
45  NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
46 
47  rv = stream->WriteWStringZ(aEntry.BeginReading());
48  NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
49 
50  return PL_DHASH_NEXT;
51 }
52 
53 PLDHashOperator PR_CALLBACK
54 SB_CopySelectionListCallback(nsStringHashKey::KeyType aKey,
55  nsString aEntry,
56  void* aUserData)
57 {
58  NS_ASSERTION(aUserData, "Null userData!");
59 
60  sbSelectionList* list =
61  static_cast<sbSelectionList*>(aUserData);
62  NS_ASSERTION(list, "Could not cast user data");
63 
64  PRBool success = list->Put(aKey, aEntry);
65  NS_ENSURE_TRUE(success, PL_DHASH_STOP);
66 
67  return PL_DHASH_NEXT;
68 }
69 
70 PLDHashOperator PR_CALLBACK
71 SB_SelectionListGuidsToTArrayCallback(nsStringHashKey::KeyType aKey,
72  nsString aEntry,
73  void* aUserData)
74 {
75  NS_ASSERTION(aUserData, "Null userData!");
76 
77  nsTArray<nsString>* list = static_cast<nsTArray<nsString>*>(aUserData);
78  NS_ASSERTION(list, "Could not cast user data");
79 
80  nsString* appended = list->AppendElement(aEntry);
81  NS_ENSURE_TRUE(appended, PL_DHASH_STOP);
82 
83  return PL_DHASH_NEXT;
84 }
nsDataHashtable< nsStringHashKey, nsString > sbSelectionList
PLDHashOperator PR_CALLBACK SB_SelectionListGuidsToTArrayCallback(nsStringHashKey::KeyType aKey, nsString aEntry, void *aUserData)
PLDHashOperator PR_CALLBACK SB_CopySelectionListCallback(nsStringHashKey::KeyType aKey, nsString aEntry, void *aUserData)
PLDHashOperator PR_CALLBACK SB_SerializeSelectionListCallback(nsStringHashKey::KeyType aKey, nsString aEntry, void *aUserData)