00001 // Copyright (c) 2005, Google Inc. 00002 // All rights reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without 00005 // modification, are permitted provided that the following conditions are 00006 // met: 00007 // 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above 00011 // copyright notice, this list of conditions and the following disclaimer 00012 // in the documentation and/or other materials provided with the 00013 // distribution. 00014 // * Neither the name of Google Inc. nor the names of its 00015 // contributors may be used to endorse or promote products derived from 00016 // this software without specific prior written permission. 00017 // 00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 00030 // --- 00031 // This file is a compatibility layer that defines Google's version of 00032 // command line flags that are used for configuration. 00033 // 00034 // We put flags into their own namespace. It is purposefully 00035 // named in an opaque way that people should have trouble typing 00036 // directly. The idea is that DEFINE puts the flag in the weird 00037 // namespace, and DECLARE imports the flag from there into the 00038 // current namespace. The net result is to force people to use 00039 // DECLARE to get access to a flag, rather than saying 00040 // extern bool FLAGS_logtostderr; 00041 // or some such instead. We want this so we can put extra 00042 // functionality (like sanity-checking) in DECLARE if we want, 00043 // and make sure it is picked up everywhere. 00044 // 00045 // We also put the type of the variable in the namespace, so that 00046 // people can't DECLARE_int32 something that they DEFINE_bool'd 00047 // elsewhere. 00048 #ifndef BASE_COMMANDLINEFLAGS_H__ 00049 #define BASE_COMMANDLINEFLAGS_H__ 00050 00051 #include <string> 00052 #include "base/basictypes.h" 00053 00054 #define DECLARE_VARIABLE(type, name) \ 00055 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead { \ 00056 extern type FLAGS_##name; \ 00057 } \ 00058 using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_##name 00059 00060 #define DEFINE_VARIABLE(type, name, value, meaning) \ 00061 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead { \ 00062 type FLAGS_##name(value); \ 00063 char FLAGS_no##name; \ 00064 } \ 00065 using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_##name 00066 00067 // bool specialization 00068 #define DECLARE_bool(name) \ 00069 DECLARE_VARIABLE(bool, name) 00070 #define DEFINE_bool(name, value, meaning) \ 00071 DEFINE_VARIABLE(bool, name, value, meaning) 00072 00073 // int32 specialization 00074 #define DECLARE_int32(name) \ 00075 DECLARE_VARIABLE(int32, name) 00076 #define DEFINE_int32(name, value, meaning) \ 00077 DEFINE_VARIABLE(int32, name, value, meaning) 00078 00079 // int64 specialization 00080 #define DECLARE_int64(name) \ 00081 DECLARE_VARIABLE(int64, name) 00082 #define DEFINE_int64(name, value, meaning) \ 00083 DEFINE_VARIABLE(int64, name, value, meaning) 00084 00085 #define DECLARE_uint64(name) \ 00086 DECLARE_VARIABLE(uint64, name) 00087 #define DEFINE_uint64(name, value, meaning) \ 00088 DEFINE_VARIABLE(uint64, name, value, meaning) 00089 00090 // double specialization 00091 #define DECLARE_double(name) \ 00092 DECLARE_VARIABLE(double, name) 00093 #define DEFINE_double(name, value, meaning) \ 00094 DEFINE_VARIABLE(double, name, value, meaning) 00095 00096 // Special case for string, because we have to specify the namespace 00097 // std::string, which doesn't play nicely with our FLAG__namespace hackery. 00098 #define DECLARE_string(name) \ 00099 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ 00100 extern std::string FLAGS_##name; \ 00101 } \ 00102 using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name 00103 #define DEFINE_string(name, value, meaning) \ 00104 namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ 00105 std::string FLAGS_##name(value); \ 00106 char FLAGS_no##name; \ 00107 } \ 00108 using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name 00109 00110 #endif // BASE_COMMANDLINEFLAGS_H__