一、gflags简单介绍
gflags是google开源的一套命令行参数解析工具。通常在项目开发中会有一种需求:
- 可以在代码运行的时候指定某些代码中某些参数的值
- 如果没有显式指定,这些参数可以使用默认的值
比如:服务器编程中需要用到IP和端口号。但是这两个变量有时候在具体使用程序的时候才会有具体的值,如果不用gflags可以这么写:
//test.cc
#include <iostream>
#include <string>
//else header file
#define LOG
class Server{
public:
Server(const std::string& ip = "127.0.0.1" , uint16_t port = 8080) : _ip(ip), _port(port) {
std::cout << "Init Server..." << std::endl;
#ifdef LOG
std::cout << "ip : " << _ip << std::endl;
std