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/. */
7 #include "nsProperties.h"
9 ////////////////////////////////////////////////////////////////////////////////
11 NS_IMPL_AGGREGATED(nsProperties
)
12 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties
)
13 NS_INTERFACE_MAP_ENTRY(nsIProperties
)
17 nsProperties::Get(const char* prop
, const nsIID
& uuid
, void** result
)
19 if (NS_WARN_IF(!prop
)) {
20 return NS_ERROR_INVALID_ARG
;
23 nsCOMPtr
<nsISupports
> value
;
24 if (!nsProperties_HashBase::Get(prop
, getter_AddRefs(value
))) {
25 return NS_ERROR_FAILURE
;
27 return (value
) ? value
->QueryInterface(uuid
, result
) : NS_ERROR_NO_INTERFACE
;
31 nsProperties::Set(const char* prop
, nsISupports
* value
)
33 if (NS_WARN_IF(!prop
)) {
34 return NS_ERROR_INVALID_ARG
;
41 nsProperties::Undefine(const char* prop
)
43 if (NS_WARN_IF(!prop
)) {
44 return NS_ERROR_INVALID_ARG
;
47 return nsProperties_HashBase::Remove(prop
) ? NS_OK
: NS_ERROR_FAILURE
;
51 nsProperties::Has(const char* prop
, bool* result
)
53 if (NS_WARN_IF(!prop
)) {
54 return NS_ERROR_INVALID_ARG
;
57 *result
= nsProperties_HashBase::Contains(prop
);
62 nsProperties::GetKeys(uint32_t* aCount
, char*** aKeys
)
64 if (NS_WARN_IF(!aCount
) || NS_WARN_IF(!aKeys
)) {
65 return NS_ERROR_INVALID_ARG
;
68 uint32_t count
= Count();
69 char** keys
= (char**)moz_xmalloc(count
* sizeof(char*));
72 for (auto iter
= this->Iter(); !iter
.Done(); iter
.Next()) {
73 const char* key
= iter
.Key();
74 keys
[j
] = strdup(key
);
78 for (uint32_t i
= 0; i
< j
; i
++) {
82 return NS_ERROR_OUT_OF_MEMORY
;
92 ////////////////////////////////////////////////////////////////////////////////