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 nsArray_h__ 8 #define nsArray_h__ 9 10 #include "nsIMutableArray.h" 11 #include "nsCOMArray.h" 12 #include "nsCOMPtr.h" 13 #include "nsCycleCollectionParticipant.h" 14 #include "mozilla/Attributes.h" 15 16 // {35C66FD1-95E9-4e0a-80C5-C3BD2B375481} 17 #define NS_ARRAY_CID \ 18 { \ 19 0x35c66fd1, 0x95e9, 0x4e0a, { \ 20 0x80, 0xc5, 0xc3, 0xbd, 0x2b, 0x37, 0x54, 0x81 \ 21 } \ 22 } 23 24 // nsArray without any refcounting declarations 25 class nsArrayBase : public nsIMutableArray { 26 public: 27 NS_DECL_NSIARRAY 28 NS_DECL_NSIARRAYEXTENSIONS 29 NS_DECL_NSIMUTABLEARRAY 30 31 /* Both of these factory functions create a cycle-collectable array 32 on the main thread and a non-cycle-collectable array on other 33 threads. */ 34 static already_AddRefed<nsIMutableArray> Create(); 35 /* Only for the benefit of the XPCOM module system, use Create() 36 instead. */ 37 static nsresult XPCOMConstructor(nsISupports* aOuter, const nsIID& aIID, 38 void** aResult); 39 40 protected: 41 nsArrayBase() = default; 42 nsArrayBase(const nsArrayBase& aOther); nsArrayBase(const nsCOMArray_base & aBaseArray)43 explicit nsArrayBase(const nsCOMArray_base& aBaseArray) 44 : mArray(aBaseArray) {} 45 virtual ~nsArrayBase(); 46 47 nsCOMArray_base mArray; 48 }; 49 50 class nsArray final : public nsArrayBase { 51 friend class nsArrayBase; 52 53 public: 54 NS_DECL_ISUPPORTS 55 56 private: nsArray()57 nsArray() : nsArrayBase() {} 58 nsArray(const nsArray& aOther); nsArray(const nsCOMArray_base & aBaseArray)59 explicit nsArray(const nsCOMArray_base& aBaseArray) 60 : nsArrayBase(aBaseArray) {} 61 ~nsArray() = default; 62 }; 63 64 class nsArrayCC final : public nsArrayBase { 65 friend class nsArrayBase; 66 67 public: 68 NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsArrayCC,nsIMutableArray)69 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsArrayCC, nsIMutableArray) 70 71 private: 72 nsArrayCC() : nsArrayBase() {} 73 nsArrayCC(const nsArrayCC& aOther); nsArrayCC(const nsCOMArray_base & aBaseArray)74 explicit nsArrayCC(const nsCOMArray_base& aBaseArray) 75 : nsArrayBase(aBaseArray) {} 76 ~nsArrayCC() = default; 77 }; 78 79 #endif 80