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