gflags摘记
projcet url:
https://github.com/schuhschuh/gflags
usage: commandline flags processing
DEFINE: Defining Flags In Program
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
DECLARE: Using the Flag in a Different File
If the flag does span multiple files, DECLARE it in theassociated .h file, and make others #include that .h file if they want to access the flag. The #include will make explicit
the dependency between the two files. This causes the flag to be a global variable.
RegisterFlagValidator: Sanity-checking Flag Values
Here is an example use of this functionality:
static bool ValidatePort(const char* flagname, int32 value) {
if (value > 0 && value < 32768) // value is ok
return true;
printf("Invalid value for --%s: %d\n", flagname, (int)value);
return false;
}
DEFINE_int32(port, 0, "What port to listen on");
static const bool port_dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort);
By doing the registration at global initialization time (right after the DEFINE), we ensure that the registration happens before the commandline is parsed at the beginning of main().
Putting It Together: How to Set Up Flags
gflags::ParseCommandLineFlags(&argc, &argv, true);
The last argument is called "remove_flags".
If true, then ParseCommandLineFlags removes the flags and their arguments from argv, and modifies argc appropriately. In this case, after the function call, argv will hold only commandline arguments, and not commandline
flags.
If, on the other hand, remove_flags is false, then ParseCommandLineFlags will leave argc unchanged, butwill rearrange the arguments in argv so that the flags are all at the beginning.
Setting Flags on the Command Line
Here's an example of all the ways to specify the "languages" flag:
app_containing_foo --languages="chinese,japanese,korean"
app_containing_foo -languages="chinese,japanese,korean"
app_containing_foo --languages "chinese,japanese,korean"
app_containing_foo -languages "chinese,japanese,korean"
For boolean flags, the possibilities are slightly different:
app_containing_foo --big_menu
app_containing_foo --nobig_menu
app_containing_foo --big_menu=true
app_containing_foo --big_menu=false
Changing the Default Flag Value
It's simple to do this: just assign a new value to the flag in main(), before calling ParseCommandLineFlags():
DECLARE_bool(lib_verbose); // mylib has a lib_verbose flag, default is false
int main(int argc, char** argv) {
FLAGS_lib_verbose = true; // in my app, I want a verbose lib by default
ParseCommandLineFlags(...);
}
For this application, users can still set the flag value on the commandline, but if they do not, the flag's value will default to true.
Special Flags
--helpshows all flags from all files, sorted by file and then by name; shows the flagname, its default value,
and its help string
--helpfullsame as -help, but unambiguously asks for all flags (in case -help changes in the future)
--helpshortshows only flags for the file with the same name as the executable (usually the one containing main())
--helpxmllike --help, but output is in xml for easier parsing
--helpon=FILE shows only flags defined in FILE.*
--helpmatch=Sshows only flags defined in *S*.*
--helppackageshows flags defined in files in same directory as main()
--versionprints version info for the executable
--fromenv
--fromenv=foo,bar says to read the values for the foo and bar flags from the environment.
--tryfromenv
--tryfromenv is exactly like --fromenv, except it is not a fatal error to say --tryfromenv=foo if FLAGS_foo is not actually defined in the environment.
--flagfile
--flagfile=f tells the commandlineflags module to read the file f, and to run all the flag-assignments found in that file as if these flags had been specified on the commandline.
The API
For more information about these routines, and other useful helper methods such asgflags::SetUsageMessage() andgflags::SetVersionString,
seegflags.h.
Miscellaneous Notes
If your application has code like this:
#define STRIP_FLAG_HELP 1 // this must go before the #include!
#include <gflags/gflags.h>
we will remove the help messages from the compiled source. This canreduce the size of the resulting binary somewhat, and mayalso be useful for
security reasons.
gflags摘记的更多相关文章
- gflags
一.安装配置 下载地址: https://code.google.com/p/gflags/downloads/list 解压安装: tar zxvf gflags-2.0.tar.gz && ...
- 使用PageHeap.EXE或GFlags.EXE检查内存越界错误 (转)
2011-05-27 20:19 290人阅读 评论(0) 收藏 举报 microsoftdebuggingstructureoutputimagefile 必先利其器之一:使用PageHeap.EX ...
- google gflags使用.
code.google.com 被墙的好开心... gflags很简单. 编译使用都很简单. (不像omaha这种丧心病狂的编译依赖). cmake 生成一下. 一路顺风顺水. 值得注意的是: 默认 ...
- glog摘记
projcet url:https://code.google.com/p/google-glog/ usage: application-level logging setting flags GL ...
- 使用PageHeap.EXE或GFlags.EXE检查内存越界错误
必先利其器之一:使用PageHeap.EXE或GFlags.EXE检查内存越界错误 Article last modified on 2002-6-3 ------------------------ ...
- Windbg的gflags.exe -- Attach调试利器
有没有碰到过程序启动就因为异常直接crash?有没有碰到程序启动之后什么反应也没有?有没有碰到过程序启动之后去触发另一个进程失败?有没有碰到别人的程序调用了你的代码,出现问题以后,让你来调查,而你只有 ...
- gflags 学习
一.下载 https://github.com/gflags/gflags 二.可以将gflags编译成lib 三.在需要的工程的workspace下面引入编译好的gflags动态库,在库里面写好BU ...
- linux下gflags的安装
gflags是google开发的一套命令行参数解析工具,被很多软件系统所依赖,应该算是一个基础的库,安装其实很简单,但是如果在网上找的一些教程大部分都是安装后不能被其他软件调用的,因为默认使用cmak ...
- gflags命令行参数解析
gflags库是google开源的命令行参数解析工具. 安装 官方没有提供二进制库,但是Debian/Ubuntu平台本身提供了二进制库,可以直接git clone https://github.co ...
随机推荐
- OneNote无法同时设置中英文字体设置解决办法
如果你是一位OneNote老用户,无论是2003.2007还是2010或者最新的2013版本,都一直存在一个Bug,就是无法同时设置中英文字体(比如在Word中就可以分别设置不同的).我搜了一下,在微 ...
- 按书上学写测试pytest
慢慢的,这块知识也补好吧. 系统的学习框架,具体的细节,可以边百度边实现. test_three.py '''Test the Task data type.''' from collections ...
- 最小圆覆盖 gym-102006 I
#include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...
- Spring Boot 教程demo
https://github.com/ityouknow/spring-boot-examples
- redis配置新端口
为redis分配一个8888端口,操作步骤如下:1.$REDIS_HOME/redis.conf重新复制一份,重命名为redis8888.conf.2.打开redis8888.conf配置文件,找到p ...
- WebLogic和Tomcat的区别
J2ee开发主要是浏览器和服务器进行交互的一种结构.逻辑都是在后台进行处理,然后再把结果传输回给浏览器.可以看出服务器在这种架构是非常重要的. 这几天接触到两种Java的web服务器,做项目用的Tom ...
- vue 单向数据流 & 双向绑定
在react中是单向数据绑定,而在vue中的特色是双向数据绑定.但是其实就我个人的理解是: 其实无论是vue还是react其实还是提倡单向数据流去管理状态,这一点在vuex和redux状态管理器上体现 ...
- Python 中的面向对象和异常处理
在之前我们已经说过了 Python 中内置的主要的几种对象类型,(数,字符串,列表,元组和字典).而面向对象的核心人物还没出场呢 .那么我们常说的对象是什么类型的呢,其实他的类型就是“类”.继承封装和 ...
- Linux安装系统选择 日报 18/06/23
Linux安装系统选择 Centos7 程序体积7个G,如果是学习伊始, 注意不要选择那个体积小的,因为我装过之后进去发现这个wifie还要自己进行一些烈的命令才能连接成功.很麻烦的. 安装比较顺利但 ...
- 50个必备jQuery代码段
0. 如何创建嵌套的过滤器: 1 2 3 4 5 //允许你减少集合中的匹配元素的过滤器, //只剩下那些与给定的选择器匹配的部分.在这种情况下, //查询删除了任何没(:not)有(:has) // ...