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 #ifndef nsHashPropertyBag_h___
8 #define nsHashPropertyBag_h___
9 
10 #include "nsIVariant.h"
11 #include "nsIWritablePropertyBag.h"
12 #include "nsIWritablePropertyBag2.h"
13 
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsInterfaceHashtable.h"
16 
17 class nsHashPropertyBagBase : public nsIWritablePropertyBag,
18                               public nsIWritablePropertyBag2 {
19  public:
20   nsHashPropertyBagBase() = default;
21 
22   void CopyFrom(const nsHashPropertyBagBase* aOther);
23   void CopyFrom(nsIPropertyBag* aOther);
24   static void CopyFrom(nsIWritablePropertyBag* aTo, nsIPropertyBag* aFrom);
25 
26   NS_DECL_NSIPROPERTYBAG
27   NS_DECL_NSIPROPERTYBAG2
28 
29   NS_DECL_NSIWRITABLEPROPERTYBAG
30   NS_DECL_NSIWRITABLEPROPERTYBAG2
31 
32  protected:
33   // a hash table of string -> nsIVariant
34   nsInterfaceHashtable<nsStringHashKey, nsIVariant> mPropertyHash;
35 };
36 
37 class nsHashPropertyBag : public nsHashPropertyBagBase {
38  public:
39   nsHashPropertyBag() = default;
40   NS_DECL_THREADSAFE_ISUPPORTS
41 
42  protected:
43   virtual ~nsHashPropertyBag();
44 };
45 
46 /* A cycle collected nsHashPropertyBag for main-thread-only use. */
47 class nsHashPropertyBagCC final : public nsHashPropertyBagBase {
48  public:
49   nsHashPropertyBagCC() = default;
50   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
51   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHashPropertyBagCC,
52                                            nsIWritablePropertyBag)
53  protected:
54   virtual ~nsHashPropertyBagCC() = default;
55 };
56 
ToSupports(nsHashPropertyBagBase * aPropertyBag)57 inline nsISupports* ToSupports(nsHashPropertyBagBase* aPropertyBag) {
58   return static_cast<nsIWritablePropertyBag*>(aPropertyBag);
59 }
60 
61 #endif /* nsHashPropertyBag_h___ */
62