- 浏览: 718748 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (1042)
- 数据结构 (36)
- UML与设计模式 (42)
- c++ (87)
- rust (36)
- Qt (41)
- boost模板元编程 (43)
- Linux (77)
- 汇编 (4)
- 其它 (2)
- 烹饪 (3)
- unix c / socket (73)
- 软件工程 (4)
- shell (52)
- Python (37)
- c++ primer 5th(c++11) (22)
- 数据库/MySQL (27)
- 数据存储 (4)
- lisp (7)
- git (4)
- Utility (3)
- CDN与DNS (54)
- Http (53)
- php (7)
- nginx/lua/openresty (41)
- redis (11)
- TCP/IP (16)
- 互联网 (6)
- kernel (2)
- go (33)
- 区块链 (43)
- 比特股 (13)
- 以太坊 (23)
- 比特币 (23)
- 密码学 (10)
- EOS (53)
- DAG (1)
- docker (1)
- filecoin (7)
- solidity (64)
- ipfs (8)
- 零知识证明 (1)
- openzeppelin (3)
- java (1)
- defi (7)
最新评论
#include <boost/program_options.hpp>
#include <string.h>
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
using namespace boost;
namespace bpo = boost::program_options;
/*
config.ini:
p2p-endpoint = 0.0.0.1:31010
rpc-endpoint = 0.0.0.0:38090
*/
int main(int argc,char** argv)
{
cout << "cmd line:" << endl;
bpo::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("df_value", bpo::value<string>()->default_value("123"), ""); //give default
bpo::variables_map cmdValueMap;
bpo::store(bpo::parse_command_line(argc, argv, desc), cmdValueMap);
bpo::notify(cmdValueMap);
if(cmdValueMap.count("help")){
cout<<desc<<endl;
}
if(cmdValueMap.count("df_value")){
cout << "df_value:" << cmdValueMap["df_value"].as<string>() << endl;
}
cout << endl;
cout << "直接读取文件配置:" << endl;
boost::program_options::options_description options("Graphene Witness Node");
bpo::variables_map fileValueMap;
options.add_options()
("p2p-endpoint", bpo::value<string>(), "Endpoint for P2P node to listen on")
("rpc-endpoint", bpo::value<string>(),"aaa")
("genesis-json", bpo::value<string>()->default_value("my-genesis.json"),"genesis-json");
bool useIfStream = true;//both is ok
if(useIfStream)
{
ifstream ifs("config.ini");
boost::program_options::store(boost::program_options::parse_config_file(ifs,options), fileValueMap);
}else
{
boost::program_options::store(boost::program_options::parse_config_file<char>("config.ini",options, true), fileValueMap);
}
boost::program_options::notify(fileValueMap);
if(fileValueMap.count("p2p-endpoint")){
cout << fileValueMap["p2p-endpoint"].as<string>() << endl;
}
if(fileValueMap.count("rpc-endpoint")){
cout << fileValueMap["rpc-endpoint"].as<string>() << endl;
}
if(fileValueMap.count("genesis-json")){
cout << fileValueMap["genesis-json"].as<string>() << endl;
}
cout << endl;
cout << "遍历valueMap:" << endl;
for(bpo::variables_map::iterator iter = fileValueMap.begin(); iter != fileValueMap.end(); ++iter){
cout << iter->first << ":" << iter->second.as<string>() << endl;
}
}
执行:./a.out --help
cmd line:
Allowed options:
--help produce help message
--df_value arg (=123)
df_value:123
直接读取文件配置:
0.0.0.1:31010
0.0.0.0:38090
my-genesis.json
遍历valueMap:
genesis-json:my-genesis.json
p2p-endpoint:0.0.0.1:31010
rpc-endpoint:0.0.0.0:38090
#include <string.h>
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
using namespace boost;
namespace bpo = boost::program_options;
/*
config.ini:
p2p-endpoint = 0.0.0.1:31010
rpc-endpoint = 0.0.0.0:38090
*/
int main(int argc,char** argv)
{
cout << "cmd line:" << endl;
bpo::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("df_value", bpo::value<string>()->default_value("123"), ""); //give default
bpo::variables_map cmdValueMap;
bpo::store(bpo::parse_command_line(argc, argv, desc), cmdValueMap);
bpo::notify(cmdValueMap);
if(cmdValueMap.count("help")){
cout<<desc<<endl;
}
if(cmdValueMap.count("df_value")){
cout << "df_value:" << cmdValueMap["df_value"].as<string>() << endl;
}
cout << endl;
cout << "直接读取文件配置:" << endl;
boost::program_options::options_description options("Graphene Witness Node");
bpo::variables_map fileValueMap;
options.add_options()
("p2p-endpoint", bpo::value<string>(), "Endpoint for P2P node to listen on")
("rpc-endpoint", bpo::value<string>(),"aaa")
("genesis-json", bpo::value<string>()->default_value("my-genesis.json"),"genesis-json");
bool useIfStream = true;//both is ok
if(useIfStream)
{
ifstream ifs("config.ini");
boost::program_options::store(boost::program_options::parse_config_file(ifs,options), fileValueMap);
}else
{
boost::program_options::store(boost::program_options::parse_config_file<char>("config.ini",options, true), fileValueMap);
}
boost::program_options::notify(fileValueMap);
if(fileValueMap.count("p2p-endpoint")){
cout << fileValueMap["p2p-endpoint"].as<string>() << endl;
}
if(fileValueMap.count("rpc-endpoint")){
cout << fileValueMap["rpc-endpoint"].as<string>() << endl;
}
if(fileValueMap.count("genesis-json")){
cout << fileValueMap["genesis-json"].as<string>() << endl;
}
cout << endl;
cout << "遍历valueMap:" << endl;
for(bpo::variables_map::iterator iter = fileValueMap.begin(); iter != fileValueMap.end(); ++iter){
cout << iter->first << ":" << iter->second.as<string>() << endl;
}
}
执行:./a.out --help
cmd line:
Allowed options:
--help produce help message
--df_value arg (=123)
df_value:123
直接读取文件配置:
0.0.0.1:31010
0.0.0.0:38090
my-genesis.json
遍历valueMap:
genesis-json:my-genesis.json
p2p-endpoint:0.0.0.1:31010
rpc-endpoint:0.0.0.0:38090
发表评论
-
multi_index_container
2018-08-11 13:04 409根据不同的类中不同的字段排序 #include < ... -
centos下boost安装
2014-03-27 09:28 1010./booststarp.sh //这里的一些错误不用管 ... -
GC的改良
2013-10-17 22:05 529分代回收:对分配不久,诞生时间较短的“年龄”对象进行重点扫描, ... -
GC与引用记数
2013-10-16 21:57 664根(Root)就是判断对象是否可被引用的起始点。至于哪里才是根 ... -
boost 信号槽
2011-06-08 23:43 2273#include<boost/signals2.hp ... -
boost bind
2011-06-07 15:28 1642bind并不是一个单独的类或函数,而是非常庞大的家族,依据绑定 ... -
boost reference_wrapper
2011-06-05 21:07 1524reference_wrapper是一个引用类型的包装器 ... -
元编程
2011-06-02 22:46 893元编程的最大特点在于:某些用户自定义的计算可以在程序翻译期进行 ... -
参数化虚拟性
2011-06-02 22:17 814#include<iostream> usi ... -
boost any与variant
2011-05-31 15:55 2387any:是一种只能容纳一个元素的容器,但这个元素可以是任意类型 ... -
traits
2011-05-30 16:43 755#include<iostream> usi ... -
动静多态
2011-05-30 15:40 1029由于继承||虚函数在运行期进程处理,这种多态叫动多态。 模板允 ... -
局部特化
2011-05-29 16:27 1001局部特化并不会引入一个新的模板,它只对原来模板(基本模板)进行 ... -
类模板与模板类
2011-05-29 16:08 6751.类模板:该类是一个模板,他代表的是:整个类家族的参数化描述 ... -
boost tuple
2011-05-27 15:03 1038tuple(元组):定义了一个有固定数目元素的容器,其中的每个 ... -
boost array
2011-05-27 00:06 904array本质上是一个对静态数组的包装,没有构造函数,不能指定 ... -
单元测试
2011-05-23 22:00 849test库提供了一个最小化的测试套件minimal test. ... -
boost StaticAssert
2011-05-23 21:42 898static_assert库把断言的诊断时刻由运行期提前到编译 ... -
boost正则表达式
2011-05-17 23:10 2759xpressive是boost的正则表达式库,它比boost. ... -
为什么模板要写在.h里面
2011-05-13 18:02 1070//test.h template<typena ...
相关推荐
程序选项是,它允许通过常规方法(例如命令行和配置文件)从用户定义和获取(名称,值)对。 它与getopt_long大致相似,但可用于C ++。 执照 根据分发。 特性 C ++ 03 需要链接 建置状态 (进行中...) 分支 ...
执行程序时,经常会用到命令行参数传递参数这种方式,今天实战一个命令行参数的从头到尾。 博文虽长,但均为干货。...program options是一系列pair组成的选项列表,它允许程序通过命令行或配置文件来读取这些参
#平行国际象棋##依赖Boost> = 1.57(组件:mpi,序列化,date_time,program_options) CMake> = 2.8 螺纹GCC> = 5.1.1(或clang> = 3.4)* OpenMP(可选,但推荐) gperftools(Google Performance Tools,可选,...
cmake-boost示例 ...Program options解析命令行参数 Asio网络 Property Tree解析XML配置文件 Test单元测试 String Algo字符串算法 System系统错误码 Serialization序列化 Uuid通用统一标识码 CRC和计算 Outcome返
Boost.Program Options上的声明式配置包装器动机Boost.Program Options是一个非常好的库,用于从命令行,文本文件甚至进程环境中获取选项。 但这还需要编写命令性代码以设置解析器,并且经常需要使用琐碎的(或没有...
为了让 Apache 知道哪个 URL 是用作 Subversion 版本库,你需要使用任意文本编辑器(例如记事本)编辑 Apache 的配置文件(通常是 c:\program files\apache group\apache2\conf\httpd.conf): 1. 在配置文件最后添加...
安装从PyPI: $ pip install flynnid来自来源: $ python setup.py install运行FlynnID FlynnID需要JSON格式的配置文件或命令行参数。 使用配置文件允许注册一个或多个多个节点,而命令行参数仅允许注册一个节点。 ...
可靠,快速的NGINX配置文件解析器和生成器 安装 您可以通过以下方式安装和: pip install crossplane 命令行界面 usage: crossplane <command> [options] various operations for nginx config files optional ...
5.2 对配置文件查错 5.3 初始化cache目录 5.4 在终端窗口里测试squid 5.5 将squid作为服务进程运行 5.5.1 squid_start脚本 5.6 启动脚本 5.6.1 /etc/rc.local 5.6.2 init.d和rc.d 5.6.3 /etc/inittab ...
简明批处理教程22009年10月20日 星期二 下午 05:35 最近对于批处理技术的探讨比较热,也有不少好的批处理程序发布,但是如果没有一定的相关知识恐怕不容易看懂和理解这些批处理文件,也就更谈不上自己动手编写了,古...
2.将c:\pclint\lnt 下的3个文件lib-w32.lnt,env-vc6.lnt,co-msc60.lnt拷贝至c:\pclint下, 再在安装目录下创建std.lnt和options.lnt两个文件,其中std.lnt的内容如下 // contents of std.lnt c:\pclint\co-msc60...
(译者注:应该根据你自己的具体开发板配置,如$ make <yourboard>_config,如果没有相应的开发板,应该自己照着建立相应的目录和配置文件。) 最后我们可以开始编译U-Boot了: $ make all 5.4 安装 5.4.1 动手之前 ...
Program Execution — Program Execution Functions PS — PostScript document creation Pspell — Pspell Functions qtdom — qtdom Functions radius — Radius Rar — Rar Functions Readline — GNU Readline ...
Program Execution — Program Execution Functions PS — PostScript document creation Pspell — Pspell Functions qtdom — qtdom Functions radius — Radius Rar — Rar Functions Readline — GNU Readline ...
现在双击找到的文件会打开,双击目录会激活tc跳到该目录(如果你想设定在左边,右边或者新建一个tab可以尝试加上tc的命令行参数,不一定能用),右键选择文件,open path会用tc打开文件所在目录。 再在tc里或者其他...
Program Execution Functions CXIX. PostScript document creation CXX. Pspell Functions CXXI. qtdom Functions CXXII. Radius CXXIII. Rar Functions CXXIV. GNU Readline CXXV. GNU Recode Functions CXXVI. ...
作者和贡献者 I. 入门指引 1. 简介 2. 简明教程 II. 安装与配置 3. 安装前需要考虑的事项 4. Unix 系统下的安装 5. Mac OS X 系统下的安装 6. Windows 系统下的安装 7. PECL 扩展库安装 8. 还有问题? 9. 运行时配置...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit Functions CXXV...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit ...