1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsProperties.h"
8 ////////////////////////////////////////////////////////////////////////////////
10 NS_IMPL_AGGREGATED(nsProperties
)
11 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties
)
12 NS_INTERFACE_MAP_ENTRY(nsIProperties
)
16 nsProperties::Get(const char* prop
, const nsIID
& uuid
, void** result
)
18 if (NS_WARN_IF(!prop
)) {
19 return NS_ERROR_INVALID_ARG
;
22 nsCOMPtr
<nsISupports
> value
;
23 if (!nsProperties_HashBase::Get(prop
, getter_AddRefs(value
))) {
24 return NS_ERROR_FAILURE
;
26 return (value
) ? value
->QueryInterface(uuid
, result
) : NS_ERROR_NO_INTERFACE
;
30 nsProperties::Set(const char* prop
, nsISupports
* value
)
32 if (NS_WARN_IF(!prop
)) {
33 return NS_ERROR_INVALID_ARG
;
40 nsProperties::Undefine(const char* prop
)
42 if (NS_WARN_IF(!prop
)) {
43 return NS_ERROR_INVALID_ARG
;
46 nsCOMPtr
<nsISupports
> value
;
47 if (!nsProperties_HashBase::Get(prop
, getter_AddRefs(value
))) {
48 return NS_ERROR_FAILURE
;
56 nsProperties::Has(const char* prop
, bool* result
)
58 if (NS_WARN_IF(!prop
)) {
59 return NS_ERROR_INVALID_ARG
;
62 nsCOMPtr
<nsISupports
> value
;
63 *result
= nsProperties_HashBase::Get(prop
, getter_AddRefs(value
));
67 struct GetKeysEnumData
75 GetKeysEnumerate(const char* aKey
, nsISupports
* aData
, void* aArg
)
77 GetKeysEnumData
* gkedp
= (GetKeysEnumData
*)aArg
;
78 gkedp
->keys
[gkedp
->next
] = strdup(aKey
);
80 if (!gkedp
->keys
[gkedp
->next
]) {
81 gkedp
->res
= NS_ERROR_OUT_OF_MEMORY
;
90 nsProperties::GetKeys(uint32_t* aCount
, char*** aKeys
)
92 if (NS_WARN_IF(!aCount
) || NS_WARN_IF(!aKeys
)) {
93 return NS_ERROR_INVALID_ARG
;
97 char** k
= (char**)nsMemory::Alloc(n
* sizeof(char*));
104 EnumerateRead(GetKeysEnumerate
, &gked
);
106 nsresult rv
= gked
.res
;
109 for (uint32_t i
= 0; i
< gked
.next
; i
++) {
110 nsMemory::Free(k
[i
]);
121 ////////////////////////////////////////////////////////////////////////////////