zoukankan      html  css  js  c++  java
  • Gflags

    References

    • GFlags使用文档, http://www.yeolar.com/note/2014/12/14/gflags/
    • How To Use gflags (formerly Google Commandline Flags), https://gflags.github.io/gflags/

    Install

    • git clone https://github.com/gflags/gflags.git

    CMake

    Find gflags installation. The gflags_DIR variable must be set to the <prefix>/lib/cmake/gflags directory containing the gflags-config.cmake file if <prefix> is a non-standard location. Otherwise, CMake should find the gflags installation automatically.

       find_package(gflags REQUIRED)
       add_executable(foo main.cc)
       target_link_libraries(foo gflags::gflags)

    DEFINE: Defining Flags In Program

    Defining a flag is easy: just use the appropriate macro for the type you want the flag to be, as defined at the bottom of gflags/gflags.h. Here's an example file, foo.cc:

       #include <gflags/gflags.h>
    
       DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
       DEFINE_string(languages, "english,french,german",
                     "comma-separated list of languages to offer in the 'lang' menu");
    

    DEFINE_bool defines a boolean flag. Here are the types supported:

    • DEFINE_bool: boolean
    • DEFINE_int32: 32-bit integer
    • DEFINE_int64: 64-bit integer
    • DEFINE_uint64: unsigned 64-bit integer
    • DEFINE_double: double
    • DEFINE_string: C++ string

    Accessing the Flag

    All defined flags are available to the program as just a normal variable, with the prefix FLAGS_ prepended. In the above example, the macros define two variables, FLAGS_big_menu (a bool), and FLAGS_languages (a C++ string).

    You can read and write to the flag just like any other variable:

       if (FLAGS_consider_made_up_languages)
         FLAGS_languages += ",klingon";   // implied by --consider_made_up_languages
       if (FLAGS_languages.find("finnish") != string::npos)
         HandleFinnish();
    

    You can also get and set flag values via special functions in gflags.h. That's a rarer use case, though.

    Miscellaneous Notes

    If your application has code like this:

       #define STRIP_FLAG_HELP 1    // this must go before the #include!
       #include <gflags/gflags.h>

     

     

    新博客地址:www.ybliu.com
  • 相关阅读:
    VSCode 快捷键(整理)
    MySQL数据库插入 100w 条数据用了多久?
    @Transactional事务几点注意及其属性Propagation的使用
    maven deploy时报错 distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
    Spring Boot+Mybatis 配置多数据源
    IDEA集成MyBatis Generator 插件 详解
    Spring boot中Yml文件的坑
    朝北教室的风筝 初听不知曲中意,再听已是曲中人
    Debug 调试问题-如何找到出问题的方法
    资损问题
  • 原文地址:https://www.cnblogs.com/yubao/p/11325613.html
Copyright © 2011-2022 走看看