OLD | NEW |
1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include <string> | 52 #include <string> |
53 #include <string.h> // for memchr | 53 #include <string.h> // for memchr |
54 #include <stdlib.h> // for getenv | 54 #include <stdlib.h> // for getenv |
55 #include "base/basictypes.h" | 55 #include "base/basictypes.h" |
56 | 56 |
57 #if defined(__ANDROID__) || defined(ANDROID) | 57 #if defined(__ANDROID__) || defined(ANDROID) |
58 #include <sys/system_properties.h> | 58 #include <sys/system_properties.h> |
59 #endif | 59 #endif |
60 | 60 |
61 #define DECLARE_VARIABLE(type, name) \ | 61 #define DECLARE_VARIABLE(type, name) \ |
62 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead {
\ | 62 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead {\ |
63 extern PERFTOOLS_DLL_DECL type FLAGS_##name; \ | 63 extern PERFTOOLS_DLL_DECL type FLAGS_##name; \ |
64 } \ | 64 } \ |
65 using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_
##name | 65 using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_
##name |
66 | 66 |
67 #define DEFINE_VARIABLE(type, name, value, meaning) \ | 67 #define DEFINE_VARIABLE(type, name, value, meaning) \ |
68 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead {
\ | 68 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead {\ |
69 PERFTOOLS_DLL_DECL type FLAGS_##name(value); \ | 69 PERFTOOLS_DLL_DECL type FLAGS_##name(value); \ |
70 char FLAGS_no##name; \ | 70 char FLAGS_no##name; \ |
71 } \ | 71 } \ |
72 using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_
##name | 72 using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_
##name |
73 | 73 |
74 // bool specialization | 74 // bool specialization |
75 #define DECLARE_bool(name) \ | 75 #define DECLARE_bool(name) \ |
76 DECLARE_VARIABLE(bool, name) | 76 DECLARE_VARIABLE(bool, name) |
77 #define DEFINE_bool(name, value, meaning) \ | 77 #define DEFINE_bool(name, value, meaning) \ |
78 DEFINE_VARIABLE(bool, name, value, meaning) | 78 DEFINE_VARIABLE(bool, name, value, meaning) |
(...skipping 14 matching lines...) Expand all Loading... |
93 DECLARE_VARIABLE(uint64, name) | 93 DECLARE_VARIABLE(uint64, name) |
94 #define DEFINE_uint64(name, value, meaning) \ | 94 #define DEFINE_uint64(name, value, meaning) \ |
95 DEFINE_VARIABLE(uint64, name, value, meaning) | 95 DEFINE_VARIABLE(uint64, name, value, meaning) |
96 | 96 |
97 // double specialization | 97 // double specialization |
98 #define DECLARE_double(name) \ | 98 #define DECLARE_double(name) \ |
99 DECLARE_VARIABLE(double, name) | 99 DECLARE_VARIABLE(double, name) |
100 #define DEFINE_double(name, value, meaning) \ | 100 #define DEFINE_double(name, value, meaning) \ |
101 DEFINE_VARIABLE(double, name, value, meaning) | 101 DEFINE_VARIABLE(double, name, value, meaning) |
102 | 102 |
103 // Special case for string, because we have to specify the namespace | 103 // Special case for string, because of the pointer type. |
104 // std::string, which doesn't play nicely with our FLAG__namespace hackery. | |
105 #define DECLARE_string(name) \ | 104 #define DECLARE_string(name) \ |
106 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ | 105 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ |
107 extern std::string FLAGS_##name;
\ | 106 extern const char* FLAGS_##name; \ |
108 } \ | 107 } \ |
109 using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##
name | 108 using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##
name |
110 #define DEFINE_string(name, value, meaning) \ | 109 #define DEFINE_string(name, value, meaning) \ |
111 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ | 110 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ |
112 std::string FLAGS_##name(value);
\ | 111 const char* FLAGS_##name = value; \ |
113 char FLAGS_no##name; \ | 112 char FLAGS_no##name; \ |
114 } \ | 113 } \ |
115 using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##
name | 114 using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##
name |
116 | 115 |
117 // These macros (could be functions, but I don't want to bother with a .cc | 116 // These macros (could be functions, but I don't want to bother with a .cc |
118 // file), make it easier to initialize flags from the environment. | 117 // file), make it easier to initialize flags from the environment. |
119 // They are functions in Android because __system_property_get() doesn't | 118 // They are functions in Android because __system_property_get() doesn't |
120 // return a string. | 119 // return a string. |
121 | 120 |
122 #if defined(ENABLE_PROFILING) | 121 #if defined(ENABLE_PROFILING) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 183 |
185 #define EnvToString(envname, dflt) (dflt) | 184 #define EnvToString(envname, dflt) (dflt) |
186 #define EnvToBool(envname, dflt) (dflt) | 185 #define EnvToBool(envname, dflt) (dflt) |
187 #define EnvToInt(envname, dflt) (dflt) | 186 #define EnvToInt(envname, dflt) (dflt) |
188 #define EnvToInt64(envname, dflt) (dflt) | 187 #define EnvToInt64(envname, dflt) (dflt) |
189 #define EnvToDouble(envname, dflt) (dflt) | 188 #define EnvToDouble(envname, dflt) (dflt) |
190 | 189 |
191 #endif // defined(ENABLE_PROFILING) | 190 #endif // defined(ENABLE_PROFILING) |
192 | 191 |
193 #endif // BASE_COMMANDLINEFLAGS_H_ | 192 #endif // BASE_COMMANDLINEFLAGS_H_ |
OLD | NEW |