libcopp
2.2.0
|
#include <cmd_option.h>
Public Types | |
typedef unsigned char | uc_t |
typedef cmd_option_bind< TCmdStr > | self_type |
typedef binder::cmd_option_bind_base::help_msg_t | help_msg_t |
typedef binder::cmd_option_bind_base::help_list_t | help_list_t |
typedef std::shared_ptr< binder::cmd_option_bind_base > | func_ptr_t |
typedef std::map< TCmdStr, func_ptr_t > | funmap_type |
typedef std::shared_ptr< cmd_option_bind > | ptr_type |
typedef callback_param | param_type |
Public Member Functions | |
void | list_help_msg (help_list_t &msg, const std::string &prefix) const |
std::ostream & | dump (std::ostream &os, const std::string &prefix) |
std::shared_ptr< std::vector< const char * > > | get_cmd_names () const |
std::shared_ptr< binder::cmd_option_bind_base > | get_binded_cmd (const char *cmd_name) const |
size_t | size () const |
size_t | empty () const |
const funmap_type & | get_all () const |
size_t | children_size () const |
size_t | children_empty () const |
const funmap_type & | get_all_children () const |
int | get_help_cmd_style () const |
void | set_help_cmd_style (int style) |
int | get_help_description_style () const |
void | set_help_description_style (int style) |
void | start (callback_param args, bool is_single_cmd=false) const |
void | start (int argv, const char *argc[], bool is_single_cmd=false, void *ext_param=nullptr) const |
void | start (int argv, char *argc[], bool is_single_cmd=false, void *ext_param=nullptr) const |
void | start (const std::vector< std::string > &cmds, bool is_single_cmd=false, void *ext_param=nullptr) const |
void | start (const char *cmd_content, bool is_single_cmd=false, void *ext_param=nullptr) const |
void | start (const std::string &cmd_content, bool is_single_cmd=false, void *ext_param=nullptr) const |
void | unbind_cmd (const std::string &cmd_content) |
void | unbind_all_cmd () |
std::shared_ptr< binder::cmd_option_bindt< typename binder::maybe_wrap_member_pointer< void(cmd_option_bind< TCmdStr >::*)(callback_param)>::caller_type, binder::cmd_option_bind_param_list< cmd_option_bind< TCmdStr > * > > > | bind_help_cmd (const char *help_cmd_content) |
virtual void | operator() (callback_param arg) |
virtual std::string | get_help_msg (const char *prefix_data="") const |
template<typename _F , typename... _Args> | |
std::shared_ptr< binder::cmd_option_bindt< typename binder::maybe_wrap_member_pointer< _F >::caller_type, binder::cmd_option_bind_param_list< _Args... > > > | bind_cmd (const std::string &cmd_content, _F raw_fn, _Args... args) |
std::shared_ptr< binder::cmd_option_bind_base > | bind_child_cmd (const std::string cmd_content, std::shared_ptr< binder::cmd_option_bind_base > base_node) |
std::shared_ptr< binder::cmd_option_bind_base > | bind_child_cmd (const std::string cmd_content, ptr_type cmd_opt) |
virtual std::shared_ptr< cmd_option_bind_base > | set_help_msg (const char *help_msg) |
virtual std::shared_ptr< cmd_option_bind_base > | add_help_msg (const char *help_msg) |
Static Public Member Functions | |
static std::ostream & | dump (std::ostream &os, const self_type &self, const std::string &prefix) |
static const char * | get_segment (const char *begin_str, std::string &val) |
static std::vector< std::string > | split_cmd (const char *begin_str) |
static ptr_type | create () |
Protected Member Functions | |
void | run_cmd (const TCmdStr &cmd_content, callback_param params) const |
void | on_help (callback_param) |
Static Protected Member Functions | |
static bool | sort_by_all_cmds (const help_msg_t &l, const help_msg_t &r) |
Protected Attributes | |
funmap_type | callback_funcs_ |
funmap_type | callback_children_ |
int | help_cmd_style_ |
int | help_description_style_ |
std::string | help_msg_ |
Static Protected Attributes | |
static short | map_value_ [256] = {0} |
static char | trans_value_ [256] = {0} |
static const char * | ROOT_NODE_CMD = "@Root" |
Private Member Functions | |
cmd_option_bind () | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const self_type &self) |
命令处理函数 内定命令/变量列表(用于处理内部事件): @OnError : 出错时触发 @ErrorMsg : @OnError 函数的错误名称
@OnDefault : 默认执行函数(用于执行批量命令时的第一个指令前的参数) 注意:如果第一个参数就是指令则@OnDefault会被传入空参数执行
@OnCallFunc : 分离参数后,转入命令前(将传入所有参数,仅限于子cmd_option_bind<TCmdStr>执行时) 建议:可以在这个事件响应函数里再绑定其他命令,减少指令冗余 [注: 调用start函数不会响应这个事件]
Definition at line 66 of file cmd_option.h.
typedef std::shared_ptr<binder::cmd_option_bind_base> util::cli::cmd_option_bind< TCmdStr >::func_ptr_t |
Definition at line 72 of file cmd_option.h.
typedef std::map<TCmdStr, func_ptr_t> util::cli::cmd_option_bind< TCmdStr >::funmap_type |
Definition at line 73 of file cmd_option.h.
typedef binder::cmd_option_bind_base::help_list_t util::cli::cmd_option_bind< TCmdStr >::help_list_t |
Definition at line 71 of file cmd_option.h.
typedef binder::cmd_option_bind_base::help_msg_t util::cli::cmd_option_bind< TCmdStr >::help_msg_t |
Definition at line 70 of file cmd_option.h.
|
inherited |
Definition at line 50 of file cmd_option_list.h.
typedef std::shared_ptr<cmd_option_bind> util::cli::cmd_option_bind< TCmdStr >::ptr_type |
Definition at line 325 of file cmd_option.h.
typedef cmd_option_bind<TCmdStr> util::cli::cmd_option_bind< TCmdStr >::self_type |
Definition at line 69 of file cmd_option.h.
typedef unsigned char util::cli::cmd_option_bind< TCmdStr >::uc_t |
Definition at line 68 of file cmd_option.h.
|
inlineprivate |
构造函数
Definition at line 291 of file cmd_option.h.
References util::cli::CMDSPLIT, util::cli::cmd_option_bind< TCmdStr >::map_value_, util::cli::SPLITCHAR, util::cli::STRINGSYM, util::cli::cmd_option_bind< TCmdStr >::trans_value_, and util::cli::TRANSLATE.
Referenced by util::cli::cmd_option_bind< TCmdStr >::create().
|
inlinevirtualinherited |
Definition at line 64 of file cmd_option_list.h.
References util::cli::binder::cmd_option_bind_base::help_msg_.
|
inline |
|
inline |
绑定指令(通用) bind_cmd: 绑定参数 example: *.bind_cmd(命令名称, binder::cmd_option_bind_base 结构智能指针) *.bind_cmd(命令名称, cmd_option_bind<TCmdStr> 结构引用) 推荐使用上一种,可以减少一次结构复制
Definition at line 601 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_children_, util::cli::cmd_option_bind< TCmdStr >::callback_funcs_, util::cli::cmd_option_bind< TCmdStr >::size(), and util::cli::cmd_option_bind< TCmdStr >::split_cmd().
|
inline |
增加指令处理函数 (相同命令会被覆盖) 支持普通函数和类成员函数 注意:所有传入的类为引用,请确保在执行start时类对象未被释放(特别注意指针和局部变量) 注意:参数的复制发生在执行bind_cmd函数时 绑定函数对象/函数/成员函数(自适应) 注意:默认会复制函数对象和传入参数
bind_cmd: 绑定参数[注意值的复制发生在本函数执行时] example: *.bind_cmd(命令名称, 函数对象/函数/成员函数, 参数) // 默认类型推断是传值而非引用 *.bind_cmd<传入类型>(命令名称, 函数对象/函数/成员函数, 参数) *.bind_cmd<传入类型, 参数类型>(命令名称, 函数对象/函数/成员函数, 参数)
Definition at line 576 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_, util::cli::cmd_option_bind< TCmdStr >::size(), and util::cli::cmd_option_bind< TCmdStr >::split_cmd().
Referenced by util::cli::cmd_option_bind< TCmdStr >::bind_help_cmd().
|
inline |
绑定默认帮助函数
help_cmd_content | 帮助命令名称 |
Definition at line 513 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::bind_cmd().
|
inline |
Definition at line 359 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_children_.
|
inline |
Definition at line 358 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_children_.
|
inlinestatic |
Definition at line 326 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::cmd_option_bind().
Referenced by run_tests().
|
inlinestatic |
Definition at line 173 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::help_cmd_style_, util::cli::cmd_option_bind< TCmdStr >::help_description_style_, and util::cli::binder::cmd_option_bind_base::sort_by_all_cmds().
|
inline |
Definition at line 217 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::dump().
Referenced by util::cli::cmd_option_bind< TCmdStr >::dump().
|
inline |
Definition at line 355 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_.
|
inline |
Definition at line 356 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_.
|
inline |
Definition at line 360 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_children_.
|
inline |
获取已绑定的指令对象
cmd_name | 指令名称 |
Definition at line 348 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_.
|
inline |
获取已绑定的指令列表
Definition at line 332 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_.
|
inline |
Definition at line 362 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::help_cmd_style_.
|
inline |
Definition at line 364 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::help_description_style_.
|
inlinevirtual |
获取命令集合的帮助信息
prefix_data | 前缀 |
Reimplemented from util::cli::binder::cmd_option_bind_base.
Definition at line 533 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_, and util::cli::binder::cmd_option_bind_base::help_msg_.
|
inlinestatic |
从字符串获取一个字段(返回未处理的字符串结尾)
begin_str | 要解析的字符串的起始位置 |
val | 解析结果 |
Definition at line 225 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::map_value_, util::cli::SPLITCHAR, util::cli::STRINGSYM, util::cli::cmd_option_bind< TCmdStr >::trans_value_, and util::cli::TRANSLATE.
Referenced by util::cli::cmd_option_list::init_key_value_map(), and util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
Definition at line 126 of file cmd_option.h.
References util::cli::binder::cmd_option_bind_base::help_msg_t::binded_obj, util::cli::cmd_option_bind< TCmdStr >::callback_children_, util::cli::cmd_option_bind< TCmdStr >::callback_funcs_, util::cli::binder::cmd_option_bind_base::help_msg_t::cmd_paths, util::cli::binder::cmd_option_bind_base::help_msg_t::description, and util::cli::cmd_option_bind< TCmdStr >::list_help_msg().
Referenced by util::cli::cmd_option_bind< TCmdStr >::list_help_msg().
|
inlineprotected |
默认帮助函数
Definition at line 120 of file cmd_option.h.
|
inlinevirtual |
执行子结构
Implements util::cli::binder::cmd_option_bind_base.
Definition at line 520 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_, and util::cli::cmd_option_bind< TCmdStr >::start().
|
inlineprotected |
执行命令
cmd_content | 指令名称 |
params | 指令参数 |
Definition at line 89 of file cmd_option.h.
References util::cli::cmd_option_list::add(), util::cli::cmd_option_list::append_cmd(), util::cli::cmd_option_bind< TCmdStr >::callback_funcs_, util::cli::cmd_option_list::get_cmd_array(), and util::cli::binder::cmd_option_bind_base::ROOT_NODE_CMD.
Referenced by util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
Definition at line 363 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::help_cmd_style_.
|
inline |
Definition at line 365 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::help_description_style_.
|
inlinevirtualinherited |
Definition at line 58 of file cmd_option_list.h.
References util::cli::binder::cmd_option_bind_base::help_msg_.
|
inline |
Definition at line 354 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_funcs_.
Referenced by util::cli::cmd_option_bind< TCmdStr >::bind_child_cmd(), util::cli::cmd_option_bind< TCmdStr >::bind_cmd(), and util::cli::cmd_option_bind< TCmdStr >::start().
|
inlinestaticprotectedinherited |
Definition at line 46 of file cmd_option_list.h.
References util::cli::binder::cmd_option_bind_base::help_msg_t::all_cmds.
Referenced by util::cli::cmd_option_bind< TCmdStr >::dump().
|
inlinestatic |
多指令分离
begin_str | 源字符串 |
Definition at line 268 of file cmd_option.h.
References util::cli::CMDSPLIT, and util::cli::cmd_option_bind< TCmdStr >::map_value_.
Referenced by util::cli::cmd_option_bind< TCmdStr >::bind_child_cmd(), and util::cli::cmd_option_bind< TCmdStr >::bind_cmd().
|
inline |
处理指令 说明: 在第一个指令前的参数都将传入@OnDefault事件 参数可通过get[数组下标]获取 第一次使用get[字符串]时将构建参数映射表,get(0)为key,get(1)为value,get(2)为key,get(3)为value,依此类推 如果最后一组key没有value,执行get[key]将返回空指针 注意:get[偶数下标]对应的所有value值和get[字符串]返回的指针共享数据(即改了一个另一个也随之更改) 处理已分离指令(使用cmd_option_list存储参数集)
args | 数据集合 |
is_single_cmd | 是否强制单指令, 如果不强制, 则指令名称不能重复 |
Definition at line 381 of file cmd_option.h.
References util::cli::cmd_option_list::add(), util::cli::cmd_option_bind< TCmdStr >::callback_funcs_, util::cli::cmd_option_list::clear(), util::cli::cmd_option_list::get_cmd_array(), util::cli::cmd_option_list::get_ext_param(), util::cli::cmd_option_list::get_params_number(), util::cli::cmd_option_list::load_cmd_array(), util::cli::cmd_option_bind< TCmdStr >::run_cmd(), util::cli::cmd_option_list::set_ext_param(), and util::cli::cmd_option_bind< TCmdStr >::size().
Referenced by util::cli::cmd_option_bind< TCmdStr >::operator()(), and util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
处理未分离指令(使用const char*存储参数集字符串)
cmd_content | 指令 |
is_single_cmd | 是否强制单指令, 如果不强制, 则指令名称不能重复 |
Definition at line 464 of file cmd_option.h.
References util::cli::cmd_option_list::add(), util::cli::cmd_option_bind< TCmdStr >::get_segment(), util::cli::cmd_option_list::set_ext_param(), and util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
处理未分离指令(使用const std::string&存储参数集字符串)
cmd_content | 指令 |
is_single_cmd | 是否强制单指令, 如果不强制, 则指令名称不能重复 |
Definition at line 484 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
处理已分离指令(使用std::vector<std::string>存储参数集)
cmds | 数据集合 |
is_single_cmd | 是否强制单指令, 如果不强制, 则指令名称不能重复 |
ext_param | 透传参数 |
Definition at line 452 of file cmd_option.h.
References util::cli::cmd_option_list::set_ext_param(), and util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
处理已分离指令(使用char**存储参数集)
argv | 参数个数 |
argc | 参数列表 |
is_single_cmd | 是否强制单指令, 如果不强制, 则指令名称不能重复 |
ext_param | 透传参数 |
Definition at line 440 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
处理已分离指令(使用char**存储参数集)
argv | 参数个数 |
argc | 参数列表 |
is_single_cmd | 是否强制单指令, 如果不强制, 则指令名称不能重复 |
ext_param | 透传参数 |
Definition at line 426 of file cmd_option.h.
References util::cli::cmd_option_list::set_ext_param(), and util::cli::cmd_option_bind< TCmdStr >::start().
|
inline |
解绑全部指令
Definition at line 501 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_children_, and util::cli::cmd_option_bind< TCmdStr >::callback_funcs_.
|
inline |
解绑指令
cmd_content | 指令名称 |
Definition at line 492 of file cmd_option.h.
References util::cli::cmd_option_bind< TCmdStr >::callback_children_, and util::cli::cmd_option_bind< TCmdStr >::callback_funcs_.
|
friend |
Definition at line 215 of file cmd_option.h.
|
protected |
Definition at line 80 of file cmd_option.h.
Referenced by util::cli::cmd_option_bind< TCmdStr >::bind_child_cmd(), util::cli::cmd_option_bind< TCmdStr >::children_empty(), util::cli::cmd_option_bind< TCmdStr >::children_size(), util::cli::cmd_option_bind< TCmdStr >::get_all_children(), util::cli::cmd_option_bind< TCmdStr >::list_help_msg(), util::cli::cmd_option_bind< TCmdStr >::unbind_all_cmd(), and util::cli::cmd_option_bind< TCmdStr >::unbind_cmd().
|
protected |
Definition at line 79 of file cmd_option.h.
Referenced by util::cli::cmd_option_bind< TCmdStr >::bind_child_cmd(), util::cli::cmd_option_bind< TCmdStr >::bind_cmd(), util::cli::cmd_option_bind< TCmdStr >::empty(), util::cli::cmd_option_bind< TCmdStr >::get_all(), util::cli::cmd_option_bind< TCmdStr >::get_binded_cmd(), util::cli::cmd_option_bind< TCmdStr >::get_cmd_names(), util::cli::cmd_option_bind< TCmdStr >::get_help_msg(), util::cli::cmd_option_bind< TCmdStr >::list_help_msg(), util::cli::cmd_option_bind< TCmdStr >::operator()(), util::cli::cmd_option_bind< TCmdStr >::run_cmd(), util::cli::cmd_option_bind< TCmdStr >::size(), util::cli::cmd_option_bind< TCmdStr >::start(), util::cli::cmd_option_bind< TCmdStr >::unbind_all_cmd(), and util::cli::cmd_option_bind< TCmdStr >::unbind_cmd().
|
protected |
Definition at line 81 of file cmd_option.h.
Referenced by util::cli::cmd_option_bind< TCmdStr >::dump(), util::cli::cmd_option_bind< TCmdStr >::get_help_cmd_style(), and util::cli::cmd_option_bind< TCmdStr >::set_help_cmd_style().
|
protected |
Definition at line 82 of file cmd_option.h.
Referenced by util::cli::cmd_option_bind< TCmdStr >::dump(), util::cli::cmd_option_bind< TCmdStr >::get_help_description_style(), and util::cli::cmd_option_bind< TCmdStr >::set_help_description_style().
|
protectedinherited |
|
staticprotected |
Definition at line 76 of file cmd_option.h.
Referenced by util::cli::cmd_option_bind< TCmdStr >::cmd_option_bind(), util::cli::cmd_option_bind< TCmdStr >::get_segment(), and util::cli::cmd_option_bind< TCmdStr >::split_cmd().
|
staticprotectedinherited |
Definition at line 34 of file cmd_option_list.h.
Referenced by util::cli::cmd_option_bind< TCmdStr >::run_cmd().
|
staticprotected |
Definition at line 77 of file cmd_option.h.
Referenced by util::cli::cmd_option_bind< TCmdStr >::cmd_option_bind(), and util::cli::cmd_option_bind< TCmdStr >::get_segment().