/src/mozilla-central/xpcom/ds/nsProperties.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "nsProperties.h" |
8 | | |
9 | | //////////////////////////////////////////////////////////////////////////////// |
10 | | |
11 | | NS_IMPL_AGGREGATED(nsProperties) |
12 | 0 | NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties) |
13 | 0 | NS_INTERFACE_MAP_ENTRY(nsIProperties) |
14 | 0 | NS_INTERFACE_MAP_END |
15 | | |
16 | | NS_IMETHODIMP |
17 | | nsProperties::Get(const char* prop, const nsIID& uuid, void** result) |
18 | 0 | { |
19 | 0 | if (NS_WARN_IF(!prop)) { |
20 | 0 | return NS_ERROR_INVALID_ARG; |
21 | 0 | } |
22 | 0 | |
23 | 0 | nsCOMPtr<nsISupports> value; |
24 | 0 | if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) { |
25 | 0 | return NS_ERROR_FAILURE; |
26 | 0 | } |
27 | 0 | return (value) ? value->QueryInterface(uuid, result) : NS_ERROR_NO_INTERFACE; |
28 | 0 | } |
29 | | |
30 | | NS_IMETHODIMP |
31 | | nsProperties::Set(const char* prop, nsISupports* value) |
32 | 0 | { |
33 | 0 | if (NS_WARN_IF(!prop)) { |
34 | 0 | return NS_ERROR_INVALID_ARG; |
35 | 0 | } |
36 | 0 | Put(prop, value); |
37 | 0 | return NS_OK; |
38 | 0 | } |
39 | | |
40 | | NS_IMETHODIMP |
41 | | nsProperties::Undefine(const char* prop) |
42 | 0 | { |
43 | 0 | if (NS_WARN_IF(!prop)) { |
44 | 0 | return NS_ERROR_INVALID_ARG; |
45 | 0 | } |
46 | 0 | |
47 | 0 | return nsProperties_HashBase::Remove(prop) ? NS_OK : NS_ERROR_FAILURE; |
48 | 0 | } |
49 | | |
50 | | NS_IMETHODIMP |
51 | | nsProperties::Has(const char* prop, bool* result) |
52 | 0 | { |
53 | 0 | if (NS_WARN_IF(!prop)) { |
54 | 0 | return NS_ERROR_INVALID_ARG; |
55 | 0 | } |
56 | 0 | |
57 | 0 | *result = nsProperties_HashBase::Contains(prop); |
58 | 0 | return NS_OK; |
59 | 0 | } |
60 | | |
61 | | NS_IMETHODIMP |
62 | | nsProperties::GetKeys(uint32_t* aCount, char*** aKeys) |
63 | 0 | { |
64 | 0 | if (NS_WARN_IF(!aCount) || NS_WARN_IF(!aKeys)) { |
65 | 0 | return NS_ERROR_INVALID_ARG; |
66 | 0 | } |
67 | 0 | |
68 | 0 | uint32_t count = Count(); |
69 | 0 | char** keys = (char**)moz_xmalloc(count * sizeof(char*)); |
70 | 0 | uint32_t j = 0; |
71 | 0 |
|
72 | 0 | for (auto iter = this->Iter(); !iter.Done(); iter.Next()) { |
73 | 0 | const char* key = iter.Key(); |
74 | 0 | keys[j] = strdup(key); |
75 | 0 |
|
76 | 0 | if (!keys[j]) { |
77 | 0 | // Free 'em all |
78 | 0 | for (uint32_t i = 0; i < j; i++) { |
79 | 0 | free(keys[i]); |
80 | 0 | } |
81 | 0 | free(keys); |
82 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
83 | 0 | } |
84 | 0 | j++; |
85 | 0 | } |
86 | 0 |
|
87 | 0 | *aCount = count; |
88 | 0 | *aKeys = keys; |
89 | 0 | return NS_OK; |
90 | 0 | } |
91 | | |
92 | | //////////////////////////////////////////////////////////////////////////////// |