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 ...
随机推荐
- Java字符串常见实例与函数
字符串比较 字符串函数 compareTo (string) ,compareToIgnoreCase(String) 及 compareTo(object string) 来比较两个字符串,并返回字 ...
- CVE-2010-2553 Microsoft Windows Cinepak 编码解码器解压缩漏洞 分析
Microsoft Windows是微软发布的非常流行的操作系统. Microsoft Windows XP SP2和SP3,Windows Vista SP1和SP2,以及Win ...
- JDBC连接池和DBUtils
本节内容: JDBC连接池 DBUtils 一.JDBC连接池 实际开发中“获得连接”或“释放资源”是非常消耗系统资源的两个过程,为了解决此类性能问题,通常情况我们采取连接池技术,来共享连接Conne ...
- hiho 1227 找到一个恰好包含n个点的圆 (2015北京网赛 A题)
平面上有m个点,要从这m个点当中找出n个点,使得包含这n个点的圆的半径(圆心为n个点当中的某一点且半径为整数)最小,同时保证圆周上没有点. n > m 时要输出-1 样例输入43 2 0 0 1 ...
- bzoj 4551
4551 思路: 乱搞: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...
- 模拟界面请求到web服务器
客户端 package com.lsw.client; import java.io.*; import java.net.*; import java.util.*; public class HT ...
- React Native之网页组件WebView的使用与通信
在实际开发中,我们通常会嵌入一些html页面,官方为我们提供了一个非常好用的网页组件WebView,通过这个组件我们可以通过传入一个url或者是传入一段html 一. WebView的基本属性方法介绍 ...
- Java I/O流输入输出,序列化,NIO,NIO.2
Java IO流 File类: File类是java.io包下代表和平台无关的文件和目录,File不能访问文件内容本身. File类基本操作: System.out.println("判断文 ...
- Revit二次开发示例:AutoStamp
该示例中,在Revit启动时添加打印事件,在打印时向模型添加水印,打印完成后删除该水印. #region Namespaces using System; using System.Collect ...
- Django-url反向解析与csrf-token设置
url反向解析 在使用Django 项目时,一个常见的需求是获得URL 的最终形式,以用于嵌入到生成的内容中(视图中和显示给用户的URL等)或者用于处理服务器端的导航(重定向等). 人们强烈希望不要硬 ...