Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Side by Side Diff: client/simple_string_dictionary.h

Issue 656703002: Convert NULL to nullptr (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Fix 80-column violations Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | client/simple_string_dictionary_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 //! \brief An iterator to traverse all of the active entries in a 72 //! \brief An iterator to traverse all of the active entries in a
73 //! TSimpleStringDictionary. 73 //! TSimpleStringDictionary.
74 class Iterator { 74 class Iterator {
75 public: 75 public:
76 explicit Iterator(const TSimpleStringDictionary& map) 76 explicit Iterator(const TSimpleStringDictionary& map)
77 : map_(map), 77 : map_(map),
78 current_(0) { 78 current_(0) {
79 } 79 }
80 80
81 //! \brief Returns the next entry in the map, or `NULL` if at the end of the 81 //! \brief Returns the next entry in the map, or `nullptr` if at the end of
82 //! collection. 82 //! the collection.
83 const Entry* Next() { 83 const Entry* Next() {
84 while (current_ < map_.num_entries) { 84 while (current_ < map_.num_entries) {
85 const Entry* entry = &map_.entries_[current_++]; 85 const Entry* entry = &map_.entries_[current_++];
86 if (entry->is_active()) { 86 if (entry->is_active()) {
87 return entry; 87 return entry;
88 } 88 }
89 } 89 }
90 return NULL; 90 return nullptr;
91 } 91 }
92 92
93 private: 93 private:
94 const TSimpleStringDictionary& map_; 94 const TSimpleStringDictionary& map_;
95 size_t current_; 95 size_t current_;
96 96
97 DISALLOW_COPY_AND_ASSIGN(Iterator); 97 DISALLOW_COPY_AND_ASSIGN(Iterator);
98 }; 98 };
99 99
100 TSimpleStringDictionary() 100 TSimpleStringDictionary()
(...skipping 26 matching lines...) Expand all
127 for (size_t i = 0; i < num_entries; ++i) { 127 for (size_t i = 0; i < num_entries; ++i) {
128 if (entries_[i].is_active()) { 128 if (entries_[i].is_active()) {
129 ++count; 129 ++count;
130 } 130 }
131 } 131 }
132 return count; 132 return count;
133 } 133 }
134 134
135 //! \brief Given \a key, returns its corresponding value. 135 //! \brief Given \a key, returns its corresponding value.
136 //! 136 //!
137 //! \param[in] key The key to look up. This must not be `NULL`. 137 //! \param[in] key The key to look up. This must not be `nullptr`.
138 //! 138 //!
139 //! \return The corresponding value for \a key, or if \a key is not found, 139 //! \return The corresponding value for \a key, or if \a key is not found,
140 //! `NULL`. 140 //! `nullptr`.
141 const char* GetValueForKey(const char* key) const { 141 const char* GetValueForKey(const char* key) const {
142 DCHECK(key); 142 DCHECK(key);
143 if (!key) { 143 if (!key) {
144 return NULL; 144 return nullptr;
145 } 145 }
146 146
147 const Entry* entry = GetConstEntryForKey(key); 147 const Entry* entry = GetConstEntryForKey(key);
148 if (!entry) { 148 if (!entry) {
149 return NULL; 149 return nullptr;
150 } 150 }
151 151
152 return entry->value; 152 return entry->value;
153 } 153 }
154 154
155 //! \brief Stores \a value into \a key, replacing the existing value if \a key 155 //! \brief Stores \a value into \a key, replacing the existing value if \a key
156 //! is already present. 156 //! is already present.
157 //! 157 //!
158 //! If there \a key is not yet in the map and the map is already full 158 //! If \a key is not yet in the map and the map is already full (containing
159 //! (containing \a NumEntries active entries), this operation silently fails. 159 //! \a NumEntries active entries), this operation silently fails.
160 //! 160 //!
161 //! \param[in] key The key to store. This must not be `NULL`. 161 //! \param[in] key The key to store. This must not be `nullptr`.
162 //! \param[in] value The value to store. If `NULL`, \a key is removed from the 162 //! \param[in] value The value to store. If `nullptr`, \a key is removed from
163 //! map. 163 //! the map.
164 void SetKeyValue(const char* key, const char* value) { 164 void SetKeyValue(const char* key, const char* value) {
165 if (!value) { 165 if (!value) {
166 RemoveKey(key); 166 RemoveKey(key);
167 return; 167 return;
168 } 168 }
169 169
170 DCHECK(key); 170 DCHECK(key);
171 if (!key) { 171 if (!key) {
172 return; 172 return;
173 } 173 }
(...skipping 13 matching lines...) Expand all
187 entry = &entries_[i]; 187 entry = &entries_[i];
188 188
189 strncpy(entry->key, key, key_size); 189 strncpy(entry->key, key, key_size);
190 entry->key[key_size - 1] = '\0'; 190 entry->key[key_size - 1] = '\0';
191 191
192 break; 192 break;
193 } 193 }
194 } 194 }
195 } 195 }
196 196
197 // If the map is out of space, entry will be NULL. 197 // If the map is out of space, |entry| will be nullptr.
198 if (!entry) { 198 if (!entry) {
199 return; 199 return;
200 } 200 }
201 201
202 #ifndef NDEBUG 202 #ifndef NDEBUG
203 // Sanity check that the key only appears once. 203 // Sanity check that the key only appears once.
204 int count = 0; 204 int count = 0;
205 for (size_t i = 0; i < num_entries; ++i) { 205 for (size_t i = 0; i < num_entries; ++i) {
206 if (strncmp(entries_[i].key, key, key_size) == 0) { 206 if (strncmp(entries_[i].key, key, key_size) == 0) {
207 ++count; 207 ++count;
208 } 208 }
209 } 209 }
210 DCHECK_EQ(count, 1); 210 DCHECK_EQ(count, 1);
211 #endif 211 #endif
212 212
213 strncpy(entry->value, value, value_size); 213 strncpy(entry->value, value, value_size);
214 entry->value[value_size - 1] = '\0'; 214 entry->value[value_size - 1] = '\0';
215 } 215 }
216 216
217 //! \brief Removes \a key from the map. 217 //! \brief Removes \a key from the map.
218 //! 218 //!
219 //! If the key is not found, this is a no-op. 219 //! If \a key is not found, this is a no-op.
220 //! 220 //!
221 //! \param[in] key The key of the entry to remove. This must not be `NULL`. 221 //! \param[in] key The key of the entry to remove. This must not be `nullptr`.
222 void RemoveKey(const char* key) { 222 void RemoveKey(const char* key) {
223 DCHECK(key); 223 DCHECK(key);
224 if (!key) { 224 if (!key) {
225 return; 225 return;
226 } 226 }
227 227
228 Entry* entry = GetEntryForKey(key); 228 Entry* entry = GetEntryForKey(key);
229 if (entry) { 229 if (entry) {
230 entry->key[0] = '\0'; 230 entry->key[0] = '\0';
231 entry->value[0] = '\0'; 231 entry->value[0] = '\0';
232 } 232 }
233 233
234 DCHECK_EQ(GetEntryForKey(key), static_cast<void*>(NULL)); 234 DCHECK_EQ(GetEntryForKey(key), static_cast<Entry*>(nullptr));
235 } 235 }
236 236
237 //! \brief Returns a serialized form of the map. 237 //! \brief Returns a serialized form of the map.
238 //! 238 //!
239 //! Places a serialized version of the map into \a map and returns the size in 239 //! Places a serialized version of the map into \a map and returns the size in
240 //! bytes. Both \a map and the size should be passed to the deserializing 240 //! bytes. Both \a map and the size should be passed to the deserializing
241 //! constructor. Note that the serialized \a map is scoped to the lifetime of 241 //! constructor. Note that the serialized \a map is scoped to the lifetime of
242 //! the non-serialized instance of this class. The \a map data can be copied 242 //! the non-serialized instance of this class. The \a map data can be copied
243 //! across IPC boundaries. 243 //! across IPC boundaries.
244 size_t Serialize(const SerializedSimpleStringDictionary** map) const { 244 size_t Serialize(const SerializedSimpleStringDictionary** map) const {
245 *map = reinterpret_cast<const SerializedSimpleStringDictionary*>(entries_); 245 *map = reinterpret_cast<const SerializedSimpleStringDictionary*>(entries_);
246 return sizeof(entries_); 246 return sizeof(entries_);
247 } 247 }
248 248
249 private: 249 private:
250 const Entry* GetConstEntryForKey(const char* key) const { 250 const Entry* GetConstEntryForKey(const char* key) const {
251 for (size_t i = 0; i < num_entries; ++i) { 251 for (size_t i = 0; i < num_entries; ++i) {
252 if (strncmp(key, entries_[i].key, key_size) == 0) { 252 if (strncmp(key, entries_[i].key, key_size) == 0) {
253 return &entries_[i]; 253 return &entries_[i];
254 } 254 }
255 } 255 }
256 return NULL; 256 return nullptr;
257 } 257 }
258 258
259 Entry* GetEntryForKey(const char* key) { 259 Entry* GetEntryForKey(const char* key) {
260 return const_cast<Entry*>(GetConstEntryForKey(key)); 260 return const_cast<Entry*>(GetConstEntryForKey(key));
261 } 261 }
262 262
263 Entry entries_[NumEntries]; 263 Entry entries_[NumEntries];
264 }; 264 };
265 265
266 //! \brief A TSimpleStringDictionary with default template parameters. 266 //! \brief A TSimpleStringDictionary with default template parameters.
267 //! 267 //!
268 //! For historical reasons this specialized version is available with the same 268 //! For historical reasons this specialized version is available with the same
269 //! size factors as a previous implementation. 269 //! size factors as a previous implementation.
270 typedef TSimpleStringDictionary<256, 256, 64> SimpleStringDictionary; 270 typedef TSimpleStringDictionary<256, 256, 64> SimpleStringDictionary;
271 271
272 } // namespace crashpad 272 } // namespace crashpad
273 273
274 #endif // CRASHPAD_CLIENT_SIMPLE_STRING_DICTIONARY_H_ 274 #endif // CRASHPAD_CLIENT_SIMPLE_STRING_DICTIONARY_H_
OLDNEW
« no previous file with comments | « no previous file | client/simple_string_dictionary_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698