/thirdparty/breakpad/third_party/linux/include/gflags/gflags.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 533 lines · 179 code · 62 blank · 292 comment · 3 complexity · 41634cf10972e2a80ee346b7bc34fec7 MD5 · raw file

  1. // Copyright (c) 2006, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // ---
  30. // Author: Ray Sidney
  31. // Revamped and reorganized by Craig Silverstein
  32. //
  33. // This is the file that should be included by any file which declares
  34. // or defines a command line flag or wants to parse command line flags
  35. // or print a program usage message (which will include information about
  36. // flags). Executive summary, in the form of an example foo.cc file:
  37. //
  38. // #include "foo.h" // foo.h has a line "DECLARE_int32(start);"
  39. //
  40. // DEFINE_int32(end, 1000, "The last record to read");
  41. // DECLARE_bool(verbose); // some other file has a DEFINE_bool(verbose, ...)
  42. //
  43. // void MyFunc() {
  44. // if (FLAGS_verbose) printf("Records %d-%d\n", FLAGS_start, FLAGS_end);
  45. // }
  46. //
  47. // Then, at the command-line:
  48. // ./foo --noverbose --start=5 --end=100
  49. //
  50. // For more details, see
  51. // doc/gflags.html
  52. //
  53. // --- A note about thread-safety:
  54. //
  55. // We describe many functions in this routine as being thread-hostile,
  56. // thread-compatible, or thread-safe. Here are the meanings we use:
  57. //
  58. // thread-safe: it is safe for multiple threads to call this routine
  59. // (or, when referring to a class, methods of this class)
  60. // concurrently.
  61. // thread-hostile: it is not safe for multiple threads to call this
  62. // routine (or methods of this class) concurrently. In gflags,
  63. // most thread-hostile routines are intended to be called early in,
  64. // or even before, main() -- that is, before threads are spawned.
  65. // thread-compatible: it is safe for multiple threads to read from
  66. // this variable (when applied to variables), or to call const
  67. // methods of this class (when applied to classes), as long as no
  68. // other thread is writing to the variable or calling non-const
  69. // methods of this class.
  70. #ifndef GOOGLE_GFLAGS_H_
  71. #define GOOGLE_GFLAGS_H_
  72. #include <string>
  73. #include <vector>
  74. // We care a lot about number of bits things take up. Unfortunately,
  75. // systems define their bit-specific ints in a lot of different ways.
  76. // We use our own way, and have a typedef to get there.
  77. // Note: these commands below may look like "#if 1" or "#if 0", but
  78. // that's because they were constructed that way at ./configure time.
  79. // Look at gflags.h.in to see how they're calculated (based on your config).
  80. #if 1
  81. #include <stdint.h> // the normal place uint16_t is defined
  82. #endif
  83. #if 1
  84. #include <sys/types.h> // the normal place u_int16_t is defined
  85. #endif
  86. #if 1
  87. #include <inttypes.h> // a third place for uint16_t or u_int16_t
  88. #endif
  89. namespace google {
  90. #if 1 // the C99 format
  91. typedef int32_t int32;
  92. typedef uint32_t uint32;
  93. typedef int64_t int64;
  94. typedef uint64_t uint64;
  95. #elif 1 // the BSD format
  96. typedef int32_t int32;
  97. typedef u_int32_t uint32;
  98. typedef int64_t int64;
  99. typedef u_int64_t uint64;
  100. #elif 0 // the windows (vc7) format
  101. typedef __int32 int32;
  102. typedef unsigned __int32 uint32;
  103. typedef __int64 int64;
  104. typedef unsigned __int64 uint64;
  105. #else
  106. #error Do not know how to define a 32-bit integer quantity on your system
  107. #endif
  108. // --------------------------------------------------------------------
  109. // To actually define a flag in a file, use DEFINE_bool,
  110. // DEFINE_string, etc. at the bottom of this file. You may also find
  111. // it useful to register a validator with the flag. This ensures that
  112. // when the flag is parsed from the commandline, or is later set via
  113. // SetCommandLineOption, we call the validation function.
  114. //
  115. // The validation function should return true if the flag value is valid, and
  116. // false otherwise. If the function returns false for the new setting of the
  117. // flag, the flag will retain its current value. If it returns false for the
  118. // default value, InitGoogle will die.
  119. //
  120. // This function is safe to call at global construct time (as in the
  121. // example below).
  122. //
  123. // Example use:
  124. // static bool ValidatePort(const char* flagname, int32 value) {
  125. // if (value > 0 && value < 32768) // value is ok
  126. // return true;
  127. // printf("Invalid value for --%s: %d\n", flagname, (int)value);
  128. // return false;
  129. // }
  130. // DEFINE_int32(port, 0, "What port to listen on");
  131. // static bool dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort);
  132. // Returns true if successfully registered, false if not (because the
  133. // first argument doesn't point to a command-line flag, or because a
  134. // validator is already registered for this flag).
  135. bool RegisterFlagValidator(const bool* flag,
  136. bool (*validate_fn)(const char*, bool));
  137. bool RegisterFlagValidator(const int32* flag,
  138. bool (*validate_fn)(const char*, int32));
  139. bool RegisterFlagValidator(const int64* flag,
  140. bool (*validate_fn)(const char*, int64));
  141. bool RegisterFlagValidator(const uint64* flag,
  142. bool (*validate_fn)(const char*, uint64));
  143. bool RegisterFlagValidator(const double* flag,
  144. bool (*validate_fn)(const char*, double));
  145. bool RegisterFlagValidator(const std::string* flag,
  146. bool (*validate_fn)(const char*, const std::string&));
  147. // --------------------------------------------------------------------
  148. // These methods are the best way to get access to info about the
  149. // list of commandline flags. Note that these routines are pretty slow.
  150. // GetAllFlags: mostly-complete info about the list, sorted by file.
  151. // ShowUsageWithFlags: pretty-prints the list to stdout (what --help does)
  152. // ShowUsageWithFlagsRestrict: limit to filenames with restrict as a substr
  153. //
  154. // In addition to accessing flags, you can also access argv[0] (the program
  155. // name) and argv (the entire commandline), which we sock away a copy of.
  156. // These variables are static, so you should only set them once.
  157. struct CommandLineFlagInfo {
  158. std::string name; // the name of the flag
  159. std::string type; // the type of the flag: int32, etc
  160. std::string description; // the "help text" associated with the flag
  161. std::string current_value; // the current value, as a string
  162. std::string default_value; // the default value, as a string
  163. std::string filename; // 'cleaned' version of filename holding the flag
  164. bool has_validator_fn; // true if RegisterFlagValidator called on flag
  165. bool is_default; // true if the flag has default value
  166. };
  167. extern void GetAllFlags(std::vector<CommandLineFlagInfo>* OUTPUT);
  168. // These two are actually defined in commandlineflags_reporting.cc.
  169. extern void ShowUsageWithFlags(const char *argv0); // what --help does
  170. extern void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict);
  171. // Create a descriptive string for a flag.
  172. // Goes to some trouble to make pretty line breaks.
  173. extern std::string DescribeOneFlag(const CommandLineFlagInfo& flag);
  174. // Thread-hostile; meant to be called before any threads are spawned.
  175. extern void SetArgv(int argc, const char** argv);
  176. // The following functions are thread-safe as long as SetArgv() is
  177. // only called before any threads start.
  178. extern const std::vector<std::string>& GetArgvs(); // all of argv as a vector
  179. extern const char* GetArgv(); // all of argv as a string
  180. extern const char* GetArgv0(); // only argv0
  181. extern uint32 GetArgvSum(); // simple checksum of argv
  182. extern const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set
  183. extern const char* ProgramInvocationShortName(); // basename(argv0)
  184. // ProgramUsage() is thread-safe as long as SetUsageMessage() is only
  185. // called before any threads start.
  186. extern const char* ProgramUsage(); // string set by SetUsageMessage()
  187. // --------------------------------------------------------------------
  188. // Normally you access commandline flags by just saying "if (FLAGS_foo)"
  189. // or whatever, and set them by calling "FLAGS_foo = bar" (or, more
  190. // commonly, via the DEFINE_foo macro). But if you need a bit more
  191. // control, we have programmatic ways to get/set the flags as well.
  192. // These programmatic ways to access flags are thread-safe, but direct
  193. // access is only thread-compatible.
  194. // Return true iff the flagname was found.
  195. // OUTPUT is set to the flag's value, or unchanged if we return false.
  196. extern bool GetCommandLineOption(const char* name, std::string* OUTPUT);
  197. // Return true iff the flagname was found. OUTPUT is set to the flag's
  198. // CommandLineFlagInfo or unchanged if we return false.
  199. extern bool GetCommandLineFlagInfo(const char* name,
  200. CommandLineFlagInfo* OUTPUT);
  201. // Return the CommandLineFlagInfo of the flagname. exit() if name not found.
  202. // Example usage, to check if a flag's value is currently the default value:
  203. // if (GetCommandLineFlagInfoOrDie("foo").is_default) ...
  204. extern CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
  205. enum FlagSettingMode {
  206. // update the flag's value (can call this multiple times).
  207. SET_FLAGS_VALUE,
  208. // update the flag's value, but *only if* it has not yet been updated
  209. // with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef".
  210. SET_FLAG_IF_DEFAULT,
  211. // set the flag's default value to this. If the flag has not yet updated
  212. // yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef")
  213. // change the flag's current value to the new default value as well.
  214. SET_FLAGS_DEFAULT
  215. };
  216. // Set a particular flag ("command line option"). Returns a string
  217. // describing the new value that the option has been set to. The
  218. // return value API is not well-specified, so basically just depend on
  219. // it to be empty if the setting failed for some reason -- the name is
  220. // not a valid flag name, or the value is not a valid value -- and
  221. // non-empty else.
  222. // SetCommandLineOption uses set_mode == SET_FLAGS_VALUE (the common case)
  223. extern std::string SetCommandLineOption(const char* name, const char* value);
  224. extern std::string SetCommandLineOptionWithMode(const char* name, const char* value,
  225. FlagSettingMode set_mode);
  226. // --------------------------------------------------------------------
  227. // Saves the states (value, default value, whether the user has set
  228. // the flag, registered validators, etc) of all flags, and restores
  229. // them when the FlagSaver is destroyed. This is very useful in
  230. // tests, say, when you want to let your tests change the flags, but
  231. // make sure that they get reverted to the original states when your
  232. // test is complete.
  233. //
  234. // Example usage:
  235. // void TestFoo() {
  236. // FlagSaver s1;
  237. // FLAG_foo = false;
  238. // FLAG_bar = "some value";
  239. //
  240. // // test happens here. You can return at any time
  241. // // without worrying about restoring the FLAG values.
  242. // }
  243. //
  244. // Note: This class is marked with __attribute__((unused)) because all the
  245. // work is done in the constructor and destructor, so in the standard
  246. // usage example above, the compiler would complain that it's an
  247. // unused variable.
  248. //
  249. // This class is thread-safe.
  250. class FlagSaver {
  251. public:
  252. FlagSaver();
  253. ~FlagSaver();
  254. private:
  255. class FlagSaverImpl* impl_; // we use pimpl here to keep API steady
  256. FlagSaver(const FlagSaver&); // no copying!
  257. void operator=(const FlagSaver&);
  258. } __attribute__ ((unused));
  259. // --------------------------------------------------------------------
  260. // Some deprecated or hopefully-soon-to-be-deprecated functions.
  261. // This is often used for logging. TODO(csilvers): figure out a better way
  262. extern std::string CommandlineFlagsIntoString();
  263. // Usually where this is used, a FlagSaver should be used instead.
  264. extern bool ReadFlagsFromString(const std::string& flagfilecontents,
  265. const char* prog_name,
  266. bool errors_are_fatal); // uses SET_FLAGS_VALUE
  267. // These let you manually implement --flagfile functionality.
  268. // DEPRECATED.
  269. extern bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name);
  270. extern bool SaveCommandFlags(); // actually defined in google.cc !
  271. extern bool ReadFromFlagsFile(const std::string& filename, const char* prog_name,
  272. bool errors_are_fatal); // uses SET_FLAGS_VALUE
  273. // --------------------------------------------------------------------
  274. // Useful routines for initializing flags from the environment.
  275. // In each case, if 'varname' does not exist in the environment
  276. // return defval. If 'varname' does exist but is not valid
  277. // (e.g., not a number for an int32 flag), abort with an error.
  278. // Otherwise, return the value. NOTE: for booleans, for true use
  279. // 't' or 'T' or 'true' or '1', for false 'f' or 'F' or 'false' or '0'.
  280. extern bool BoolFromEnv(const char *varname, bool defval);
  281. extern int32 Int32FromEnv(const char *varname, int32 defval);
  282. extern int64 Int64FromEnv(const char *varname, int64 defval);
  283. extern uint64 Uint64FromEnv(const char *varname, uint64 defval);
  284. extern double DoubleFromEnv(const char *varname, double defval);
  285. extern const char *StringFromEnv(const char *varname, const char *defval);
  286. // --------------------------------------------------------------------
  287. // The next two functions parse commandlineflags from main():
  288. // Set the "usage" message for this program. For example:
  289. // string usage("This program does nothing. Sample usage:\n");
  290. // usage += argv[0] + " <uselessarg1> <uselessarg2>";
  291. // SetUsageMessage(usage);
  292. // Do not include commandline flags in the usage: we do that for you!
  293. // Thread-hostile; meant to be called before any threads are spawned.
  294. extern void SetUsageMessage(const std::string& usage);
  295. // Looks for flags in argv and parses them. Rearranges argv to put
  296. // flags first, or removes them entirely if remove_flags is true.
  297. // If a flag is defined more than once in the command line or flag
  298. // file, the last definition is used.
  299. // See top-of-file for more details on this function.
  300. #ifndef SWIG // In swig, use ParseCommandLineFlagsScript() instead.
  301. extern uint32 ParseCommandLineFlags(int *argc, char*** argv,
  302. bool remove_flags);
  303. #endif
  304. // Calls to ParseCommandLineNonHelpFlags and then to
  305. // HandleCommandLineHelpFlags can be used instead of a call to
  306. // ParseCommandLineFlags during initialization, in order to allow for
  307. // changing default values for some FLAGS (via
  308. // e.g. SetCommandLineOptionWithMode calls) between the time of
  309. // command line parsing and the time of dumping help information for
  310. // the flags as a result of command line parsing.
  311. // If a flag is defined more than once in the command line or flag
  312. // file, the last definition is used.
  313. extern uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv,
  314. bool remove_flags);
  315. // This is actually defined in commandlineflags_reporting.cc.
  316. // This function is misnamed (it also handles --version, etc.), but
  317. // it's too late to change that now. :-(
  318. extern void HandleCommandLineHelpFlags(); // in commandlineflags_reporting.cc
  319. // Allow command line reparsing. Disables the error normally
  320. // generated when an unknown flag is found, since it may be found in a
  321. // later parse. Thread-hostile; meant to be called before any threads
  322. // are spawned.
  323. extern void AllowCommandLineReparsing();
  324. // Reparse the flags that have not yet been recognized.
  325. // Only flags registered since the last parse will be recognized.
  326. // Any flag value must be provided as part of the argument using "=",
  327. // not as a separate command line argument that follows the flag argument.
  328. // Intended for handling flags from dynamically loaded libraries,
  329. // since their flags are not registered until they are loaded.
  330. extern uint32 ReparseCommandLineNonHelpFlags();
  331. // --------------------------------------------------------------------
  332. // Now come the command line flag declaration/definition macros that
  333. // will actually be used. They're kind of hairy. A major reason
  334. // for this is initialization: we want people to be able to access
  335. // variables in global constructors and have that not crash, even if
  336. // their global constructor runs before the global constructor here.
  337. // (Obviously, we can't guarantee the flags will have the correct
  338. // default value in that case, but at least accessing them is safe.)
  339. // The only way to do that is have flags point to a static buffer.
  340. // So we make one, using a union to ensure proper alignment, and
  341. // then use placement-new to actually set up the flag with the
  342. // correct default value. In the same vein, we have to worry about
  343. // flag access in global destructors, so FlagRegisterer has to be
  344. // careful never to destroy the flag-values it constructs.
  345. //
  346. // Note that when we define a flag variable FLAGS_<name>, we also
  347. // preemptively define a junk variable, FLAGS_no<name>. This is to
  348. // cause a link-time error if someone tries to define 2 flags with
  349. // names like "logging" and "nologging". We do this because a bool
  350. // flag FLAG can be set from the command line to true with a "-FLAG"
  351. // argument, and to false with a "-noFLAG" argument, and so this can
  352. // potentially avert confusion.
  353. //
  354. // We also put flags into their own namespace. It is purposefully
  355. // named in an opaque way that people should have trouble typing
  356. // directly. The idea is that DEFINE puts the flag in the weird
  357. // namespace, and DECLARE imports the flag from there into the current
  358. // namespace. The net result is to force people to use DECLARE to get
  359. // access to a flag, rather than saying "extern bool FLAGS_whatever;"
  360. // or some such instead. We want this so we can put extra
  361. // functionality (like sanity-checking) in DECLARE if we want, and
  362. // make sure it is picked up everywhere.
  363. //
  364. // We also put the type of the variable in the namespace, so that
  365. // people can't DECLARE_int32 something that they DEFINE_bool'd
  366. // elsewhere.
  367. class FlagRegisterer {
  368. public:
  369. FlagRegisterer(const char* name, const char* type,
  370. const char* help, const char* filename,
  371. void* current_storage, void* defvalue_storage);
  372. };
  373. extern bool FlagsTypeWarn(const char *name);
  374. // If your application #defines STRIP_FLAG_HELP to a non-zero value
  375. // before #including this file, we remove the help message from the
  376. // binary file. This can reduce the size of the resulting binary
  377. // somewhat, and may also be useful for security reasons.
  378. extern const char kStrippedFlagHelp[];
  379. }
  380. #ifndef SWIG // In swig, ignore the main flag declarations
  381. #if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0
  382. // Need this construct to avoid the 'defined but not used' warning.
  383. #define MAYBE_STRIPPED_HELP(txt) (false ? (txt) : kStrippedFlagHelp)
  384. #else
  385. #define MAYBE_STRIPPED_HELP(txt) txt
  386. #endif
  387. // Each command-line flag has two variables associated with it: one
  388. // with the current value, and one with the default value. However,
  389. // we have a third variable, which is where value is assigned; it's a
  390. // constant. This guarantees that FLAG_##value is initialized at
  391. // static initialization time (e.g. before program-start) rather than
  392. // than global construction time (which is after program-start but
  393. // before main), at least when 'value' is a compile-time constant. We
  394. // use a small trick for the "default value" variable, and call it
  395. // FLAGS_no<name>. This serves the second purpose of assuring a
  396. // compile error if someone tries to define a flag named no<name>
  397. // which is illegal (--foo and --nofoo both affect the "foo" flag).
  398. #define DEFINE_VARIABLE(type, shorttype, name, value, help) \
  399. namespace fL##shorttype { \
  400. static const type FLAGS_nono##name = value; \
  401. type FLAGS_##name = FLAGS_nono##name; \
  402. type FLAGS_no##name = FLAGS_nono##name; \
  403. static ::google::FlagRegisterer o_##name( \
  404. #name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \
  405. &FLAGS_##name, &FLAGS_no##name); \
  406. } \
  407. using fL##shorttype::FLAGS_##name
  408. #define DECLARE_VARIABLE(type, shorttype, name) \
  409. namespace fL##shorttype { \
  410. extern type FLAGS_##name; \
  411. } \
  412. using fL##shorttype::FLAGS_##name
  413. // For DEFINE_bool, we want to do the extra check that the passed-in
  414. // value is actually a bool, and not a string or something that can be
  415. // coerced to a bool. These declarations (no definition needed!) will
  416. // help us do that, and never evaluate From, which is important.
  417. // We'll use 'sizeof(IsBool(val))' to distinguish. This code requires
  418. // that the compiler have different sizes for bool & double. Since
  419. // this is not guaranteed by the standard, we check it with a
  420. // compile-time assert (msg[-1] will give a compile-time error).
  421. namespace fLB {
  422. struct CompileAssert {};
  423. typedef CompileAssert expected_sizeof_double_neq_sizeof_bool[
  424. (sizeof(double) != sizeof(bool)) ? 1 : -1];
  425. template<typename From> double IsBoolFlag(const From& from);
  426. bool IsBoolFlag(bool from);
  427. } // namespace fLB
  428. #define DECLARE_bool(name) DECLARE_VARIABLE(bool,B, name)
  429. #define DEFINE_bool(name,val,txt) \
  430. namespace fLB { \
  431. typedef CompileAssert FLAG_##name##_value_is_not_a_bool[ \
  432. (sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \
  433. } \
  434. DEFINE_VARIABLE(bool,B, name, val, txt)
  435. #define DECLARE_int32(name) DECLARE_VARIABLE(::google::int32,I, name)
  436. #define DEFINE_int32(name,val,txt) DEFINE_VARIABLE(::google::int32,I, name, val, txt)
  437. #define DECLARE_int64(name) DECLARE_VARIABLE(::google::int64,I64, name)
  438. #define DEFINE_int64(name,val,txt) DEFINE_VARIABLE(::google::int64,I64, name, val, txt)
  439. #define DECLARE_uint64(name) DECLARE_VARIABLE(::google::uint64,U64, name)
  440. #define DEFINE_uint64(name,val,txt) DEFINE_VARIABLE(::google::uint64,U64, name, val, txt)
  441. #define DECLARE_double(name) DECLARE_VARIABLE(double,D, name)
  442. #define DEFINE_double(name,val,txt) DEFINE_VARIABLE(double,D, name, val, txt)
  443. // Strings are trickier, because they're not a POD, so we can't
  444. // construct them at static-initialization time (instead they get
  445. // constructed at global-constructor time, which is much later). To
  446. // try to avoid crashes in that case, we use a char buffer to store
  447. // the string, which we can static-initialize, and then placement-new
  448. // into it later. It's not perfect, but the best we can do.
  449. #define DECLARE_string(name) namespace fLS { extern std::string& FLAGS_##name; } \
  450. using fLS::FLAGS_##name
  451. // We need to define a var named FLAGS_no##name so people don't define
  452. // --string and --nostring. And we need a temporary place to put val
  453. // so we don't have to evaluate it twice. Two great needs that go
  454. // great together!
  455. // The weird 'using' + 'extern' inside the fLS namespace is to work around
  456. // an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See
  457. // http://code.google.com/p/google-gflags/issues/detail?id=20
  458. #define DEFINE_string(name, val, txt) \
  459. namespace fLS { \
  460. static union { void* align; char s[sizeof(std::string)]; } s_##name[2]; \
  461. const std::string* const FLAGS_no##name = new (s_##name[0].s) std::string(val); \
  462. static ::google::FlagRegisterer o_##name( \
  463. #name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
  464. s_##name[0].s, new (s_##name[1].s) std::string(*FLAGS_no##name)); \
  465. extern std::string& FLAGS_##name; \
  466. using fLS::FLAGS_##name; \
  467. std::string& FLAGS_##name = *(reinterpret_cast<std::string*>(s_##name[0].s)); \
  468. } \
  469. using fLS::FLAGS_##name
  470. #endif // SWIG
  471. #endif // GOOGLE_GFLAGS_H_