/work/obj-fuzz/dist/include/nsCommandParams.h
Line | Count | Source (jump to first uncovered line) |
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 nsCommandParams_h |
8 | | #define nsCommandParams_h |
9 | | |
10 | | #include "mozilla/ErrorResult.h" |
11 | | #include "nsString.h" |
12 | | #include "nsICommandParams.h" |
13 | | #include "nsCOMPtr.h" |
14 | | #include "PLDHashTable.h" |
15 | | |
16 | | class nsCommandParams : public nsICommandParams |
17 | | { |
18 | | typedef mozilla::ErrorResult ErrorResult; |
19 | | typedef mozilla::IgnoredErrorResult IgnoredErrorResult; |
20 | | |
21 | | public: |
22 | | nsCommandParams(); |
23 | | |
24 | | NS_DECL_ISUPPORTS |
25 | | NS_DECL_NSICOMMANDPARAMS |
26 | | |
27 | | bool GetBool(const char* aName, ErrorResult& aRv) const; |
28 | | inline bool GetBool(const char* aName) const |
29 | 0 | { |
30 | 0 | IgnoredErrorResult error; |
31 | 0 | return GetBool(aName, error); |
32 | 0 | } |
33 | | int32_t GetInt(const char* aName, ErrorResult& aRv) const; |
34 | | inline int32_t GetInt(const char* aName) const |
35 | 0 | { |
36 | 0 | IgnoredErrorResult error; |
37 | 0 | return GetInt(aName, error); |
38 | 0 | } |
39 | | double GetDouble(const char* aName, ErrorResult& aRv) const; |
40 | | inline double GetDouble(const char* aName) const |
41 | 0 | { |
42 | 0 | IgnoredErrorResult error; |
43 | 0 | return GetDouble(aName, error); |
44 | 0 | } |
45 | | nsresult GetString(const char* aName, nsAString& aValue) const; |
46 | | nsresult GetCString(const char* aName, nsACString& aValue) const; |
47 | | already_AddRefed<nsISupports> |
48 | | GetISupports(const char* aName, ErrorResult& aRv) const; |
49 | | inline already_AddRefed<nsISupports> GetISupports(const char* aName) const |
50 | 0 | { |
51 | 0 | IgnoredErrorResult error; |
52 | 0 | return GetISupports(aName, error); |
53 | 0 | } |
54 | | |
55 | | nsresult SetBool(const char* aName, bool aValue); |
56 | | nsresult SetInt(const char* aName, int32_t aValue); |
57 | | nsresult SetDouble(const char* aName, double aValue); |
58 | | nsresult SetString(const char* aName, const nsAString& aValue); |
59 | | nsresult SetCString(const char* aName, const nsACString& aValue); |
60 | | nsresult SetISupports(const char* aName, nsISupports* aValue); |
61 | | |
62 | | protected: |
63 | | virtual ~nsCommandParams(); |
64 | | |
65 | | struct HashEntry : public PLDHashEntryHdr |
66 | | { |
67 | | nsCString mEntryName; |
68 | | |
69 | | uint8_t mEntryType; |
70 | | union |
71 | | { |
72 | | bool mBoolean; |
73 | | int32_t mLong; |
74 | | double mDouble; |
75 | | nsString* mString; |
76 | | nsCString* mCString; |
77 | | } mData; |
78 | | |
79 | | nsCOMPtr<nsISupports> mISupports; |
80 | | |
81 | | HashEntry(uint8_t aType, const char* aEntryName) |
82 | | : mEntryName(aEntryName) |
83 | | , mEntryType(aType) |
84 | | , mData() |
85 | | { |
86 | | Reset(mEntryType); |
87 | | } |
88 | | |
89 | | explicit HashEntry(const HashEntry& aRHS) |
90 | | : mEntryType(aRHS.mEntryType) |
91 | | { |
92 | | Reset(mEntryType); |
93 | | switch (mEntryType) { |
94 | | case eBooleanType: |
95 | | mData.mBoolean = aRHS.mData.mBoolean; |
96 | | break; |
97 | | case eLongType: |
98 | | mData.mLong = aRHS.mData.mLong; |
99 | | break; |
100 | | case eDoubleType: |
101 | | mData.mDouble = aRHS.mData.mDouble; |
102 | | break; |
103 | | case eWStringType: |
104 | | NS_ASSERTION(aRHS.mData.mString, "Source entry has no string"); |
105 | | mData.mString = new nsString(*aRHS.mData.mString); |
106 | | break; |
107 | | case eStringType: |
108 | | NS_ASSERTION(aRHS.mData.mCString, "Source entry has no string"); |
109 | | mData.mCString = new nsCString(*aRHS.mData.mCString); |
110 | | break; |
111 | | case eISupportsType: |
112 | | mISupports = aRHS.mISupports.get(); |
113 | | break; |
114 | | default: |
115 | | NS_ERROR("Unknown type"); |
116 | | } |
117 | | } |
118 | | |
119 | | ~HashEntry() { Reset(eNoType); } |
120 | | |
121 | | void Reset(uint8_t aNewType) |
122 | | { |
123 | | switch (mEntryType) { |
124 | | case eNoType: |
125 | | break; |
126 | | case eBooleanType: |
127 | | mData.mBoolean = false; |
128 | | break; |
129 | | case eLongType: |
130 | | mData.mLong = 0; |
131 | | break; |
132 | | case eDoubleType: |
133 | | mData.mDouble = 0.0; |
134 | | break; |
135 | | case eWStringType: |
136 | | delete mData.mString; |
137 | | mData.mString = nullptr; |
138 | | break; |
139 | | case eISupportsType: |
140 | | mISupports = nullptr; |
141 | | break; |
142 | | case eStringType: |
143 | | delete mData.mCString; |
144 | | mData.mCString = nullptr; |
145 | | break; |
146 | | default: |
147 | | NS_ERROR("Unknown type"); |
148 | | } |
149 | | mEntryType = aNewType; |
150 | | } |
151 | | }; |
152 | | |
153 | | HashEntry* GetNamedEntry(const char* aName) const; |
154 | | HashEntry* GetOrMakeEntry(const char* aName, uint8_t aEntryType); |
155 | | |
156 | | protected: |
157 | | static PLDHashNumber HashKey(const void* aKey); |
158 | | |
159 | | static bool HashMatchEntry(const PLDHashEntryHdr* aEntry, const void* aKey); |
160 | | |
161 | | static void HashMoveEntry(PLDHashTable* aTable, const PLDHashEntryHdr* aFrom, |
162 | | PLDHashEntryHdr* aTo); |
163 | | |
164 | | static void HashClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry); |
165 | | |
166 | | PLDHashTable mValuesHash; |
167 | | |
168 | | static const PLDHashTableOps sHashOps; |
169 | | }; |
170 | | |
171 | | nsCommandParams* |
172 | | nsICommandParams::AsCommandParams() |
173 | 0 | { |
174 | 0 | return static_cast<nsCommandParams*>(this); |
175 | 0 | } |
176 | | |
177 | | const nsCommandParams* |
178 | | nsICommandParams::AsCommandParams() const |
179 | 0 | { |
180 | 0 | return static_cast<const nsCommandParams*>(this); |
181 | 0 | } |
182 | | |
183 | | #endif // nsCommandParams_h |