X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fexperimental%2FProgramOptions.cpp;h=842cfbca8b802df58d110d92aebf5f65c7efc6c9;hb=7b116ffe3b116ffc3c2089ca0b864ca7ebb1d28c;hp=8146722e5192b7c28063433f2f98bf225f90ea3b;hpb=29193aca605bb93d82a3c92acd95bb342115f3a4;p=folly.git diff --git a/folly/experimental/ProgramOptions.cpp b/folly/experimental/ProgramOptions.cpp index 8146722e..842cfbca 100644 --- a/folly/experimental/ProgramOptions.cpp +++ b/folly/experimental/ProgramOptions.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,11 @@ #include #include -#include #include + #include #include +#include namespace po = ::boost::program_options; @@ -82,12 +83,14 @@ class GFlagValueSemanticBase : public po::value_semantic { std::string name() const override { return "arg"; } #if BOOST_VERSION >= 105900 - bool adjacent_tokens_only() const override { return false; } + bool adjacent_tokens_only() const { + return false; + } #endif bool is_composing() const override { return false; } bool is_required() const override { return false; } // We handle setting the GFlags from parse(), so notify() does nothing. - void notify(const boost::any& valueStore) const override { } + void notify(const boost::any& /* valueStore */) const override {} bool apply_default(boost::any& valueStore) const override { // We're using the *current* rather than *default* value here, and // this is intentional; GFlags-using programs assign to FLAGS_foo @@ -101,11 +104,11 @@ class GFlagValueSemanticBase : public po::value_semantic { void parse(boost::any& valueStore, const std::vector& tokens, - bool utf8) const override; + bool /* utf8 */) const override; private: virtual T parseValue(const std::vector& tokens) const = 0; - virtual void transform(T& val) const { } + virtual void transform(T& /* val */) const {} mutable std::shared_ptr> info_; }; @@ -113,12 +116,12 @@ class GFlagValueSemanticBase : public po::value_semantic { template void GFlagValueSemanticBase::parse(boost::any& valueStore, const std::vector& tokens, - bool utf8) const { + bool /* utf8 */) const { T val; try { val = this->parseValue(tokens); this->transform(val); - } catch (const std::exception& e) { + } catch (const std::exception&) { throw po::invalid_option_value( tokens.empty() ? std::string() : tokens.front()); } @@ -166,29 +169,11 @@ class NegativeBoolGFlagValueSemantic : public BoolGFlagValueSemantic { } }; -static const std::unordered_set gSkipFlags { - "flagfile", - "fromenv", - "tryfromenv", - "undefok", - "help", - "helpfull", - "helpshort", - "helpon", - "helpmatch", - "helppackage", - "helpxml", - "version", - "tab_completion_columns", - "tab_completion_word", -}; - -static const std::unordered_map gFlagOverrides { - // Allow -v in addition to --v - {"v", "v,v"}, -}; - const std::string& getName(const std::string& name) { + static const std::unordered_map gFlagOverrides{ + // Allow -v in addition to --v + {"v", "v,v"}, + }; auto pos = gFlagOverrides.find(name); return pos != gFlagOverrides.end() ? pos->second : name; } @@ -252,6 +237,7 @@ const std::unordered_map gFlagAdders = { X("bool", bool) X("int32", int32_t) X("int64", int64_t) + X("uint32", uint32_t) X("uint64", uint64_t) X("double", double) X("string", std::string) @@ -261,6 +247,23 @@ const std::unordered_map gFlagAdders = { } // namespace po::options_description getGFlags(ProgramOptionsStyle style) { + static const std::unordered_set gSkipFlags{ + "flagfile", + "fromenv", + "tryfromenv", + "undefok", + "help", + "helpfull", + "helpshort", + "helpon", + "helpmatch", + "helppackage", + "helpxml", + "version", + "tab_completion_columns", + "tab_completion_word", + }; + po::options_description desc("GFlags"); std::vector allFlags;