本文整理汇总了C++中VSTRING::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ VSTRING::clear方法的具体用法?C++ VSTRING::clear怎么用?C++ VSTRING::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VSTRING
的用法示例。
在下文中一共展示了VSTRING::clear方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_cmd
int32_t do_cmd(char* key)
{
key = strip_line(key);
if (!key[0])
{
return TFS_SUCCESS;
}
#ifdef _WITH_READ_LINE
// not blank line, add to history
add_history(key);
#endif
char* token = strchr(key, ' ');
if (token != NULL)
{
*token = '\0';
}
STR_FUNC_MAP_ITER it = g_cmd_map.find(Func::str_to_lower(key));
if (it == g_cmd_map.end())
{
fprintf(stderr, "unknown command. \n");
return TFS_ERROR;
}
// ok this is current command
g_cur_cmd = key;
if (token != NULL)
{
token++;
key = token;
}
else
{
key = NULL;
}
VSTRING param;
param.clear();
while ((token = strsep(&key, " ")) != NULL)
{
if ('\0' == token[0])
{
continue;
}
param.push_back(token);
}
// check param count
int32_t param_cnt = param.size();
if (param_cnt < it->second.min_param_cnt_ || param_cnt > it->second.max_param_cnt_)
{
fprintf(stderr, "%s\t\t%s\n\n", it->second.syntax_, it->second.info_);
return TFS_ERROR;
}
return it->second.func_(param);
}
示例2: parse_cmd
//get the command
int parse_cmd(char* key, VSTRING & param)
{
int cmd = CMD_NOP;
char* token;
//remove the space
while (*key == ' ')
key++;
token = key + strlen(key);
while (*(token - 1) == ' ' || *(token - 1) == '\n' || *(token - 1) == '\r')
token--;
*token = '\0';
if (key[0] == '\0')
{
return cmd;
}
#ifdef _WITH_READ_LINE
// not blank line, add to history
add_history(key);
#endif
token = strchr(key, ' ');
if (token != NULL)
{
*token = '\0';
}
//find the command
STR_INT_MAP_ITER it = cmd_map.find(Func::str_to_lower(key));
if (it == cmd_map.end())
{
return CMD_UNKNOWN;
}
else
{
cmd = it->second;
}
if (token != NULL)
{
token++;
key = token;
}
else
{
key = NULL;
}
//get the parameters
param.clear();
while ((token = strsep(&key, " ")) != NULL)
{
if (token[0] == '\0')
{
continue;
}
param.push_back(token);
}
return cmd;
}
示例3: cmd_check_all
int cmd_check_all(const VSTRING&)
{
print_head();
// for uniformity, a little time waste
MSTR_VSTR::iterator it;
VSTRING param;
for (it = g_server_map.begin(); it != g_server_map.end(); it++)
{
param.clear();
param.push_back(it->first);
do_monitor(param, ADMIN_CMD_CHECK);
}
return TFS_SUCCESS;
}
示例4: main
int main(int argc, char* argv[])
{
int32_t i;
int ret = TFS_SUCCESS;
bool directly = false;
bool set_log_level = false;
// analyze arguments
while ((i = getopt(argc, argv, "s:r:nih")) != EOF)
{
switch (i)
{
case 'n':
set_log_level = true;
break;
case 's':
nsip = optarg;
break;
case 'r':
rc_addr = optarg;
break;
case 'i':
directly = true;
break;
case 'h':
default:
usage(argv[0]);
return TFS_ERROR;
}
}
if (set_log_level)
{
TBSYS_LOGGER.setLogLevel("ERROR");
}
if (NULL == nsip && NULL == rc_addr)
{
usage(argv[0]);
return TFS_ERROR;
}
gstreamer.set_packet_factory(&gfactory);
NewClientManager::get_instance().initialize(&gfactory, &gstreamer);
if (nsip != NULL)
{
g_tfs_client = TfsClientImpl::Instance();
ret = g_tfs_client->initialize(nsip, DEFAULT_BLOCK_CACHE_TIME, 1000, false);
if (ret != TFS_SUCCESS)
{
fprintf(stderr, "init tfs client fail, ret: %d\n", ret);
return ret;
}
g_use_meta = false;
}
else if (rc_addr != NULL)
{
strcpy(app_key, default_app_key);
g_use_meta = true;
}
init();
if (optind >= argc)
{
signal(SIGINT, sign_handler);
signal(SIGTERM, sign_handler);
main_loop();
}
else // has other params
{
int32_t i = 0;
if (directly)
{
for (i = optind; i < argc; i++)
{
do_cmd(argv[i]);
}
}
else
{
VSTRING param;
for (i = optind; i < argc; i++)
{
param.clear();
param.push_back(argv[i]);
cmd_batch_file(param);
}
}
}
if (g_tfs_client != NULL)
{
g_tfs_client->destroy();
}
return TFS_SUCCESS;
}
示例5: do_cmd
int32_t do_cmd(char* key)
{
key = strip_line(key);
if (!key[0])
{
return TFS_SUCCESS;
}
#ifdef _WITH_READ_LINE
// not blank line, add to history
add_history(key);
#endif
char* token = strchr(key, ' ');
if (token != NULL)
{
*token = '\0';
}
MSTR_FUNC_ITER it = g_cmd_map.find(Func::str_to_lower(key));
if (it == g_cmd_map.end())
{
fprintf(stderr, "unknown command. \n");
return TFS_ERROR;
}
// ok this is current command
g_cur_cmd = key;
if (token != NULL)
{
token++;
key = token;
}
else
{
key = NULL;
}
VSTRING param;
param.clear();
while ((token = strsep(&key, " ")) != NULL)
{
if ('\0' == token[0])
{
break;
}
param.push_back(token);
}
//check param count
int32_t min_param_count = g_cmd_map[g_cur_cmd].min_param_count_;
int32_t max_param_count = g_cmd_map[g_cur_cmd].max_param_count_;
int32_t param_size = static_cast<int32_t>(param.size());
if ((param_size < min_param_count) || param_size > max_param_count)
{
//fprintf(stderr, "%s\n\n", g_cmd_map[g_cur_cmd].info_);
fprintf(stderr, "bad param...");
print_help();
return TFS_ERROR;
}
return it->second.func_(param);
}
示例6: main
int main(int argc,char** argv)
{
//TODO readline
int32_t i;
string ns_ip_port_1;
string ns_ip_port_2;
bool directly = false;
while ((i = getopt(argc, argv, "s:m:ihv")) != EOF)
{
switch (i)
{
case 's':
ns_ip_port_2 = optarg;
break;
case 'm':
ns_ip_port_1 = optarg;
g_need_cmp = true;
break;
case 'i':
directly = true;
break;
case 'v':
version(argv[0]);
break;
case 'h':
default:
usage(argv[0]);
}
}
if (ns_ip_port_2.empty() || (g_need_cmp && ns_ip_port_1.empty()))
{
fprintf(stderr, "please input nameserver ip and port.\n");
usage(argv[0]);
}
TBSYS_LOGGER.setLogLevel("error");
init();
gstreamer.set_packet_factory(&gfactory);
NewClientManager::get_instance().initialize(&gfactory, &gstreamer);
if (!g_need_cmp)
{
g_show_info.set_ns_ip(ns_ip_port_2);
}
else
{
g_cmp_info.set_ns_ip(ns_ip_port_1, ns_ip_port_2);
}
signal(SIGINT, sign_handler);
signal(SIGTERM, sign_handler);
if (optind >= argc)
{
main_loop();
}
else
{
if (directly) // ssm ... -i "cmd"
{
for (i = optind; i < argc; i++)
{
do_cmd(argv[i]);
}
g_show_info.clean_last_file();
}
else// exec filename
{
VSTRING param;
for (i = optind; i < argc; i++)
{
param.clear();
param.push_back(argv[i]);
cmd_batch(param);
}
}
}
NewClientManager::get_instance().destroy();
}
示例7: main
int main(int argc, char* argv[])
{
int32_t i;
bool directly = false;
bool set_log_level = false;
// analyze arguments
while ((i = getopt(argc, argv, "s:k:ih")) != EOF)
{
switch (i)
{
case 'n':
set_log_level = true;
break;
case 'k':
krs_addr = optarg;
break;
case 'i':
directly = true;
break;
case 'h':
default:
usage(argv[0]);
return TFS_ERROR;
}
}
if (set_log_level)
{
TBSYS_LOGGER.setLogLevel("ERROR");
}
if (NULL == krs_addr)
{
usage(argv[0]);
return TFS_ERROR;
}
gstreamer.set_packet_factory(&gfactory);
NewClientManager::get_instance().initialize(&gfactory, &gstreamer);
if (krs_addr != NULL)
{
new_server_id = Func::get_host_ip(krs_addr);
}
init();
if (optind >= argc)
{
signal(SIGINT, sign_handler);
signal(SIGTERM, sign_handler);
main_loop();
}
else // has other params
{
int32_t i = 0;
if (directly)
{
for (i = optind; i < argc; i++)
{
do_cmd(argv[i]);
}
}
else
{
VSTRING param;
for (i = optind; i < argc; i++)
{
param.clear();
param.push_back(argv[i]);
cmd_batch_file(param);
}
}
}
return TFS_SUCCESS;
}
示例8: main
int main(int argc, char* argv[])
{
int i = 0;
int iex = 0;
// input option
if (argc == 1)
{
usage(argv[0]);
return TFS_ERROR;
}
while ((i = getopt(argc, argv, "d:i::")) != -1)
{
switch (i)
{
case 'i':
iex = 1;
break;
case 'd':
ds_ip = Func::get_host_ip(optarg);
if (ds_ip == 0)
{
printf("ip or port is invalid, please try again.\n");
return TFS_ERROR;
}
break;
case ':':
printf("missing -d");
usage(argv[0]);
break;
default:
usage(argv[0]);
return TFS_ERROR;
}
}
static tfs::message::MessageFactory factory;
static tfs::common::BasePacketStreamer streamer;
streamer.set_packet_factory(&factory);
NewClientManager::get_instance().initialize(&factory, &streamer);
init();
if (optind >= argc)
{
signal(SIGINT, signal_handler);
main_loop();
}
else
{
VSTRING param;
int i = optind;
if (iex)
{
printf("with i\n");
for (i = optind; i < argc; i++)
{
param.clear();
int cmd = parse_cmd(argv[i], param);
switch_cmd(cmd, param);
}
}
else
{
printf("without i\n");
for (i = optind; i < argc; i++)
{
param.clear();
param.push_back(argv[i]);
}
}
}
return TFS_SUCCESS;
}