Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsCommandParams_h__ |
michael@0 | 8 | #define nsCommandParams_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsString.h" |
michael@0 | 11 | #include "nsICommandParams.h" |
michael@0 | 12 | #include "nsCOMPtr.h" |
michael@0 | 13 | #include "pldhash.h" |
michael@0 | 14 | |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | class nsCommandParams : public nsICommandParams |
michael@0 | 18 | { |
michael@0 | 19 | public: |
michael@0 | 20 | |
michael@0 | 21 | nsCommandParams(); |
michael@0 | 22 | virtual ~nsCommandParams(); |
michael@0 | 23 | |
michael@0 | 24 | |
michael@0 | 25 | NS_DECL_ISUPPORTS |
michael@0 | 26 | NS_DECL_NSICOMMANDPARAMS |
michael@0 | 27 | |
michael@0 | 28 | nsresult Init(); |
michael@0 | 29 | |
michael@0 | 30 | protected: |
michael@0 | 31 | |
michael@0 | 32 | struct HashEntry : public PLDHashEntryHdr |
michael@0 | 33 | { |
michael@0 | 34 | nsCString mEntryName; |
michael@0 | 35 | |
michael@0 | 36 | uint8_t mEntryType; |
michael@0 | 37 | union { |
michael@0 | 38 | |
michael@0 | 39 | bool mBoolean; |
michael@0 | 40 | int32_t mLong; |
michael@0 | 41 | double mDouble; |
michael@0 | 42 | nsString* mString; |
michael@0 | 43 | nsCString* mCString; |
michael@0 | 44 | } mData; |
michael@0 | 45 | |
michael@0 | 46 | nsCOMPtr<nsISupports> mISupports; |
michael@0 | 47 | |
michael@0 | 48 | HashEntry(uint8_t inType, const char * inEntryName) |
michael@0 | 49 | : mEntryName(inEntryName) |
michael@0 | 50 | , mEntryType(inType) |
michael@0 | 51 | { |
michael@0 | 52 | memset(&mData, 0, sizeof(mData)); |
michael@0 | 53 | Reset(mEntryType); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | HashEntry(const HashEntry& inRHS) |
michael@0 | 57 | : mEntryType(inRHS.mEntryType) |
michael@0 | 58 | { |
michael@0 | 59 | Reset(mEntryType); |
michael@0 | 60 | switch (mEntryType) |
michael@0 | 61 | { |
michael@0 | 62 | case eBooleanType: mData.mBoolean = inRHS.mData.mBoolean; break; |
michael@0 | 63 | case eLongType: mData.mLong = inRHS.mData.mLong; break; |
michael@0 | 64 | case eDoubleType: mData.mDouble = inRHS.mData.mDouble; break; |
michael@0 | 65 | case eWStringType: |
michael@0 | 66 | NS_ASSERTION(inRHS.mData.mString, "Source entry has no string"); |
michael@0 | 67 | mData.mString = new nsString(*inRHS.mData.mString); |
michael@0 | 68 | break; |
michael@0 | 69 | case eStringType: |
michael@0 | 70 | NS_ASSERTION(inRHS.mData.mCString, "Source entry has no string"); |
michael@0 | 71 | mData.mCString = new nsCString(*inRHS.mData.mCString); |
michael@0 | 72 | break; |
michael@0 | 73 | case eISupportsType: |
michael@0 | 74 | mISupports = inRHS.mISupports.get(); // additional addref |
michael@0 | 75 | break; |
michael@0 | 76 | default: |
michael@0 | 77 | NS_ERROR("Unknown type"); |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | ~HashEntry() |
michael@0 | 82 | { |
michael@0 | 83 | if (mEntryType == eWStringType) |
michael@0 | 84 | delete mData.mString; |
michael@0 | 85 | else if (mEntryType == eStringType) |
michael@0 | 86 | delete mData.mCString; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | void Reset(uint8_t inNewType) |
michael@0 | 90 | { |
michael@0 | 91 | switch (mEntryType) |
michael@0 | 92 | { |
michael@0 | 93 | case eNoType: break; |
michael@0 | 94 | case eBooleanType: mData.mBoolean = false; break; |
michael@0 | 95 | case eLongType: mData.mLong = 0; break; |
michael@0 | 96 | case eDoubleType: mData.mDouble = 0.0; break; |
michael@0 | 97 | case eWStringType: delete mData.mString; mData.mString = nullptr; break; |
michael@0 | 98 | case eISupportsType: mISupports = nullptr; break; // clear the nsCOMPtr |
michael@0 | 99 | case eStringType: delete mData.mCString; mData.mCString = nullptr; break; |
michael@0 | 100 | default: |
michael@0 | 101 | NS_ERROR("Unknown type"); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | mEntryType = inNewType; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | |
michael@0 | 110 | HashEntry* GetNamedEntry(const char * name); |
michael@0 | 111 | HashEntry* GetIndexedEntry(int32_t index); |
michael@0 | 112 | uint32_t GetNumEntries(); |
michael@0 | 113 | |
michael@0 | 114 | nsresult GetOrMakeEntry(const char * name, uint8_t entryType, HashEntry*& outEntry); |
michael@0 | 115 | |
michael@0 | 116 | protected: |
michael@0 | 117 | |
michael@0 | 118 | static PLDHashNumber HashKey(PLDHashTable *table, const void *key); |
michael@0 | 119 | |
michael@0 | 120 | static bool HashMatchEntry(PLDHashTable *table, |
michael@0 | 121 | const PLDHashEntryHdr *entry, const void *key); |
michael@0 | 122 | |
michael@0 | 123 | static void HashMoveEntry(PLDHashTable *table, const PLDHashEntryHdr *from, |
michael@0 | 124 | PLDHashEntryHdr *to); |
michael@0 | 125 | |
michael@0 | 126 | static void HashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry); |
michael@0 | 127 | |
michael@0 | 128 | |
michael@0 | 129 | protected: |
michael@0 | 130 | |
michael@0 | 131 | enum { |
michael@0 | 132 | eNumEntriesUnknown = -1 |
michael@0 | 133 | }; |
michael@0 | 134 | |
michael@0 | 135 | // this is going to have to use a pldhash, because we need to |
michael@0 | 136 | // be able to iterate through entries, passing names back |
michael@0 | 137 | // to the caller, which means that we need to store the names |
michael@0 | 138 | // internally. |
michael@0 | 139 | |
michael@0 | 140 | PLDHashTable mValuesHash; |
michael@0 | 141 | |
michael@0 | 142 | // enumerator data |
michael@0 | 143 | int32_t mCurEntry; |
michael@0 | 144 | int32_t mNumEntries; // number of entries at start of enumeration (-1 indicates not known) |
michael@0 | 145 | |
michael@0 | 146 | static const PLDHashTableOps sHashOps; |
michael@0 | 147 | }; |
michael@0 | 148 | |
michael@0 | 149 | |
michael@0 | 150 | #endif // nsCommandParams_h__ |