Home | History | Annotate | Download | only in base

Lines Matching defs:Flag

42 // Implementation of Flag
44 Flag::Flag(const char* file, const char* name, const char* comment,
56 void Flag::SetToDefault() {
58 // flag variables are not really of type FlagValue and thus may
60 // of a flag variable for convenient access. Since union members
63 case Flag::BOOL:
66 case Flag::INT:
69 case Flag::FLOAT:
72 case Flag::STRING:
80 static const char* Type2String(Flag::Type type) {
82 case Flag::BOOL: return "bool";
83 case Flag::INT: return "int";
84 case Flag::FLOAT: return "float";
85 case Flag::STRING: return "string";
92 static void PrintFlagValue(Flag::Type type, FlagValue* p) {
94 case Flag::BOOL:
97 case Flag::INT:
100 case Flag::FLOAT:
103 case Flag::STRING:
111 void Flag::Print(bool print_current_value) {
126 Flag* FlagList::list_ = NULL;
134 // Since flag registration is likely by file (= C++ file),
137 for (Flag* f = list_; f != NULL; f = f->next()) {
149 Flag* FlagList::Lookup(const char* name) {
150 Flag* f = list_;
166 // find the begin of the flag name
176 // find the end of the flag name
182 // make a copy so we can NUL-terminate flag name
203 // split arg into flag components
211 // lookup the flag
212 Flag* flag = Lookup(name);
213 if (flag == NULL) {
214 fprintf(stderr, "Error: unrecognized flag %s\n", arg);
218 // if we still need a flag value, use the next argument if available
219 if (flag->type() != Flag::BOOL && value == NULL) {
223 fprintf(stderr, "Error: missing value for flag %s of type %s\n",
224 arg, Type2String(flag->type()));
229 // set the flag
232 switch (flag->type()) {
233 case Flag::BOOL:
234 *flag->bool_variable() = !is_bool;
236 case Flag::INT:
237 *flag->int_variable() = strtol(value, &endp, 10);
239 case Flag::FLOAT:
240 *flag->float_variable() = strtod(value, &endp);
242 case Flag::STRING:
243 *flag->string_variable() = value;
248 if ((flag->type() == Flag::BOOL && value != NULL) ||
249 (flag->type() != Flag::BOOL && is_bool) ||
251 fprintf(stderr, "Error: illegal value for flag %s of type %s\n",
252 arg, Type2String(flag->type()));
256 // remove the flag & value from the command
277 void FlagList::Register(Flag* flag) {
278 assert(flag != NULL && strlen(flag->name()) > 0);
279 if (Lookup(flag->name()) != NULL)
280 Fatal(flag->file(), 0, "flag %s declared twice", flag->name());
281 flag->next_ = list_;
282 list_ = flag;