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

Side by Side Diff: webrtc/base/flags.cc

Issue 2718663005: Replace NULL with nullptr or null in webrtc/base/. (Closed)
Patch Set: Fixing Windows and formatting issues. Created 3 years, 9 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 | « webrtc/base/flags.h ('k') | webrtc/base/httpbase.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2006 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 printf(" current value: "); 99 printf(" current value: ");
100 PrintFlagValue(type_, variable_); 100 PrintFlagValue(type_, variable_);
101 } 101 }
102 printf("\n"); 102 printf("\n");
103 } 103 }
104 104
105 105
106 // ----------------------------------------------------------------------------- 106 // -----------------------------------------------------------------------------
107 // Implementation of FlagList 107 // Implementation of FlagList
108 108
109 Flag* FlagList::list_ = NULL; 109 Flag* FlagList::list_ = nullptr;
110
111 110
112 FlagList::FlagList() { 111 FlagList::FlagList() {
113 list_ = NULL; 112 list_ = nullptr;
114 } 113 }
115 114
116 void FlagList::Print(const char* file, bool print_current_value) { 115 void FlagList::Print(const char* file, bool print_current_value) {
117 // Since flag registration is likely by file (= C++ file), 116 // Since flag registration is likely by file (= C++ file),
118 // we don't need to sort by file and still get grouped output. 117 // we don't need to sort by file and still get grouped output.
119 const char* current = NULL; 118 const char* current = nullptr;
120 for (Flag* f = list_; f != NULL; f = f->next()) { 119 for (Flag* f = list_; f != nullptr; f = f->next()) {
121 if (file == NULL || file == f->file()) { 120 if (file == nullptr || file == f->file()) {
122 if (current != f->file()) { 121 if (current != f->file()) {
123 printf("Flags from %s:\n", f->file()); 122 printf("Flags from %s:\n", f->file());
124 current = f->file(); 123 current = f->file();
125 } 124 }
126 f->Print(print_current_value); 125 f->Print(print_current_value);
127 } 126 }
128 } 127 }
129 } 128 }
130 129
131 130
132 Flag* FlagList::Lookup(const char* name) { 131 Flag* FlagList::Lookup(const char* name) {
133 Flag* f = list_; 132 Flag* f = list_;
134 while (f != NULL && strcmp(name, f->name()) != 0) 133 while (f != nullptr && strcmp(name, f->name()) != 0)
135 f = f->next(); 134 f = f->next();
136 return f; 135 return f;
137 } 136 }
138 137
139 138
140 void FlagList::SplitArgument(const char* arg, 139 void FlagList::SplitArgument(const char* arg,
141 char* buffer, int buffer_size, 140 char* buffer, int buffer_size,
142 const char** name, const char** value, 141 const char** name, const char** value,
143 bool* is_bool) { 142 bool* is_bool) {
144 *name = NULL; 143 *name = nullptr;
145 *value = NULL; 144 *value = nullptr;
146 *is_bool = false; 145 *is_bool = false;
147 146
148 if (*arg == '-') { 147 if (*arg == '-') {
149 // find the begin of the flag name 148 // find the begin of the flag name
150 arg++; // remove 1st '-' 149 arg++; // remove 1st '-'
151 if (*arg == '-') 150 if (*arg == '-')
152 arg++; // remove 2nd '-' 151 arg++; // remove 2nd '-'
153 if (arg[0] == 'n' && arg[1] == 'o') { 152 if (arg[0] == 'n' && arg[1] == 'o') {
154 arg += 2; // remove "no" 153 arg += 2; // remove "no"
155 *is_bool = true; 154 *is_bool = true;
(...skipping 26 matching lines...) Expand all
182 int j = i; // j > 0 181 int j = i; // j > 0
183 const char* arg = argv[i++]; 182 const char* arg = argv[i++];
184 183
185 // split arg into flag components 184 // split arg into flag components
186 char buffer[1024]; 185 char buffer[1024];
187 const char* name; 186 const char* name;
188 const char* value; 187 const char* value;
189 bool is_bool; 188 bool is_bool;
190 SplitArgument(arg, buffer, sizeof buffer, &name, &value, &is_bool); 189 SplitArgument(arg, buffer, sizeof buffer, &name, &value, &is_bool);
191 190
192 if (name != NULL) { 191 if (name != nullptr) {
193 // lookup the flag 192 // lookup the flag
194 Flag* flag = Lookup(name); 193 Flag* flag = Lookup(name);
195 if (flag == NULL) { 194 if (flag == nullptr) {
196 fprintf(stderr, "Error: unrecognized flag %s\n", arg); 195 fprintf(stderr, "Error: unrecognized flag %s\n", arg);
197 return j; 196 return j;
198 } 197 }
199 198
200 // if we still need a flag value, use the next argument if available 199 // if we still need a flag value, use the next argument if available
201 if (flag->type() != Flag::BOOL && value == NULL) { 200 if (flag->type() != Flag::BOOL && value == nullptr) {
202 if (i < *argc) { 201 if (i < *argc) {
203 value = argv[i++]; 202 value = argv[i++];
204 } else { 203 } else {
205 fprintf(stderr, "Error: missing value for flag %s of type %s\n", 204 fprintf(stderr, "Error: missing value for flag %s of type %s\n",
206 arg, Type2String(flag->type())); 205 arg, Type2String(flag->type()));
207 return j; 206 return j;
208 } 207 }
209 } 208 }
210 209
211 // set the flag 210 // set the flag
212 char empty[] = { '\0' }; 211 char empty[] = { '\0' };
213 char* endp = empty; 212 char* endp = empty;
214 switch (flag->type()) { 213 switch (flag->type()) {
215 case Flag::BOOL: 214 case Flag::BOOL:
216 *flag->bool_variable() = !is_bool; 215 *flag->bool_variable() = !is_bool;
217 break; 216 break;
218 case Flag::INT: 217 case Flag::INT:
219 *flag->int_variable() = strtol(value, &endp, 10); 218 *flag->int_variable() = strtol(value, &endp, 10);
220 break; 219 break;
221 case Flag::FLOAT: 220 case Flag::FLOAT:
222 *flag->float_variable() = strtod(value, &endp); 221 *flag->float_variable() = strtod(value, &endp);
223 break; 222 break;
224 case Flag::STRING: 223 case Flag::STRING:
225 *flag->string_variable() = value; 224 *flag->string_variable() = value;
226 break; 225 break;
227 } 226 }
228 227
229 // handle errors 228 // handle errors
230 if ((flag->type() == Flag::BOOL && value != NULL) || 229 if ((flag->type() == Flag::BOOL && value != nullptr) ||
231 (flag->type() != Flag::BOOL && is_bool) || 230 (flag->type() != Flag::BOOL && is_bool) || *endp != '\0') {
232 *endp != '\0') {
233 fprintf(stderr, "Error: illegal value for flag %s of type %s\n", 231 fprintf(stderr, "Error: illegal value for flag %s of type %s\n",
234 arg, Type2String(flag->type())); 232 arg, Type2String(flag->type()));
235 return j; 233 return j;
236 } 234 }
237 235
238 // remove the flag & value from the command 236 // remove the flag & value from the command
239 if (remove_flags) 237 if (remove_flags)
240 while (j < i) 238 while (j < i)
241 argv[j++] = NULL; 239 argv[j++] = nullptr;
242 } 240 }
243 } 241 }
244 242
245 // shrink the argument list 243 // shrink the argument list
246 if (remove_flags) { 244 if (remove_flags) {
247 int j = 1; 245 int j = 1;
248 for (int i = 1; i < *argc; i++) { 246 for (int i = 1; i < *argc; i++) {
249 if (argv[i] != NULL) 247 if (argv[i] != nullptr)
250 argv[j++] = argv[i]; 248 argv[j++] = argv[i];
251 } 249 }
252 *argc = j; 250 *argc = j;
253 } 251 }
254 252
255 // parsed all flags successfully 253 // parsed all flags successfully
256 return 0; 254 return 0;
257 } 255 }
258 256
259 void FlagList::Register(Flag* flag) { 257 void FlagList::Register(Flag* flag) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // need to free each string in the array, and then the array. 290 // need to free each string in the array, and then the array.
293 for(int i = 0; i < argc_; i++) { 291 for(int i = 0; i < argc_; i++) {
294 delete[] argv_[i]; 292 delete[] argv_[i];
295 } 293 }
296 294
297 delete[] argv_; 295 delete[] argv_;
298 } 296 }
299 #endif // WEBRTC_WIN 297 #endif // WEBRTC_WIN
300 298
301 } // namespace rtc 299 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/flags.h ('k') | webrtc/base/httpbase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698